Class: Pvectl::Formatters::Wide
- Defined in:
- lib/pvectl/formatters/wide.rb,
sig/pvectl/formatters/wide.rbs
Overview
Formats data as a wide table with extended columns.
For collections: uses wide_columns and to_wide_row from presenter. For single resources (describe): delegates to Table (no wide variant).
Instance Method Summary collapse
-
#colorize_row(row, headers, pastel) ⇒ Array
Colorizes status columns in a row.
-
#format(data, presenter, color_enabled: true, describe: false, **context) ⇒ String
Formats data as wide table output.
-
#format_wide_table(data, presenter, color_enabled, **context) ⇒ String
Formats collection as wide table.
-
#render_table(headers, rows) ⇒ String
Renders table using tty-table.
Methods inherited from Base
Instance Method Details
#colorize_row(row, headers, pastel) ⇒ Array
Colorizes status columns in a row.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pvectl/formatters/wide.rb', line 64 def colorize_row(row, headers, pastel) row.each_with_index.map do |value, idx| header = headers[idx].to_s.downcase if header == "status" ColorSupport.colorize_status(value, pastel) else value.nil? ? "-" : value end end end |
#format(data, presenter, color_enabled: true, describe: false, **context) ⇒ String
Formats data as wide table output.
28 29 30 31 32 33 34 35 36 |
# File 'lib/pvectl/formatters/wide.rb', line 28 def format(data, presenter, color_enabled: true, describe: false, **context) # For describe (single resource), delegate to Table formatter # Wide format has no meaning for vertical key-value layout if describe || !collection?(data) Table.new.format(data, presenter, color_enabled: color_enabled, describe: true, **context) else format_wide_table(data, presenter, color_enabled, **context) end end |
#format_wide_table(data, presenter, color_enabled, **context) ⇒ String
Formats collection as wide table.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pvectl/formatters/wide.rb', line 47 def format_wide_table(data, presenter, color_enabled, **context) pastel = ColorSupport.pastel(explicit_flag: color_enabled) headers = presenter.wide_columns rows = data.map do |model| row = presenter.to_wide_row(model, **context) colorize_row(row, headers, pastel) end render_table(headers, rows) end |
#render_table(headers, rows) ⇒ String
Renders table using tty-table.
Uses :basic renderer for clean kubectl-like output (no borders). Handles non-TTY environments gracefully by rescuing ioctl errors.
83 84 85 86 87 88 89 90 |
# File 'lib/pvectl/formatters/wide.rb', line 83 def render_table(headers, rows) table = TTY::Table.new(header: headers, rows: rows) table.render(:basic, padding: [0, 2]) || headers.join("\t") rescue NoMethodError # TTY::Screen may call ioctl on non-TTY streams (e.g., StringIO in tests) # Fall back to simple tab-separated output ([headers] + rows).map { |row| row.join("\t") }.join("\n") end |