Class: TTYtest::Capture
- Inherits:
-
Object
- Object
- TTYtest::Capture
- Includes:
- Assertions
- Defined in:
- lib/ttytest/capture.rb
Overview
Represents the complete state of a Terminal at the time it was captured, including contents, cursor position, etc.
Constant Summary
Constants included from Assertions
Instance Attribute Summary collapse
-
#cursor_x ⇒ Integer
readonly
The cursor’s column (starting at 0) in the captured terminal.
-
#cursor_y ⇒ Integer
readonly
The cursor’s row (starting at 0) in the captured terminal.
-
#height ⇒ Integer
readonly
The number of rows in the captured terminal.
-
#rows ⇒ Array<String>
readonly
An array of each row’s contents from the captured terminal.
-
#width ⇒ Integer
readonly
The number of columns in the captured terminal.
Instance Method Summary collapse
-
#capture ⇒ Capture
Returns self.
-
#cursor_hidden? ⇒ true, false
Whether the cursor is hidden in the captured terminal.
-
#cursor_visible? ⇒ true, false
Whether the cursor is visible in the captured terminal.
-
#initialize(contents, cursor_x: 0, cursor_y: 0, width: nil, height: nil, cursor_visible: true) ⇒ Capture
constructor
private
Used internally by drivers when called by Terminal#capture.
-
#print ⇒ Object
Prints out the current terminal contents.
-
#print_rows ⇒ Object
Prints out the current terminal contents as an array of strings separated by lines.
-
#row(row_number) ⇒ String
The content of the row from the captured terminal.
-
#to_s ⇒ String
All rows of the captured terminal, separated by newlines.
Methods included from Assertions
#assert_contents, #assert_contents_at, #assert_contents_empty, #assert_contents_include, #assert_contents_match_regexp, #assert_cursor_hidden, #assert_cursor_position, #assert_cursor_visible, #assert_file_contains, #assert_file_doesnt_exist, #assert_file_exists, #assert_file_has_line_count, #assert_file_has_permissions, #assert_row, #assert_row_at, #assert_row_ends_with, #assert_row_is_empty, #assert_row_like, #assert_row_regexp, #assert_row_starts_with, #assert_rows_each_match_regexp
Constructor Details
#initialize(contents, cursor_x: 0, cursor_y: 0, width: nil, height: nil, cursor_visible: true) ⇒ Capture
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.
Used internally by drivers when called by Terminal#capture
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ttytest/capture.rb', line 16 def initialize(contents, cursor_x: 0, cursor_y: 0, width: nil, height: nil, cursor_visible: true) @rows = "#{contents}\nEND".split("\n")[0...-1].map do |row| row || '' end @cursor_x = cursor_x @cursor_y = cursor_y @width = width @height = height @cursor_visible = cursor_visible end |
Instance Attribute Details
#cursor_x ⇒ Integer (readonly)
The cursor’s column (starting at 0) in the captured terminal.
9 10 11 |
# File 'lib/ttytest/capture.rb', line 9 def cursor_x @cursor_x end |
#cursor_y ⇒ Integer (readonly)
The cursor’s row (starting at 0) in the captured terminal.
9 10 11 |
# File 'lib/ttytest/capture.rb', line 9 def cursor_y @cursor_y end |
#height ⇒ Integer (readonly)
The number of rows in the captured terminal.
9 10 11 |
# File 'lib/ttytest/capture.rb', line 9 def height @height end |
#rows ⇒ Array<String> (readonly)
Returns An array of each row’s contents from the captured terminal.
28 29 30 |
# File 'lib/ttytest/capture.rb', line 28 def rows @rows end |
#width ⇒ Integer (readonly)
The number of columns in the captured terminal.
9 10 11 |
# File 'lib/ttytest/capture.rb', line 9 def width @width end |
Instance Method Details
#capture ⇒ Capture
Returns self
47 48 49 |
# File 'lib/ttytest/capture.rb', line 47 def capture self end |
#cursor_hidden? ⇒ true, false
Returns Whether the cursor is hidden in the captured terminal.
42 43 44 |
# File 'lib/ttytest/capture.rb', line 42 def cursor_hidden? !cursor_visible? end |
#cursor_visible? ⇒ true, false
Returns Whether the cursor is visible in the captured terminal.
37 38 39 |
# File 'lib/ttytest/capture.rb', line 37 def cursor_visible? @cursor_visible end |
#print ⇒ Object
Prints out the current terminal contents.
52 53 54 |
# File 'lib/ttytest/capture.rb', line 52 def print puts "\n#{self}" end |
#print_rows ⇒ Object
Prints out the current terminal contents as an array of strings separated by lines.
57 58 59 |
# File 'lib/ttytest/capture.rb', line 57 def print_rows p rows end |
#row(row_number) ⇒ String
Returns The content of the row from the captured terminal.
32 33 34 |
# File 'lib/ttytest/capture.rb', line 32 def row(row_number) rows[row_number] end |
#to_s ⇒ String
Returns All rows of the captured terminal, separated by newlines.
62 63 64 |
# File 'lib/ttytest/capture.rb', line 62 def to_s rows.join("\n") end |