Module: Aspera::Cli::TerminalFormatter
- Includes:
- FormatterInterface
- Defined in:
- lib/aspera/cli/formatter.rb
Overview
Terminal formatter with ANSI colors and Unicode support
Class Method Summary collapse
-
.check_row(row) ⇒ Object
Prepare table row for terminal display (word wrap arrays).
-
.markdown_text(match) ⇒ Object
Convert Markdown to terminal format (bold -> blue, ‘code` -> bold).
-
.special_format(what) ⇒ Object
Format special values with colors (dim for empty, reverse for others).
-
.tick(yes) ⇒ Object
Format boolean with colored symbol (✓/✗ or Y/ ).
Class Method Details
.check_row(row) ⇒ Object
Prepare table row for terminal display (word wrap arrays)
47 48 49 50 51 |
# File 'lib/aspera/cli/formatter.rb', line 47 def check_row(row) row.each_key do |k| row[k] = row[k].map{ |i| WordWrap.ww(i.to_s, 120).chomp}.join("\n") if row[k].is_a?(Array) end end |
.markdown_text(match) ⇒ Object
Convert Markdown to terminal format (bold -> blue, ‘code` -> bold)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aspera/cli/formatter.rb', line 55 def markdown_text(match) if match.is_a?(String) match = Markdown::FORMATS.match(match) Aspera.assert(match) end Aspera.assert_type(match, MatchData) if match[:entity] Aspera.assert_values(match[:entity], %w[bsol]) '\\' elsif match[:bold] match[:bold].to_s.blue elsif match[:code] match[:code].to_s.bold else Aspera.error_unexpected_value(match.to_s) end end |
.special_format(what) ⇒ Object
Format special values with colors (dim for empty, reverse for others)
41 42 43 44 |
# File 'lib/aspera/cli/formatter.rb', line 41 def special_format(what) result = "<#{what}>" return %w[null empty].any?{ |s| what.include?(s)} ? result.dim : result.reverse_color end |
.tick(yes) ⇒ Object
Format boolean with colored symbol (✓/✗ or Y/ )
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aspera/cli/formatter.rb', line 29 def tick(yes) result = if Environment.terminal_supports_unicode? yes ? "\u2713" : "\u2717" else yes ? 'Y' : ' ' end return result.green if yes return result.red end |