Module: Console

Included in:
Pecorb
Defined in:
lib/pecorb/console.rb

Constant Summary collapse

CSI =
"\e["
UP =
"#{CSI}A"
DOWN =
"#{CSI}B"
RIGHT =
"#{CSI}C"
LEFT =
"#{CSI}D"

Instance Method Summary collapse

Instance Method Details

#backspace(n = 1) ⇒ Object



33
# File 'lib/pecorb/console.rb', line 33

def backspace(n=1)      $stderr.print "\b"*n              end

#blackObject



38
# File 'lib/pecorb/console.rb', line 38

def black()             $stderr.print "#{CSI}#{CSI}30m"   end

#blueObject



42
# File 'lib/pecorb/console.rb', line 42

def blue()              $stderr.print "#{CSI}#{CSI}34m"   end

#carriage_returnObject



34
# File 'lib/pecorb/console.rb', line 34

def carriage_return()   $stderr.print "\r"                end

#clear_screenObject



36
# File 'lib/pecorb/console.rb', line 36

def clear_screen()      $stderr.print "#{CSI}H#{CSI}J"    end

#clear_to_eolObject



35
# File 'lib/pecorb/console.rb', line 35

def clear_to_eol()      $stderr.print "#{CSI}K"           end

#cyanObject



44
# File 'lib/pecorb/console.rb', line 44

def cyan()              $stderr.print "#{CSI}#{CSI}36m"   end

#down(n = 1) ⇒ Object



29
# File 'lib/pecorb/console.rb', line 29

def down(n=1)           $stderr.print "#{CSI}#{n}B"       end

#greenObject



40
# File 'lib/pecorb/console.rb', line 40

def green()             $stderr.print "#{CSI}#{CSI}32m"   end

#left(n = 1) ⇒ Object



31
# File 'lib/pecorb/console.rb', line 31

def left(n=1)           $stderr.print "#{CSI}#{n}D"       end

#load_posObject



55
# File 'lib/pecorb/console.rb', line 55

def load_pos() $stderr.print "#{CSI}u" end

#magentaObject



43
# File 'lib/pecorb/console.rb', line 43

def magenta()           $stderr.print "#{CSI}#{CSI}35m"   end

#output(val) ⇒ Object



26
# File 'lib/pecorb/console.rb', line 26

def output(val)         $stdout.puts val                  end


24
# File 'lib/pecorb/console.rb', line 24

def print(val)          $stderr.print val                 end

#puts(val) ⇒ Object



25
# File 'lib/pecorb/console.rb', line 25

def puts(val)           $stderr.puts val                  end

#read_charObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pecorb/console.rb', line 10

def read_char
  $stdin.echo = false
  $stdin.raw!
  input = $stdin.getc.chr
  if input == "\e" then
    input << $stdin.read_nonblock(3) rescue nil
    input << $stdin.read_nonblock(2) rescue nil
  end
ensure
  $stdin.echo = true
  $stdin.cooked!
  return input
end

#redObject



39
# File 'lib/pecorb/console.rb', line 39

def red()               $stderr.print "#{CSI}#{CSI}31m"   end

#reset_colorObject



46
# File 'lib/pecorb/console.rb', line 46

def reset_color()       $stderr.print "#{CSI}#{CSI}0m"    end

#right(n = 1) ⇒ Object



30
# File 'lib/pecorb/console.rb', line 30

def right(n=1)          $stderr.print "#{CSI}#{n}C"       end

#save_posObject



48
49
50
51
52
53
54
# File 'lib/pecorb/console.rb', line 48

def save_pos
  $stderr.print "#{CSI}s"
  if block_given?
    yield
    load_pos
  end
end

#up(n = 1) ⇒ Object



28
# File 'lib/pecorb/console.rb', line 28

def up(n=1)             $stderr.print "#{CSI}#{n}A"       end

#whiteObject



45
# File 'lib/pecorb/console.rb', line 45

def white()             $stderr.print "#{CSI}#{CSI}37m"   end

#yellowObject



41
# File 'lib/pecorb/console.rb', line 41

def yellow()            $stderr.print "#{CSI}#{CSI}33m"   end