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.
-
#rows ⇒ Array<String>
readonly
An array of each row’s contend 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.
-
#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 Matchers
#assert_contents, #assert_cursor_hidden, #assert_cursor_position, #assert_cursor_visible, #assert_row, #assert_row_at, #assert_row_ends_with, #assert_row_like, #assert_row_starts_with
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 contend 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 |
#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.
52 53 54 |
# File 'lib/ttytest/capture.rb', line 52 def to_s rows.join("\n") end |