Skip to content

Commit

Permalink
🔧 Improve how horizontal lines is draw in text backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Mar 20, 2020
1 parent a7d247d commit 197d4da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
29 changes: 13 additions & 16 deletions src/backends/text/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,20 @@ function _pt_text(io, pinfo;
tf.right_intersection, tf.row)
end

# The variable `all_cols_width` contains the width of all printed columns,
# including the row number and row name if the user requested. This is used
# when drawing lines.
all_cols_width = copy(cols_width)

show_row_names && (all_cols_width = vcat(row_name_width, all_cols_width))
show_row_number && (all_cols_width = vcat(row_number_width, all_cols_width))

# Top table line
# ==========================================================================

tf.top_line && _draw_line!(screen, buf, tf.up_left_corner,
tf.up_intersection, tf.up_right_corner, tf.row,
border_crayon, num_printed_cols, cols_width,
show_row_number, row_number_width,
show_row_names, row_name_width)
border_crayon, all_cols_width)

# Header
# ==========================================================================
Expand Down Expand Up @@ -335,10 +341,7 @@ function _pt_text(io, pinfo;
tf.header_line && _draw_line!(screen, buf, tf.left_intersection,
tf.middle_intersection,
tf.right_intersection, tf.row,
border_crayon, num_printed_cols,
cols_width, show_row_number,
row_number_width, show_row_names,
row_name_width)
border_crayon, all_cols_width)
end

# Data
Expand Down Expand Up @@ -417,18 +420,14 @@ function _pt_text(io, pinfo;

# Check if we must draw a horizontal line here.
i != num_rows && i in hlines &&
_draw_line!(screen, buf, hlines_format..., border_crayon,
num_printed_cols, cols_width, show_row_number,
row_number_width, show_row_names, row_name_width)
_draw_line!(screen, buf, hlines_format..., border_crayon, all_cols_width)

# Here we must check if the vertical size of the screen has been
# reached. Notice that we must add 4 to account for the command line,
# the continuation line, the bottom table line, and the last blank line.
if (screen.size[1] > 0) && (screen.row + 4 >= screen.size[1])
_draw_continuation_row(screen, buf, tf, text_crayon, border_crayon,
num_printed_cols, cols_width,
show_row_number, row_number_width,
show_row_names, row_name_width)
all_cols_width)
break
end
end
Expand All @@ -439,9 +438,7 @@ function _pt_text(io, pinfo;
tf.bottom_line && _draw_line!(screen, buf, tf.bottom_left_corner,
tf.bottom_intersection,
tf.bottom_right_corner, tf.row, border_crayon,
num_printed_cols, cols_width, show_row_number,
row_number_width, show_row_names,
row_name_width)
all_cols_width)

# Print the buffer
# ==========================================================================
Expand Down
39 changes: 9 additions & 30 deletions src/backends/text/private.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,17 @@ available. This function prints in each column the character `⋮` centered.
"""
function _draw_continuation_row(screen, io, tf, text_crayon, border_crayon,
num_printed_cols, cols_width, show_row_number,
row_number_width, show_row_names,
row_name_width)
cols_width)

_p!(screen, io, border_crayon, tf.column)

if show_row_number
row_number_i_str = _str_aligned("", :c, row_number_width + 2)
_p!(screen, io, text_crayon, row_number_i_str)
_p!(screen, io, border_crayon, tf.column)
end
num_cols = length(cols_width)

if show_row_names
row_names_i_str = _str_aligned("", :c, row_name_width + 2)
_p!(screen, io, text_crayon, row_names_i_str)
_p!(screen, io, border_crayon, tf.column)
end
_p!(screen, io, border_crayon, tf.column)

@inbounds for j = 1:num_printed_cols
@inbounds for j = 1:num_cols
data_ij_str = _str_aligned("", :c, cols_width[j] + 2)
_p!(screen, io, text_crayon, data_ij_str)

flp = j == num_printed_cols
flp = j == num_cols

_p!(screen, io, border_crayon, tf.column, flp)
_eol(screen) && break
Expand All @@ -169,26 +157,17 @@ function _draw_continuation_row(screen, io, tf, text_crayon, border_crayon,
end

"""
_draw_line!(screen, io, left, intersection, right, row, border_crayon, num_cols, cols_width, show_row_number, row_number_width, show_row_names, row_name_width)
_draw_line!(screen, io, left, intersection, right, row, border_crayon, cols_width)
Draw a vertical line in `io` using the information in `screen`.
"""
function _draw_line!(screen, io, left, intersection, right, row, border_crayon,
num_cols, cols_width, show_row_number, row_number_width,
show_row_names, row_name_width)
cols_width)

_p!(screen, io, border_crayon, left)

if show_row_number
_p!(screen, io, border_crayon, row^(row_number_width+2))
_p!(screen, io, border_crayon, intersection)
end
num_cols = length(cols_width)

if show_row_names
_p!(screen, io, border_crayon, row^(row_name_width+2))
_p!(screen, io, border_crayon, intersection)
end
_p!(screen, io, border_crayon, left)

@inbounds for i = 1:num_cols
# Check the alignment and print.
Expand Down

0 comments on commit 197d4da

Please sign in to comment.