module Terminal

Constants

BACKGROUND_BLACK
CLEAR_LINE
CYAN
LIGHT_GREEN
OTHER_TIOCGWINSZ
RED
RESET
TIOCGWINSZ
WHITE

Public Class Methods

default_colour() click to toggle source
# File lib/rubyhacks.rb, line 588
def self.default_colour
        "\033[00m"
end
erewind(nlines) click to toggle source
# File lib/rubyhacks.rb, line 579
def self.erewind(nlines)
        eprint "\033[#{nlines}A"
end
reset() click to toggle source
# File lib/rubyhacks.rb, line 584
def self.reset
        print "\033[0;00m"
end
rewind(nlines) click to toggle source
# File lib/rubyhacks.rb, line 575
def self.rewind(nlines)
        print "\033[#{nlines}A"
end
terminal_size() click to toggle source
# File lib/rubyhacks.rb, line 556
def self.terminal_size
        return [ENV['ROWS'].to_i, ENV['COLS'].to_i] if ENV['ROWS'] and ENV['COLS']
        raise TerminalError.new("Tried to determine terminal size but this process is not being run from within a terminal (may be a sub process or called within another script). Set ENV['ROWS'] ($ROWS in shell) and ENV['COLS'] ($COLS in shell) to avoid this warning") unless STDOUT.tty?
        system_code = TIOCGWINSZ
        begin
                rows, cols = 25, 80
                buf = [0, 0, 0, 0].pack("SSSS")
                if STDOUT.ioctl(system_code, buf) >= 0 then
                        rows, cols, row_pixels, row_pixels, col_pixels =  
                buf.unpack("SSSS")[0..1]
                end
                return [rows, cols]
        rescue
                #puts "Warning: TIOCGWINSZ switched in Terminal.terminal_size"
                system_code = OTHER_TIOCGWINSZ       
        retry
        end
end