Module: CLAide::ANSI::Cursor
- Included in:
- CLAide::ANSI
- Defined in:
- lib/claide/ansi/cursor.rb
Overview
Provides support for generating escape sequences relative to the position of the cursor and to erase parts of text.
Class Method Summary collapse
-
.erase_display ⇒ String
The escape sequence to erase the display.
-
.erase_line ⇒ String
The escape sequence to erase a line form the cursor position to then end.
-
.move_cursor(lines, columns = 0) ⇒ String
The escape sequence to set the cursor at the given line.
-
.restore_cursor_position ⇒ String
The escape sequence to restore the cursor to the previously saved position.
-
.save_cursor_position ⇒ String
The escape sequence to save the cursor position.
-
.set_cursor_position(line = 0, column = 0) ⇒ String
The escape sequence to set the cursor at the given line.
Class Method Details
.erase_display ⇒ String
Returns The escape sequence to erase the display.
57 58 59 |
# File 'lib/claide/ansi/cursor.rb', line 57 def self.erase_display "\e[2J" end |
.erase_line ⇒ String
Returns The escape sequence to erase a line form the cursor position to then end.
64 65 66 |
# File 'lib/claide/ansi/cursor.rb', line 64 def self.erase_line "\e[K" end |
.move_cursor(lines, columns = 0) ⇒ String
Returns The escape sequence to set the cursor at the given line.
35 36 37 38 39 |
# File 'lib/claide/ansi/cursor.rb', line 35 def self.move_cursor(lines, columns = 0) lines_code = lines < 0 ? 'A' : 'B' columns_code = columns > 0 ? 'C' : 'D' "\e[#{lines.abs}#{lines_code};#{columns.abs}#{columns_code}" end |
.restore_cursor_position ⇒ String
Returns The escape sequence to restore the cursor to the previously saved position. This sequence also clears all the output after the position.
51 52 53 |
# File 'lib/claide/ansi/cursor.rb', line 51 def self.restore_cursor_position "\e[u" end |
.save_cursor_position ⇒ String
Returns The escape sequence to save the cursor position.
43 44 45 |
# File 'lib/claide/ansi/cursor.rb', line 43 def self.save_cursor_position "\e[s" end |
.set_cursor_position(line = 0, column = 0) ⇒ String
Returns The escape sequence to set the cursor at the given line.
18 19 20 |
# File 'lib/claide/ansi/cursor.rb', line 18 def self.set_cursor_position(line = 0, column = 0) "\e[#{line};#{column}H" end |