Module: Rcurses::Cursor

Included in:
Pane
Defined in:
lib/rcurses/cursor.rb

Constant Summary collapse

ESC =
"\e".freeze
CSI =
"\e[".freeze

Class Method Summary collapse

Class Method Details

.clear_char(n = 1) ⇒ Object

Erase n characters from the current cursor position



38
# File 'lib/rcurses/cursor.rb', line 38

def clear_char(n = 1); print(CSI + "#{n}X");                        end

.clear_lineObject

Erase the entire current line and return to beginning of the line



39
# File 'lib/rcurses/cursor.rb', line 39

def clear_line;        print(CSI + '2K' + CSI + "1G");              end

.clear_line_afterObject

Erase from the current position (inclusive) to the end of the line



41
# File 'lib/rcurses/cursor.rb', line 41

def clear_line_after;  print(CSI + '0K');                           end

.clear_line_beforeObject

Erase from the beginning of the line up to and including the current cursor position.



40
# File 'lib/rcurses/cursor.rb', line 40

def clear_line_before; print(CSI + '1K');                           end

.clear_screen_downObject

Clear screen down from current row



42
# File 'lib/rcurses/cursor.rb', line 42

def clear_screen_down; print(CSI + 'J');                            end

.col(c = 1) ⇒ Object

Cursor moves to nth position horizontally in the current line



34
# File 'lib/rcurses/cursor.rb', line 34

def col(c = 1);        print(CSI + "#{c}G");                        end

.colgetObject



25
26
27
28
# File 'lib/rcurses/cursor.rb', line 25

def colget
  _row, col = pos
  col
end

.down(n = 1) ⇒ Object

Move the cursor down by n



31
# File 'lib/rcurses/cursor.rb', line 31

def down(n = 1);       print(CSI + "#{(n)}B");                      end

.hideObject

Scroll display down one line



45
# File 'lib/rcurses/cursor.rb', line 45

def hide;              print(CSI + '?25l');                         end

.left(n = 1) ⇒ Object

Move the cursor backward by n



32
# File 'lib/rcurses/cursor.rb', line 32

def left(n = 1);       print(CSI + "#{n}D");                        end

.next_lineObject

Move cursor down to beginning of next line



36
# File 'lib/rcurses/cursor.rb', line 36

def next_line;         print(CSI + 'E' + CSI + "1G");               end

.posObject

Query cursor current position



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rcurses/cursor.rb', line 9

def pos # Query cursor current position
  res = ''
  $stdin.raw do |stdin|
    $stdout << CSI + '6n' # The actual ANSI get-position
    $stdout.flush
    while (c = stdin.getc) != 'R'
      res << c if c
    end
  end
  m = res.match(/(?<row>\d+);(?<col>\d+)/)
  return m[:row].to_i, m[:col].to_i
end

.prev_lineObject

Move cursor up to beginning of previous line



37
# File 'lib/rcurses/cursor.rb', line 37

def prev_line;         print(CSI + 'A' + CSI + "1G");               end

.restoreObject

Restore cursor position



8
# File 'lib/rcurses/cursor.rb', line 8

def restore; print(Gem.win_platform? ? CSI + 'u' : ESC + '8'); end

.right(n = 1) ⇒ Object

Move the cursor forward by n



33
# File 'lib/rcurses/cursor.rb', line 33

def right(n = 1);      print(CSI + "#{n}C");                        end

.row(r = 1) ⇒ Object

Cursor moves to the nth position vertically in the current column



35
# File 'lib/rcurses/cursor.rb', line 35

def row(r = 1);        print(CSI + "#{r}d");                        end

.rowgetObject



21
22
23
24
# File 'lib/rcurses/cursor.rb', line 21

def rowget
  row, _col = pos
  row
end

.saveObject

Save current position



7
# File 'lib/rcurses/cursor.rb', line 7

def save;    print(Gem.win_platform? ? CSI + 's' : ESC + '7'); end

.scroll_downObject

Scroll display down one line



44
# File 'lib/rcurses/cursor.rb', line 44

def scroll_down;       print(ESC + 'D');                            end

.scroll_upObject

Scroll display up one line



43
# File 'lib/rcurses/cursor.rb', line 43

def scroll_up;         print(ESC + 'M');                            end

.set(r = 1, c = 1) ⇒ Object

Set cursor position to Row, Col (y,x)



29
# File 'lib/rcurses/cursor.rb', line 29

def set(r = 1, c = 1); print(CSI + "#{r}d"); print(CSI + "#{c}G");  end

.showObject

Scroll display down one line



46
# File 'lib/rcurses/cursor.rb', line 46

def show;              print(CSI + '?25h');                         end

.up(n = 1) ⇒ Object

Move cursor up by n



30
# File 'lib/rcurses/cursor.rb', line 30

def up(n = 1);         print(CSI + "#{(n)}A");                      end