diff options
author | elijah <elijah@riseup.net> | 2016-07-21 00:55:12 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-08-23 13:37:34 -0700 |
commit | 205b61dfe721e6d88fc06b050a0497eeb35f4e02 (patch) | |
tree | 518b5799f56d9e224d7ca2d85b3d29ef0c01b3c6 /lib/leap_cli/util | |
parent | 6fab56fb40256fb2e541ee3ad61490f03254d38e (diff) |
added 'leap vm' command
Diffstat (limited to 'lib/leap_cli/util')
-rw-r--r-- | lib/leap_cli/util/console_table.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/leap_cli/util/console_table.rb b/lib/leap_cli/util/console_table.rb index 53c5e18a..ccdcc2ab 100644 --- a/lib/leap_cli/util/console_table.rb +++ b/lib/leap_cli/util/console_table.rb @@ -3,9 +3,12 @@ module LeapCli; module Util class ConsoleTable def table @rows = [] + @cell_options = [] + @row_options = [] @column_widths = [] @column_options = [] + @current_row = 0 @current_column = 0 yield @@ -13,6 +16,8 @@ module LeapCli; module Util def row(options=nil) @current_column = 0 + @rows[@current_row] = [] + @cell_options[@current_row] = [] @row_options[@current_row] ||= options yield @current_row += 1 @@ -20,8 +25,8 @@ module LeapCli; module Util def column(str, options={}) str ||= "" - @rows[@current_row] ||= [] @rows[@current_row][@current_column] = str + @cell_options[@current_row][@current_column] = options @column_widths[@current_column] = [str.length, options[:min_width]||0, @column_widths[@current_column]||0].max @column_options[@current_column] ||= options @current_column += 1 @@ -33,8 +38,10 @@ module LeapCli; module Util row.each_with_index do |column, j| align = (@column_options[j]||{})[:align] || "left" width = @column_widths[j] - if color - str = LeapCli.logger.colorize(column, color) + cell_color = @cell_options[i][j] && @cell_options[i][j][:color] + cell_color ||= color + if cell_color + str = LeapCli.logger.colorize(column, cell_color) extra_width = str.length - column.length else str = column |