Sha256: 2014c4fa2481ce13f086a45bb1764277d35bf4c3932a8677a8493628ffe31ec6
Contents?: true
Size: 1.85 KB
Versions: 5
Compression:
Stored size: 1.85 KB
Contents
# frozen_string_literal: true module TTYtest # Represents the complete state of a {TTYtest::Terminal} at the time it was captured (contents, cursor position, etc). # @attr_reader [Integer] width the number of columns in the captured terminal # @attr_reader [Integer] height the number of rows in the captured terminal # @attr_reader [Integer] cursor_x the cursor's column (starting at 0) in the captured terminal # @attr_reader [Integer] cursor_y the cursor's row (starting at 0) in the captured terminal class Capture include TTYtest::Matchers attr_reader :cursor_x, :cursor_y, :width, :height # Used internally by drivers when called by {Terminal#capture} # @api private 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 # @return [Array<String>] An array of each row's contend from the captured terminal attr_reader :rows # @param [Integer] the row to return # @return [String] the content of the row from the captured terminal def row(row_number) rows[row_number] end # @return [true,false] Whether the cursor is visible in the captured terminal def cursor_visible? @cursor_visible end # @return [true,false] Whether the cursor is hidden in the captured terminal def cursor_hidden? !cursor_visible? end # @return [Capture] returns self def capture self end def print puts "\n#{self}" end def print_rows p rows end # @return [String] All rows of the captured terminal, separated by newlines def to_s rows.join("\n") end end end
Version data entries
5 entries across 5 versions & 1 rubygems