Class: TTYtest::Terminal

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ttytest/terminal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver_terminal) ⇒ Terminal

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Terminal.



16
17
18
19
# File 'lib/ttytest/terminal.rb', line 16

def initialize(driver_terminal)
  @driver_terminal = driver_terminal
  @max_wait_time = TTYtest.default_max_wait_time
end

Instance Attribute Details

#max_wait_timeInteger

the maximum amount of time (in seconds) to retry assertions before failing.

Returns:

  • (Integer)

    the current value of max_wait_time



9
10
11
# File 'lib/ttytest/terminal.rb', line 9

def max_wait_time
  @max_wait_time
end

Instance Method Details

#captureCapture

Capture the current state of the terminal

Returns:

  • (Capture)

    instantaneous state of the terminal when called



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#cursor_hidden?true, false

Returns:

  • (true, false)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#cursor_visible?true, false

Returns:

  • (true, false)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#cursor_xInteger

Returns:

  • (Integer)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#cursor_yInteger

Returns:

  • (Integer)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#heightInteger

Returns:

  • (Integer)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

Prints the current state of the terminal to stdout. See capture to get the raw string.



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

Prints the current state of the terminal as an array to stdout. See rows to get the raw array.



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#row(row) ⇒ String

Returns:

  • (String)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#rowsArray<String>

Returns:

  • (Array<String>)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?

#send_backspaceObject

Simulate typing the backspace key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_backspacesObject

Simulates typing backspace the specified number of times.

Parameters:

  • number (Integer)

    of times to send backspace



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_clearObject

Clears the screen in the terminal using ascii clear command.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_deleteObject

Simulate typing the delete key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_deletesObject

Simulates typing delete the specified number of times.

Parameters:

  • number (Integer)

    of times to send delete



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_down_arrowObject

Simulate typing the down arrow key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_down_arrowsObject

Simulates typing the down arrow the specified number of times.

Parameters:

  • number (Integer)

    of times to send down arrow



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_endObject

Simulates typing in the End key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_escapeObject

Simulates typing in the Escape (ESC) key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_homeObject

Simulates typing in the Home key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_keys(*keys) ⇒ Object

Simulate typing keys into the terminal. For canonical cli’s/shells which read line by line.

Parameters:

  • keys (String)

    keys to send to the terminal



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_keys_exactObject

Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_keys_one_at_a_time(keys) ⇒ Object

Simulate typing keys into the terminal. For noncanonical cli’s/shells which read character by character.

Parameters:

  • keys (String)

    keys to send to the terminal



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_left_arrowObject

Simulate typing the left arrow key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_left_arrowsObject

Simulates typing left arrow the specified number of times.

Parameters:

  • number (Integer)

    of times to send left arrow



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_line(line) ⇒ Object

Simulate sending a line to the terminal and hitting enter.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_line_then_sleep(line, sleep_time) ⇒ Object

Simulate sending a line to the terminal and hitting enter, then wait for the sleep_time.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_newlineObject

Simulate typing enter by sending newline character to the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_newlinesObject

Simulates sending newline the specified number of times.

Parameters:

  • number (Integer)

    of times to send newline



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_right_arrowObject

Simulate typing the right arrow key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_right_arrowsObject

Simulates typing right arrow the specified number of times.

Parameters:

  • number (Integer)

    of times to send right arrow



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_up_arrowObject

Simulate typing the up arrow key in the terminal.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#send_up_arrowsObject

Simulates typing the up arrow the specified number of times.

Parameters:

  • number (Integer)

    of times to send up arrow



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttytest/terminal.rb', line 79

def_delegators :@driver_terminal,
:send_keys, :send_keys_one_at_a_time,
:send_line, :send_line_then_sleep,
:send_newline, :send_newlines,
:send_delete, :send_deletes,
:send_backspace, :send_backspaces,
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
:capture

#widthInteger

Returns:

  • (Integer)

See Also:



118
119
120
121
122
# File 'lib/ttytest/terminal.rb', line 118

def_delegators :capture, :print, :print_rows,
:rows, :row,
:width, :height,
:cursor_x, :cursor_y,
:cursor_visible?, :cursor_hidden?