Class: TTYtest::Capture

Inherits:
Object
  • Object
show all
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

Matchers::METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

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_xInteger (readonly)

the cursor’s column (starting at 0) in the captured terminal

Returns:

  • (Integer)

    the current value of cursor_x



7
8
9
# File 'lib/ttytest/capture.rb', line 7

def cursor_x
  @cursor_x
end

#cursor_yInteger (readonly)

the cursor’s row (starting at 0) in the captured terminal

Returns:

  • (Integer)

    the current value of cursor_y



7
8
9
# File 'lib/ttytest/capture.rb', line 7

def cursor_y
  @cursor_y
end

#heightInteger (readonly)

the number of rows in the captured terminal

Returns:

  • (Integer)

    the current value of height



7
8
9
# File 'lib/ttytest/capture.rb', line 7

def height
  @height
end

#widthInteger (readonly)

the number of columns in the captured terminal

Returns:

  • (Integer)

    the current value of width



7
8
9
# File 'lib/ttytest/capture.rb', line 7

def width
  @width
end

Instance Method Details

#captureCapture

Returns self

Returns:



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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Parameters:

  • the (Integer)

    row to return

Returns:

  • (String)

    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

#rowsArray<String>

Returns An array of each row’s contend from the captured terminal.

Returns:

  • (Array<String>)

    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_sString

Returns All rows of the captured terminal, separated by newlines.

Returns:

  • (String)

    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