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 ]
Instance Method Summary collapse
- #beginning_of_line ⇒ Object
- #down(num = 1) ⇒ Object
- #go_to_pos(x, y = nil) ⇒ Object
- #left(num = 1) ⇒ Object
- #pos ⇒ Object
- #right(num = 1) ⇒ Object
- #up(num = 1) ⇒ Object
Instance Method Details
#beginning_of_line ⇒ Object
52 53 54 |
# File 'lib/rbtext/cursor.rb', line 52 def beginning_of_line print "\r" end |
#down(num = 1) ⇒ Object
17 18 19 |
# File 'lib/rbtext/cursor.rb', line 17 def down(num=1) print "\033[#{num.to_i}B" end |
#go_to_pos(x, y = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/rbtext/cursor.rb', line 29 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 |
#left(num = 1) ⇒ Object
21 22 23 |
# File 'lib/rbtext/cursor.rb', line 21 def left(num=1) print "\033[#{num.to_i}D" end |
#pos ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rbtext/cursor.rb', line 39 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
25 26 27 |
# File 'lib/rbtext/cursor.rb', line 25 def right(num=1) print "\033[#{num.to_i}C" end |
#up(num = 1) ⇒ Object
13 14 15 |
# File 'lib/rbtext/cursor.rb', line 13 def up(num=1) print "\033[#{num.to_i}A" end |