Module: Aspera::Cli::TerminalFormatter
- Includes:
- FormatterInterface
- Defined in:
- lib/aspera/cli/terminal_formatter.rb
Overview
Terminal formatter with ANSI colors and Unicode support
Class Method Summary collapse
-
.hint ⇒ Object
Prefix for hint messages (evaluated on each call, as colors can be enabled or disabled by option).
-
.markdown_text(text) ⇒ String
Convert Markdown inline markup 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 check mark, or Y and space without Unicode.
Class Method Details
.hint ⇒ Object
Prefix for hint messages (evaluated on each call, as colors can be enabled or disabled by option)
22 23 24 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 22 def hint 'HINT:'.bg(:green).white.blink end |
.markdown_text(text) ⇒ String
Convert Markdown inline markup to terminal format (bold -> blue, code -> bold)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 42 def markdown_text(text) text.to_s.gsub(Markdown::INLINE_MARKUP_RE) do match = Regexp.last_match if match[:entity] case match[:entity] when 'bsol' then '\\' else Aspera.error_unexpected_value(match[:entity]) { 'HTML entity' } end 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 end |
.special_format(what) ⇒ Object
Format special values with colors (dim for empty, reverse for others)
34 35 36 37 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 34 def special_format(what) result = "<#{what}>" %w[null empty].any? { |s| what.include?(s) } ? result.faint : result.inverse end |
.tick(yes) ⇒ Object
Format boolean with colored check mark, or Y and space without Unicode
27 28 29 30 31 |
# File 'lib/aspera/cli/terminal_formatter.rb', line 27 def tick(yes) result = Environment.char(yes ? '✓' : '✗') return result.green if yes result.red end |