Module: ANSI

Defined in:
lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb

Overview

taken from the dorkbuster gem

Constant Summary collapse

Reset =
"0"
Bright =
"1"
Black =
"30"
Red =
"31"
Green =
"32"
Yellow =
"33"
Blue =
"34"
Magenta =
"35"
Cyan =
"36"
White =
"37"
BGBlack =
"40"
BGRed =
"41"
BGGreen =
"42"
BGYellow =
"43"
BGBlue =
"44"
BGMagenta =
"45"
BGCyan =
"46"
BGWhite =
"47"
Bright_Magenta =

“1;35;40”

Bright+';'+BGBlack+';'+Magenta

Class Method Summary collapse

Class Method Details

.attr_is_bgcolor?(str) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 40

def attr_is_bgcolor?(str)
	str.to_i.between?(40, 47)
end

.attr_is_fgcolor?(str) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 36

def attr_is_fgcolor?(str)
	str.to_i.between?(30, 37)
end

.backspace_rubout(cnt = 1) ⇒ Object



106
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 106

def backspace_rubout(cnt=1); ("\b \b" * cnt) end

.blue(str) ⇒ Object



87
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 87

def blue(str);		colorize(str, Blue) end

.bright_magenta(str) ⇒ Object



91
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 91

def bright_magenta(str); colorize(str, Bright_Magenta) end

.color(*colors) ⇒ Object



28
29
30
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 28

def color(*colors)
	"\033[#{colors.join(';')}m"
end

.colorize(str, start_color, end_color = Reset) ⇒ Object



32
33
34
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 32

def colorize(str, start_color, end_color = Reset)
	"#{color(start_color)}#{str}#{color(end_color)}"
end

.cursor_down(cnt = 1) ⇒ Object



101
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 101

def cursor_down(cnt=1);	"\e[#{cnt}B" end

.cursor_left(cnt = 1) ⇒ Object



98
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 98

def cursor_left(cnt=1);	"\e[#{cnt}D" end

.cursor_right(cnt = 1) ⇒ Object



99
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 99

def cursor_right(cnt=1); "\e[#{cnt}C" end

.cursor_up(cnt = 1) ⇒ Object



100
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 100

def cursor_up(cnt=1);		"\e[#{cnt}A" end

.cyan(str) ⇒ Object



89
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 89

def cyan(str);		colorize(str, Cyan) end

.erase_eolObject



109
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 109

def erase_eol; "\e[K" end

.erase_lineObject



108
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 108

def erase_line; "\e[2K" end

.green(str) ⇒ Object



85
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 85

def green(str);	 colorize(str, Green) end

.magenta(str) ⇒ Object



88
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 88

def magenta(str); colorize(str, Magenta) end

.red(str) ⇒ Object



84
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 84

def red(str);		 colorize(str, Red) end

.restore_cursor_posObject



104
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 104

def restore_cursor_pos; "\e[u" end

.save_cursor_posObject



103
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 103

def save_cursor_pos;		"\e[s" end

.set_cursor_pos(row, col) ⇒ Object



96
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 96

def set_cursor_pos(row, col); "\e[#{row};#{col}H" end

.set_scroll_fullscreenObject



93
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 93

def set_scroll_fullscreen; "\e[r" end

.set_scroll_region(row_start, row_end) ⇒ Object



94
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 94

def set_scroll_region(row_start, row_end); "\e[#{row_start};#{row_end}r" end

.strbreak(str, len) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 65

def strbreak(str, len)
	out = []
	buf = ""
	nout = 0
	str.scan(/\e\[[\d;]*[A-Za-z]|[^\e]/) do |tok|
		if tok[0] != ?\e
			nout += 1
			if nout > len
	out << buf
	nout -= len
	buf = ""
end
		end
		buf << tok
	end
	out << buf unless buf.empty?
	out
end

.strclip(str, len) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 52

def strclip(str, len)
	out = ""
	nout = 0
	str.scan(/\e\[[\d;]*[A-Za-z]|[^\e]/) do |tok|
		if tok[0] != ?\e
			nout += 1
			break if nout > len
		end
		out << tok
	end
	out
end

.strip(str) ⇒ Object



44
45
46
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 44

def strip(str)
	str.gsub(/\e\[[\d;]*[A-Za-z]/, "")
end

.strlen(str) ⇒ Object



48
49
50
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 48

def strlen(str)
	str.strip.length
end

.yellow(str) ⇒ Object



86
# File 'lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb', line 86

def yellow(str);	colorize(str, Yellow) end