Module: ConsoleGlitter::Screen

Extended by:
Screen
Included in:
Screen
Defined in:
lib/console-glitter/screen.rb

Instance Method Summary collapse

Instance Method Details

#clear(direction = :both) ⇒ Object Also known as: clear_to

Public: From the cursor’s position clear either the whole screen, or from the cursor’s position to the beginning or end of the screen.

direction - Symbol denoting the direction the screen should be cleared,

between :both :end or :beginning.  (default: :both)

Returns a String containing the VT control code.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/console-glitter/screen.rb', line 12

def clear(direction = :both)
  options = [:both, :beginning, :end]
  target  = "clear_to_#{direction}"
  return(self.send(target)) if options.grep(direction).any?

  raise(ArgumentError,
        "Expected :both, :end, or :beginning, got #{direction}.")
end

#clear_to_beginningObject

Public: Return the VT control code to clear from the cursor to the beginning of the screen.

Returns a String containing the VT control code.



34
35
36
# File 'lib/console-glitter/screen.rb', line 34

def clear_to_beginning
  ConsoleGlitter.escape('1J')
end

#clear_to_bothObject Also known as: clear_screen

Public: Return the VT control code to clear the screen.

Returns a String containing the VT control code.



41
42
43
# File 'lib/console-glitter/screen.rb', line 41

def clear_to_both
  ConsoleGlitter.escape('2J')
end

#clear_to_endObject

Public: Return the VT control code to clear from the cursor to the end of the screen.

Returns a String containing the VT control code.



26
27
28
# File 'lib/console-glitter/screen.rb', line 26

def clear_to_end
  ConsoleGlitter.escape('0J')
end

#erase_line(direction = :both) ⇒ Object Also known as: erase_line_to

Public: From the cursor’s position clear either the whole line, or from the cursor’s position to the beginning or end of the line.

direction - Symbol denoting the direction the line should be cleared,

between :both :end or :beginning.  (default: :both)

Returns a String containing the VT control code.

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
# File 'lib/console-glitter/screen.rb', line 53

def erase_line(direction = :both)
  options = [:both, :beginning, :end]
  target  = "erase_line_to_#{direction}"
  return(self.send(target)) if options.grep(direction).any?

  raise(ArgumentError,
        "Expected :both, :end, or :beginning, got #{direction}.")
end

#erase_line_to_beginningObject

Public: Return the VT control code to clear from the cursor to the beginning of the line.

Returns a String containing the VT control code.



75
76
77
# File 'lib/console-glitter/screen.rb', line 75

def erase_line_to_beginning
  ConsoleGlitter.escape('1K')
end

#erase_line_to_bothObject

Public: Return the VT control code to clear the line where the cursor is.

Returns a String containing the VT control code.



82
83
84
# File 'lib/console-glitter/screen.rb', line 82

def erase_line_to_both
  ConsoleGlitter.escape('2K')
end

#erase_line_to_endObject

Public: Return the VT control code to clear from the cursor to the end of the line.

Returns a String containing the VT control code.



67
68
69
# File 'lib/console-glitter/screen.rb', line 67

def erase_line_to_end
  ConsoleGlitter.escape('0K')
end

#scroll_down(distance = 1) ⇒ Object

Public: Return the VT control code to scroll the screen down by a given amount.

distance - Number of lines to scroll the screen. (default: 1)

Returns a String containing the VT control code.



102
103
104
# File 'lib/console-glitter/screen.rb', line 102

def scroll_down(distance = 1)
  ConsoleGlitter.escape("#{distance}T")
end

#scroll_up(distance = 1) ⇒ Object

Public: Return the VT control code to scroll the screen up by a given amount.

distance - Number of lines to scroll the screen. (default: 1)

Returns a String containing the VT control code.



92
93
94
# File 'lib/console-glitter/screen.rb', line 92

def scroll_up(distance = 1)
  ConsoleGlitter.escape("#{distance}S")
end