module Ansi

copypasted from lindebug.rb

Constants

CANON
ClearLine
ClearLineAfter
ClearLineBefore
ClearScreen
Colors
CursHome
ECHO
ESC_SEQ
Reset
TCGETS
TCSETS
TIOCGWINSZ

Public Class Methods

color(*args) click to toggle source
# File samples/dasmnavig.rb, line 20
def self.color(*args)
        fg = true
        "\e[" << args.map { |a|
                case a
                when :bold; 2
                when :negative; 7
                when :normal; 22
                when :positive; 27
                else
                        if col = Colors.index(a)
                                add = (fg ? 30 : 40)
                                fg = false
                                col+add
                        end
                end
        }.compact.join(';') << 'm'
end
get_terminal_size() click to toggle source
# File samples/dasmnavig.rb, line 44
def self.get_terminal_size
        s = ''.ljust(8)
        $stdin.ioctl(TIOCGWINSZ, s) >= 0 ? s.unpack('SS') : [80, 25]
end
getkey() click to toggle source
# File samples/dasmnavig.rb, line 68
def self.getkey
        c = $stdin.getc
        return c if c != \e
        c = $stdin.getc
        if c != [ and c != O
                $stdin.ungetc c
                return \e
        end
        seq = ''
        loop do
                c = $stdin.getc
                seq << c
                case c; when a..z, A..Z, ~; break end
        end
        ESC_SEQ[seq] || seq
end
hline(len) click to toggle source
# File samples/dasmnavig.rb, line 37
def self.hline(len) "\e(0"<<'q'*len<<"\e(B" end
set_cursor_pos(y=1,x=1) click to toggle source
# File samples/dasmnavig.rb, line 17
def self.set_cursor_pos(y=1,x=1) "\e[#{y};#{x}H" end
set_term_canon(bool) click to toggle source
# File samples/dasmnavig.rb, line 48
def self.set_term_canon(bool)
        tty = ''.ljust(256)
        $stdin.ioctl(TCGETS, tty)
        if bool
                tty[12] &= ~(ECHO|CANON)
        else
                tty[12] |= ECHO|CANON
        end
        $stdin.ioctl(TCSETS, tty)
end