Module: Pecorb::Console

Included in:
List
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



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

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

#blackObject



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

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

#blueObject



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

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

#carriage_returnObject



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

def carriage_return()   output_stream.print "\r"                end

#clear_screenObject



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

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

#clear_to_eolObject



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

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

#clear_to_eosObject



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

def clear_to_eos()      output_stream.print "#{CSI}J"           end

#cyanObject



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

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

#down(n = 1) ⇒ Object



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

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

#greenObject



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

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

#left(n = 1) ⇒ Object



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

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

#load_posObject



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

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

#magentaObject



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

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


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

def print(val="")       output_stream.print val                 end

#puts(val = "") ⇒ Object



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

def puts(val="")        output_stream.puts val                  end

#read_charObject



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

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

#redObject



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

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

#reset_colorObject



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

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

#right(n = 1) ⇒ Object



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

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

#save_posObject

WARNING: Only use this for updates, when we can be sure no new lines will be added as this causes lines to be overwritten, see issue #1



52
53
54
55
56
57
58
# File 'lib/pecorb/console.rb', line 52

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

#up(n = 1) ⇒ Object



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

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

#whiteObject



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

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

#yellowObject



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

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