lib/tabulo/table.rb
# Resets all the column widths so that each column is *just* wide enough to accommodate
# its header text as well as the formatted content of each its cells for the entire
# collection, together with a single character of padding on either side of the column,
# without any wrapping. In addition, if the table has a title but is not wide enough to
# accommodate (without wrapping) the title text (with a character of padding either side),
# widens the columns roughly evenly until the table as a whole is just wide enough to
# accommodate the title text.
#
# Note that calling this method will cause the entire source Enumerable to
# be traversed and all the column extractors and formatters to be applied in order
# to calculate the required widths.
#
# Note also that this method causes column widths to be fixed as appropriate to the
# formatted cell contents given the state of the source Enumerable at the point it
# is called. If the source Enumerable changes between that point, and the point when
# the Table is printed, then columns will *not* be resized yet again on printing.
#
# @param [nil, Numeric] max_table_width With no args, or if passed <tt>:auto</tt>,
#   stops the total table width (including padding and borders) from expanding beyond the
#   bounds of the terminal screen.
#   If passed <tt>nil</tt>, the table width will not be capped.
#   Width is deducted from columns if required to achieve this, with one character progressively
#   deducted from the width of the widest column until the target is reached. When the
#   table is printed, wrapping or truncation will then occur in these columns as required
#   (depending on how they were configured).
#   Note that regardless of the value passed to max_table_width, the table will always be left wide
#   enough to accommodate at least 1 character's width of content, 1 character of left padding and
#   1 character of right padding in each column, together with border characters (1 on each side
#   of the table and 1 between adjacent columns). I.e. there is a certain width below width the
#   Table will refuse to shrink itself.
# @return [Table] the Table itself
Resets all the column widths so that each column is *just* wide enough to accommodate
its header text as well as the formatted content of each its cells for the entire
collection, together with a single character of padding on either side of the column,
without any wrapping. In addition, if the table has a title but is not wide enough to
accommodate (without wrapping) the title text (with a character of padding either side),
widens the columns roughly evenly until the table as a whole is just wide enough to
accommodate the title text.

Note that calling this method will cause the entire source Enumerable to
be traversed and all the column extractors and formatters to be applied in order
to calculate the required widths.

Note also that this method causes column widths to be fixed as appropriate to the
formatted cell contents given the state of the source Enumerable at the point it
is called. If the source Enumerable changes between that point, and the point when
the Table is printed, then columns will *not* be resized yet again on printing.
Resets all the column widths so that each column is * just * wide enough to accommodate its header text as well as the formatted content of each its cells for the entire collection together with a single character of padding on either side of the column without any wrapping . In addition if the table has a title but is not wide enough to accommodate ( without wrapping ) the title text ( with a character of padding either side ) widens the columns roughly evenly until the table as a whole is just wide enough to accommodate the title text . Note that calling this method will cause the entire source Enumerable to be traversed and all the column extractors and formatters to be applied in order to calculate the required widths . Note also that this method causes column widths to be fixed as appropriate to the formatted cell contents given the state of the source Enumerable at the point it is called . If the source Enumerable changes between that point and the point when the Table is printed then columns will * not * be resized yet again on printing .
def pack(max_table_width: :auto)
      get_columns.each { |column| column.width = Util.wrapped_width(column.header) }
      @sources.each_with_index do |source, row_index|
        get_columns.each_with_index do |column, column_index|
          cell = column.body_cell(source, row_index: row_index, column_index: column_index)
          cell_width = Util.wrapped_width(cell.formatted_content)
          column.width = Util.max(column.width, cell_width)
        end
      end
      shrink_to(max_table_width == :auto ? TTY::Screen.width : max_table_width) if max_table_width
      if @title
        border_edge_width = (@border == :blank ? 0 : 2)
        columns = get_columns
        expand_to(
          Unicode::DisplayWidth.of(@title) +
          columns.first.left_padding +
          columns.last.right_padding +
          border_edge_width
        )
      end
      self
    end
def pack ( max_table_width : :auto ) get_columns . each { | column | column . width = Util . wrapped_width ( column . header ) } @sources . each_with_index do | source , row_index | get_columns . each_with_index do | column , column_index | cell = column . body_cell ( source , row_index : row_index , column_index : column_index ) cell_width = Util . wrapped_width ( cell . formatted_content ) column . width = Util . max ( column . width , cell_width ) end end shrink_to ( max_table_width == :auto ? TTY :: Screen . width : max_table_width ) if max_table_width if @title border_edge_width = ( @border == :blank ? 0 : 2 ) columns = get_columns expand_to ( Unicode :: DisplayWidth . of ( @title ) + columns . first . left_padding + columns . last . right_padding + border_edge_width ) end self end
Resets all the column widths so that each column is *just* wide enough to accommodate
its header text as well as the formatted content of each its cells for the entire
collection, together with a single character of padding on either side of the column,
without any wrapping.
Resets all the column widths so that each column is * just * wide enough to accommodate its header text as well as the formatted content of each its cells for the entire collection together with a single character of padding on either side of the column without any wrapping .
the Table itself
the Table itself
Table
max_table_width
max_table_width With no args, or if passed :auto, stops the total table width (including padding and borders) from expanding beyond the bounds of the terminal screen. If passed nil, the table width will not be capped. Width is deducted from columns if required to achieve this, with one character progressively deducted from the width of the widest column until the target is reached. When the table is printed, wrapping or truncation will then occur in these columns as required (depending on how they were configured). Note that regardless of the value passed to max_table_width, the table will always be left wide enough to accommodate at least 1 character's width of content, 1 character of left padding and 1 character of right padding in each column, together with border characters (1 on each side of the table and 1 between adjacent columns). I.e. there is a certain width below width the Table will refuse to shrink itself.
max_table_width With no args or if passed : auto stops the total table width ( including padding and borders ) from expanding beyond the bounds of the terminal screen . If passed nil the table width will not be capped . Width is deducted from columns if required to achieve this with one character progressively deducted from the width of the widest column until the target is reached . When the table is printed wrapping or truncation will then occur in these columns as required ( depending on how they were configured ) . Note that regardless of the value passed to max_table_width the table will always be left wide enough to accommodate at least 1 character ' s width of content 1 character of left padding and 1 character of right padding in each column together with border characters ( 1 on each side of the table and 1 between adjacent columns ) . I . e . there is a certain width below width the Table will refuse to shrink itself .