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

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

Returns:

  • (Integer)

    the current value of cursor_x



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

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



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

def cursor_y
  @cursor_y
end

#heightInteger (readonly)

the number of rows in the captured terminal

Returns:

  • (Integer)

    the current value of height



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

def height
  @height
end

#rowsArray<String> (readonly)

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



28
29
30
# File 'lib/ttytest/capture.rb', line 28

def rows
  @rows
end

#widthInteger (readonly)

the number of columns in the captured terminal

Returns:

  • (Integer)

    the current value of width



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

def width
  @width
end

Instance Method Details

#captureCapture

Returns self

Returns:



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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Parameters:

  • the (Integer)

    row to return

Returns:

  • (String)

    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_sString

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

Returns:

  • (String)

    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