Module: RBText::Cursor

Defined in:
lib/rbtext/cursor.rb

Class Method Summary collapse

Class Method Details

.beginning_of_lineObject



42
43
44
# File 'lib/rbtext/cursor.rb', line 42

def self.beginning_of_line
  print "\r"
end

.down(num = 1) ⇒ Object



7
8
9
# File 'lib/rbtext/cursor.rb', line 7

def self.down(num=1)
  print "\033[#{num.to_i}B"
end

.go_to_pos(x, y = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/rbtext/cursor.rb', line 19

def self.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

.hideObject



50
51
52
# File 'lib/rbtext/cursor.rb', line 50

def self.hide
  print "\033[?25l"
end

.left(num = 1) ⇒ Object



11
12
13
# File 'lib/rbtext/cursor.rb', line 11

def self.left(num=1)
  print "\033[#{num.to_i}D"
end

.posObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rbtext/cursor.rb', line 29

def self.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



15
16
17
# File 'lib/rbtext/cursor.rb', line 15

def self.right(num=1)
  print "\033[#{num.to_i}C"
end

.showObject



46
47
48
# File 'lib/rbtext/cursor.rb', line 46

def self.show
  print "\033[?25h"
end

.up(num = 1) ⇒ Object



3
4
5
# File 'lib/rbtext/cursor.rb', line 3

def self.up(num=1)
  print "\033[#{num.to_i}A"
end