module Clio::ANSICode
Constants
- ColoredRegexp
Public Class Methods
define_ansicolor_method(name,code)
click to toggle source
Define color codes.
# File lib/clio/ansicode.rb, line 243 def self.define_ansicolor_method(name,code) class_eval <<-HERE def #{name.to_s}(string = nil) result = "\e[#{code}m" if block_given? result << yield result << "\e[0m" elsif string result << string result << "\e[0m" elsif respond_to?(:to_str) result << self result << "\e[0m" end return result end HERE end
Public Instance Methods
clear_line()
click to toggle source
Clear to the end of the current line.
# File lib/clio/ansicode.rb, line 181 def clear_line "\e[K" end
Also aliased as: clr
clear_screen()
click to toggle source
Clear the screen and move cursor to home.
# File lib/clio/ansicode.rb, line 174 def clear_screen "\e[2J" end
Also aliased as: cls
colors()
click to toggle source
# File lib/clio/ansicode.rb, line 313 def colors @@colors.map { |c| c[0] } end
display( line, column=0, string=nil ) { || ... }
click to toggle source
Like move
but returns to original positon after yielding block
or adding string argument.
# File lib/clio/ansicode.rb, line 225 def display( line, column=0, string=nil ) #:yield: result = "\e[s" result << "\e[#{line.to_i};#{column.to_i}H" if block_given? result << yield result << "\e[u" elsif string result << string result << "\e[u" elsif respond_to?(:to_str) result << self result << "\e[u" end return result end
down( spaces=1 )
click to toggle source
Move cursor down a specificed number of spaces.
# File lib/clio/ansicode.rb, line 206 def down( spaces=1 ) "\e[#{spaces.to_i}B" end
left( spaces=1 )
click to toggle source
Move cursor left a specificed number of spaces.
# File lib/clio/ansicode.rb, line 212 def left( spaces=1 ) "\e[#{spaces.to_i}D" end
move( line, column=0 )
click to toggle source
Move curose to line and column.
# File lib/clio/ansicode.rb, line 194 def move( line, column=0 ) "\e[#{line.to_i};#{column.to_i}H" end
restore()
click to toggle source
Restore saved cursor positon.
# File lib/clio/ansicode.rb, line 168 def restore "\e[u" end
right( spaces=1 )
click to toggle source
Move cursor right a specificed number of spaces.
# File lib/clio/ansicode.rb, line 218 def right( spaces=1 ) "\e[#{spaces.to_i}C" end
save()
click to toggle source
Save current cursor positon.
# File lib/clio/ansicode.rb, line 162 def save "\e[s" end
uncolored(string = nil) { || ... }
click to toggle source
# File lib/clio/ansicode.rb, line 299 def uncolored(string = nil) if block_given? yield.gsub(ColoredRegexp, '') elsif string string.gsub(ColoredRegexp, '') elsif respond_to?(:to_str) gsub(ColoredRegexp, '') else '' end end
up( spaces=1 )
click to toggle source
Move cursor up a specificed number of spaces.
# File lib/clio/ansicode.rb, line 200 def up( spaces=1 ) "\e[#{spaces.to_i}A" end