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

Class Method Details

.erase_displayString

Returns The escape sequence to erase the display.

Returns:

  • (String)

    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_lineString

Returns The escape sequence to erase a line form the cursor position to then end.

Returns:

  • (String)

    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.

Parameters:

  • lines (Fixnum)

    The amount of lines the cursor should be moved to. Negative values indicate up direction and positive ones down direction.

  • columns (Fixnum) (defaults to: 0)

    The amount of columns the cursor should be moved to. Negative values indicate left direction and positive ones right direction.

Returns:

  • (String)

    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_positionString

Returns The escape sequence to restore the cursor to the previously saved position. This sequence also clears all the output after the position.

Returns:

  • (String)

    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_positionString

Returns The escape sequence to save the cursor position.

Returns:

  • (String)

    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.

Parameters:

  • line (Fixnum) (defaults to: 0)

    The line where to place the cursor.

  • column (Fixnum) (defaults to: 0)

    The column where to place the cursor.

Returns:

  • (String)

    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