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

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


63
64
65
# File 'lib/monocle-print/terminal-escapes.rb', line 63

def blink
  "\e[5m"
end

.boldObject



55
56
57
# File 'lib/monocle-print/terminal-escapes.rb', line 55

def bold
  "\e[1m"
end

.clear_attrObject



51
52
53
# File 'lib/monocle-print/terminal-escapes.rb', line 51

def clear_attr
  "\e[0m"
end

.clear_downObject



136
137
138
# File 'lib/monocle-print/terminal-escapes.rb', line 136

def clear_down
  "\e[0J"
end

.clear_leftObject



128
129
130
# File 'lib/monocle-print/terminal-escapes.rb', line 128

def clear_left
  "\e[1K"
end

.clear_lineObject



132
133
134
# File 'lib/monocle-print/terminal-escapes.rb', line 132

def clear_line
  "\e[2K"
end

.clear_rightObject



124
125
126
# File 'lib/monocle-print/terminal-escapes.rb', line 124

def clear_right
  "\e[0K"
end

.clear_screenObject



144
145
146
# File 'lib/monocle-print/terminal-escapes.rb', line 144

def clear_screen
  "\e[2J"
end

.clear_upObject



140
141
142
# File 'lib/monocle-print/terminal-escapes.rb', line 140

def clear_up
  "\e[1J"
end

.concealObject



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_bottomObject



112
113
114
# File 'lib/monocle-print/terminal-escapes.rb', line 112

def dobule_height_bottom
  "\e#4"
end

.double_height_topObject

VT100 escapes



108
109
110
# File 'lib/monocle-print/terminal-escapes.rb', line 108

def double_height_top
  "\e#3"
end

.double_widthObject



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_cursorObject



99
100
101
# File 'lib/monocle-print/terminal-escapes.rb', line 99

def restore_cursor
  "\e[u"
end

.reverseObject



67
68
69
# File 'lib/monocle-print/terminal-escapes.rb', line 67

def reverse
  "\e[7m"
end

.save_cursorObject



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_widthObject



116
117
118
# File 'lib/monocle-print/terminal-escapes.rb', line 116

def single_width
  "\e#5"
end

.underlineObject



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