Module: Mimas::Terminal::Ansi
- Defined in:
- lib/mimas/terminal/ansi.rb
Constant Summary collapse
- ESCAPE =
format("%c", 27)
- MATCH =
%r!#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m!ix- COLORS =
{ bold: 1, black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, }.freeze
Instance Method Summary collapse
-
#has_ansi? ⇒ Boolean
Does the string include ANSI color codes?.
-
#reset_ansi ⇒ Object
Reset the color back to the default color so that you do not leak any colors when you move onto the next line.
-
#strip_ansi ⇒ Object
Strip ANSI from the current string.
Instance Method Details
#has_ansi? ⇒ Boolean
Does the string include ANSI color codes?
48 49 50 |
# File 'lib/mimas/terminal/ansi.rb', line 48 def has_ansi? !!(self =~ MATCH) end |
#reset_ansi ⇒ Object
Reset the color back to the default color so that you do not leak any colors when you move onto the next line. This is probably normally used as part of a wrapper so that we don't leak colors.
55 56 57 |
# File 'lib/mimas/terminal/ansi.rb', line 55 def reset_ansi @reset_ansi ||= format("%c[0m", 27) end |
#strip_ansi ⇒ Object
Strip ANSI from the current string. It also strips cursor stuff, well some of it, and it also strips some other stuff that a lot of the other ANSI strippers don't.
43 44 45 |
# File 'lib/mimas/terminal/ansi.rb', line 43 def strip_ansi gsub MATCH, "" end |