module Colorator
Constants
- ANSI_COLORS
- ANSI_MATCHR
- CORE_METHODS
- VERSION
Public Instance Methods
ansi_jump(str, num)
click to toggle source
Jump the cursor, moving it up and then back down to it’s spot, allowing you to do fancy things like multiple output (downloads) the way that Docker does them in an async way without breaking term.
# File lib/colorator.rb, line 38 def ansi_jump(str, num) "\x1b[#{num}A#{clear_line(str)}\x1b[#{ num }B" end
clear_line(str = "")
click to toggle source
# File lib/colorator.rb, line 54 def clear_line(str = "") "\x1b[2K\r#{ str }" end
clear_screen(str = "")
click to toggle source
Clear the screen’s current view, so the user gets a clean output.
# File lib/colorator.rb, line 74 def clear_screen(str = "") "\x1b[H\x1b[2J#{ str }" end
colorize(str = "", color)
click to toggle source
# File lib/colorator.rb, line 82 def colorize(str = "", color) "\x1b[#{color}m#{str}\x1b[0m" end
has_ansi?(str)
click to toggle source
Allows you to check if a string currently has ansi.
# File lib/colorator.rb, line 26 def has_ansi?(str) str.match(ANSI_MATCHR).is_a?( MatchData ) end
reset_ansi(str = "")
click to toggle source
# File lib/colorator.rb, line 46 def reset_ansi(str = "") "\x1b[0m#{ str }" end
strip_ansi(str)
click to toggle source
Strip ANSI from the current string, making it just a normal string.
# File lib/colorator.rb, line 64 def strip_ansi(str) str.gsub( ANSI_MATCHR, "" ) end