Class: TTYtest::Capture
- Inherits:
-
Object
- Object
- TTYtest::Capture
- Includes:
- Matchers
- Defined in:
- lib/ttytest/capture.rb
Overview
Represents the complete state of a Terminal at the time it was captured (contents, cursor position, etc).
Constant Summary
Constants included from Matchers
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.
-
#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.
-
#row(row_number) ⇒ String
The content of the row from the captured terminal.
-
#rows ⇒ Array<String>
An array of each row’s contend from the captured terminal.
-
#to_s ⇒ String
All rows of the captured terminal, separated by newlines.
Methods included from Matchers
#assert_contents, #assert_cursor_hidden, #assert_cursor_position, #assert_cursor_visible, #assert_row
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
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ttytest/capture.rb', line 15 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
7 8 9 |
# File 'lib/ttytest/capture.rb', line 7 def cursor_x @cursor_x end |
#cursor_y ⇒ Integer (readonly)
the cursor’s row (starting at 0) in the captured terminal
7 8 9 |
# File 'lib/ttytest/capture.rb', line 7 def cursor_y @cursor_y end |
#height ⇒ Integer (readonly)
the number of rows in the captured terminal
7 8 9 |
# File 'lib/ttytest/capture.rb', line 7 def height @height end |
#width ⇒ Integer (readonly)
the number of columns in the captured terminal
7 8 9 |
# File 'lib/ttytest/capture.rb', line 7 def width @width end |
Instance Method Details
#capture ⇒ Capture
Returns self
48 49 50 |
# File 'lib/ttytest/capture.rb', line 48 def capture self end |
#cursor_hidden? ⇒ true, false
Returns Whether the cursor is hidden in the captured terminal.
43 44 45 |
# File 'lib/ttytest/capture.rb', line 43 def cursor_hidden? !cursor_visible? end |
#cursor_visible? ⇒ true, false
Returns Whether the cursor is visible in the captured terminal.
38 39 40 |
# File 'lib/ttytest/capture.rb', line 38 def cursor_visible? @cursor_visible end |
#row(row_number) ⇒ String
Returns the content of the row from the captured terminal.
33 34 35 |
# File 'lib/ttytest/capture.rb', line 33 def row(row_number) rows[row_number] end |
#rows ⇒ Array<String>
Returns An array of each row’s contend from the captured terminal.
27 28 29 |
# File 'lib/ttytest/capture.rb', line 27 def rows @rows end |
#to_s ⇒ String
Returns All rows of the captured terminal, separated by newlines.
53 54 55 |
# File 'lib/ttytest/capture.rb', line 53 def to_s rows.join("\n") end |