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
- #backspace(n = 1) ⇒ Object
- #black ⇒ Object
- #blue ⇒ Object
- #carriage_return ⇒ Object
- #clear_screen ⇒ Object
- #clear_to_eol ⇒ Object
- #clear_to_eos ⇒ Object
- #cyan ⇒ Object
- #down(n = 1) ⇒ Object
- #green ⇒ Object
- #left(n = 1) ⇒ Object
- #load_pos ⇒ Object
- #magenta ⇒ Object
- #print(val = "") ⇒ Object
- #puts(val = "") ⇒ Object
- #read_char ⇒ Object
- #red ⇒ Object
- #reset_color ⇒ Object
- #right(n = 1) ⇒ Object
-
#save_pos ⇒ Object
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.
- #up(n = 1) ⇒ Object
- #white ⇒ Object
- #yellow ⇒ Object
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 |
#black ⇒ Object
40 |
# File 'lib/pecorb/console.rb', line 40 def black() output_stream.print "#{CSI}#{CSI}30m" end |
#blue ⇒ Object
44 |
# File 'lib/pecorb/console.rb', line 44 def blue() output_stream.print "#{CSI}#{CSI}34m" end |
#carriage_return ⇒ Object
35 |
# File 'lib/pecorb/console.rb', line 35 def carriage_return() output_stream.print "\r" end |
#clear_screen ⇒ Object
38 |
# File 'lib/pecorb/console.rb', line 38 def clear_screen() output_stream.print "#{CSI}H#{CSI}J" end |
#clear_to_eol ⇒ Object
36 |
# File 'lib/pecorb/console.rb', line 36 def clear_to_eol() output_stream.print "#{CSI}K" end |
#clear_to_eos ⇒ Object
37 |
# File 'lib/pecorb/console.rb', line 37 def clear_to_eos() output_stream.print "#{CSI}J" end |
#cyan ⇒ Object
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 |
#green ⇒ Object
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_pos ⇒ Object
59 |
# File 'lib/pecorb/console.rb', line 59 def load_pos() output_stream.print "#{CSI}u" end |
#magenta ⇒ Object
45 |
# File 'lib/pecorb/console.rb', line 45 def magenta() output_stream.print "#{CSI}#{CSI}35m" end |
#print(val = "") ⇒ Object
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_char ⇒ Object
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 |
#red ⇒ Object
41 |
# File 'lib/pecorb/console.rb', line 41 def red() output_stream.print "#{CSI}#{CSI}31m" end |
#reset_color ⇒ Object
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_pos ⇒ Object
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 |
#white ⇒ Object
47 |
# File 'lib/pecorb/console.rb', line 47 def white() output_stream.print "#{CSI}#{CSI}37m" end |
#yellow ⇒ Object
43 |
# File 'lib/pecorb/console.rb', line 43 def yellow() output_stream.print "#{CSI}#{CSI}33m" end |