Module: RBText::Cursor
- Included in:
- Cr
- Defined in:
- lib/rbtext/cursor.rb
Constant Summary collapse
- @@methods =
[ :up, :down, :left, :right, :beginning_of_line, :go_to_pos, :pos, :show, :hide ]
Instance Method Summary collapse
- #beginning_of_line ⇒ Object
- #down(num = 1) ⇒ Object
- #go_to_pos(x, y = nil) ⇒ Object
- #hide ⇒ Object
- #left(num = 1) ⇒ Object
- #pos ⇒ Object
- #right(num = 1) ⇒ Object
- #show ⇒ Object
- #up(num = 1) ⇒ Object
Instance Method Details
#beginning_of_line ⇒ Object
54 55 56 |
# File 'lib/rbtext/cursor.rb', line 54 def beginning_of_line print "\r" end |
#down(num = 1) ⇒ Object
19 20 21 |
# File 'lib/rbtext/cursor.rb', line 19 def down(num=1) print "\033[#{num.to_i}B" end |
#go_to_pos(x, y = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/rbtext/cursor.rb', line 31 def go_to_pos(x, y=nil) if x.class == Array && !y y = x[1] x = x[0] end print "\033[#{y};#{x}H" print "\033[#{y};#{x}f" end |
#hide ⇒ Object
62 63 64 |
# File 'lib/rbtext/cursor.rb', line 62 def hide print "\033[?25l" end |
#left(num = 1) ⇒ Object
23 24 25 |
# File 'lib/rbtext/cursor.rb', line 23 def left(num=1) print "\033[#{num.to_i}D" end |
#pos ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rbtext/cursor.rb', line 41 def pos res = '' $stdin.raw do |stdin| $stdout << "\e[6n" $stdout.flush while (c = stdin.getc) != 'R' res << c if c end end m = res.match /(?<row>\d+);(?<column>\d+)/ return [Integer(m[:column]), Integer(m[:row])] end |
#right(num = 1) ⇒ Object
27 28 29 |
# File 'lib/rbtext/cursor.rb', line 27 def right(num=1) print "\033[#{num.to_i}C" end |
#show ⇒ Object
58 59 60 |
# File 'lib/rbtext/cursor.rb', line 58 def show print "\033[?25h" end |
#up(num = 1) ⇒ Object
15 16 17 |
# File 'lib/rbtext/cursor.rb', line 15 def up(num=1) print "\033[#{num.to_i}A" end |