Module: MonoclePrint::TerminalEscapes
- Included in:
- OutputDevice
- Defined in:
- lib/monocle-print/terminal-escapes.rb
Constant Summary collapse
- ANSI_COLORS =
{ :blue => 4, :white => 7, :magenta => 5, :yellow => 3, :green => 2, :black => 0, :red => 1, :cyan => 6 }
Class Method Summary collapse
-
.ansi_color(type, color, bold = nil) ⇒ Object
def term_info @term_info ||= TermInfo.new end.
- .blink ⇒ Object
- .bold ⇒ Object
- .clear_attr ⇒ Object
- .clear_down ⇒ Object
- .clear_left ⇒ Object
- .clear_line ⇒ Object
- .clear_right ⇒ Object
- .clear_screen ⇒ Object
- .clear_up ⇒ Object
- .conceal ⇒ Object
- .cursor_backward(columns = 1) ⇒ Object
- .cursor_down(lines = 1) ⇒ Object
- .cursor_forward(columns = 1) ⇒ Object
- .cursor_up(lines = 1) ⇒ Object
- .dobule_height_bottom ⇒ Object
-
.double_height_top ⇒ Object
VT100 escapes.
- .double_width ⇒ Object
- .konsole_color(type, r, g, b, bold = nil) ⇒ Object
- .restore_cursor ⇒ Object
- .reverse ⇒ Object
- .save_cursor ⇒ Object
- .set_cursor(line = 0, column = 0) ⇒ Object
- .single_width ⇒ Object
- .underline ⇒ Object
- .xterm_color(type, color_index, bold = nil) ⇒ Object
Class Method Details
.ansi_color(type, color, bold = nil) ⇒ Object
def term_info
@term_info ||= TermInfo.new
end
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/monocle-print/terminal-escapes.rb', line 21 def ansi_color( type, color, bold = nil ) offset = case type when ?f then 30 # foreground when ?b then 40 # background end code = offset + ANSI_COLORS.fetch( color.to_sym ) do raise( ArgumentError, "unknown color name `%s'" % color ) end "\e[#{ '1;' if bold }#{ code }m" end |
.blink ⇒ Object
63 64 65 |
# File 'lib/monocle-print/terminal-escapes.rb', line 63 def blink "\e[5m" end |
.bold ⇒ Object
55 56 57 |
# File 'lib/monocle-print/terminal-escapes.rb', line 55 def bold "\e[1m" end |
.clear_attr ⇒ Object
51 52 53 |
# File 'lib/monocle-print/terminal-escapes.rb', line 51 def clear_attr "\e[0m" end |
.clear_down ⇒ Object
136 137 138 |
# File 'lib/monocle-print/terminal-escapes.rb', line 136 def clear_down "\e[0J" end |
.clear_left ⇒ Object
128 129 130 |
# File 'lib/monocle-print/terminal-escapes.rb', line 128 def clear_left "\e[1K" end |
.clear_line ⇒ Object
132 133 134 |
# File 'lib/monocle-print/terminal-escapes.rb', line 132 def clear_line "\e[2K" end |
.clear_right ⇒ Object
124 125 126 |
# File 'lib/monocle-print/terminal-escapes.rb', line 124 def clear_right "\e[0K" end |
.clear_screen ⇒ Object
144 145 146 |
# File 'lib/monocle-print/terminal-escapes.rb', line 144 def clear_screen "\e[2J" end |
.clear_up ⇒ Object
140 141 142 |
# File 'lib/monocle-print/terminal-escapes.rb', line 140 def clear_up "\e[1J" end |
.conceal ⇒ Object
71 72 73 |
# File 'lib/monocle-print/terminal-escapes.rb', line 71 def conceal "\e[8m" end |
.cursor_backward(columns = 1) ⇒ Object
91 92 93 |
# File 'lib/monocle-print/terminal-escapes.rb', line 91 def cursor_backward( columns = 1 ) "\e[%iD" % columns end |
.cursor_down(lines = 1) ⇒ Object
83 84 85 |
# File 'lib/monocle-print/terminal-escapes.rb', line 83 def cursor_down( lines = 1 ) "\e[%iB" % lines end |
.cursor_forward(columns = 1) ⇒ Object
87 88 89 |
# File 'lib/monocle-print/terminal-escapes.rb', line 87 def cursor_forward( columns = 1 ) "\e[%iC" % columns end |
.cursor_up(lines = 1) ⇒ Object
79 80 81 |
# File 'lib/monocle-print/terminal-escapes.rb', line 79 def cursor_up( lines = 1 ) "\e[%iA" % lines end |
.dobule_height_bottom ⇒ Object
112 113 114 |
# File 'lib/monocle-print/terminal-escapes.rb', line 112 def dobule_height_bottom "\e#4" end |
.double_height_top ⇒ Object
VT100 escapes
108 109 110 |
# File 'lib/monocle-print/terminal-escapes.rb', line 108 def double_height_top "\e#3" end |
.double_width ⇒ Object
120 121 122 |
# File 'lib/monocle-print/terminal-escapes.rb', line 120 def double_width "\e#6" end |
.konsole_color(type, r, g, b, bold = nil) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/monocle-print/terminal-escapes.rb', line 42 def konsole_color( type, r, g, b, bold = nil) prefix = case type when ?f then 38 # foreground when ?b then 48 # background end "\e[#{ prefix };2;#{ r };#{ g };#{ b }m" end |
.restore_cursor ⇒ Object
99 100 101 |
# File 'lib/monocle-print/terminal-escapes.rb', line 99 def restore_cursor "\e[u" end |
.reverse ⇒ Object
67 68 69 |
# File 'lib/monocle-print/terminal-escapes.rb', line 67 def reverse "\e[7m" end |
.save_cursor ⇒ Object
95 96 97 |
# File 'lib/monocle-print/terminal-escapes.rb', line 95 def save_cursor "\e[s" end |
.set_cursor(line = 0, column = 0) ⇒ Object
75 76 77 |
# File 'lib/monocle-print/terminal-escapes.rb', line 75 def set_cursor( line = 0, column = 0 ) "\e[%i;%iH" % [ line, column ] end |
.single_width ⇒ Object
116 117 118 |
# File 'lib/monocle-print/terminal-escapes.rb', line 116 def single_width "\e#5" end |
.underline ⇒ Object
59 60 61 |
# File 'lib/monocle-print/terminal-escapes.rb', line 59 def underline "\e[4m" end |
.xterm_color(type, color_index, bold = nil) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/monocle-print/terminal-escapes.rb', line 33 def xterm_color( type, color_index, bold = nil ) prefix = case type when ?f then 38 # foreground when ?b then 48 # background end "\e[#{ prefix };5;#{ color_index }m" end |