Module: Aspera::Cli::TerminalFormatter
- Includes:
- FormatterInterface
- Defined in:
- lib/aspera/cli/terminal_formatter.rb
Overview
Terminal formatter with ANSI colors and Unicode support
Constant Summary collapse
- HINT =
'HINT:'.bg_green.gray.blink.freeze
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)
36 37 38 39 40 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 36 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)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 44 def markdown_text(match) if match.is_a?(String) match = Markdown::FORMATS.match(match) Aspera.assert(match, 'markdown text does not match any known format') 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)
30 31 32 33 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 30 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/ )
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 18 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 |