Class: Console::Terminal::XTerm
- Defined in:
- lib/console/terminal/xterm.rb
Overview
XTerm style terminal output.
Constant Summary collapse
- COLORS =
XTerm color codes.
{ black: 0, red: 1, green: 2, yellow: 3, blue: 4, magenta: 5, cyan: 6, white: 7, default: 9, }.freeze
- ATTRIBUTES =
XTerm attribute codes.
{ normal: 0, bold: 1, bright: 1, faint: 2, italic: 3, underline: 4, blink: 5, reverse: 7, hidden: 8, }.freeze
Instance Attribute Summary
Attributes inherited from Text
Instance Method Summary collapse
-
#colors? ⇒ Boolean
Whether the terminal supports colors.
-
#reset ⇒ Object
Reset the style.
-
#size ⇒ Object
The size of the terminal.
-
#style(foreground, background = nil, *attributes) ⇒ Object
Apply the given style to the output.
-
#width ⇒ Object
The width of the terminal.
Methods inherited from Text
#The stream to write to.=, #[], #[]=, #initialize, #print, #print_line, #puts, #write
Constructor Details
This class inherits a constructor from Console::Terminal::Text
Instance Method Details
#colors? ⇒ Boolean
Whether the terminal supports colors.
42 43 44 |
# File 'lib/console/terminal/xterm.rb', line 42 def colors? true end |
#reset ⇒ Object
Reset the style.
86 87 88 |
# File 'lib/console/terminal/xterm.rb', line 86 def reset "\e[0m" end |
#size ⇒ Object
The size of the terminal.
47 48 49 50 51 52 |
# File 'lib/console/terminal/xterm.rb', line 47 def size @stream.winsize rescue Errno::ENOTTY # Fake it... [24, 80] end |
#style(foreground, background = nil, *attributes) ⇒ Object
Apply the given style to the output.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/console/terminal/xterm.rb', line 65 def style(foreground, background = nil, *attributes) tokens = [] if foreground tokens << 30 + COLORS.fetch(foreground) end if background tokens << 40 + COLORS.fetch(background) end attributes.each do |attribute| tokens << ATTRIBUTES.fetch(attribute){attribute.to_i} end return "\e[#{tokens.join(';')}m" end |
#width ⇒ Object
The width of the terminal.
55 56 57 |
# File 'lib/console/terminal/xterm.rb', line 55 def width size.last end |