### Install ttytest2 in Dockerfile Source: https://github.com/a-eski/ttytest2/blob/main/README.md Add these commands to your Dockerfile to install the necessary dependencies and the ttytest2 gem. Uncomment the ENV line if you encounter encoding issues. ```dockerfile RUN apt update && \ apt install gcc make ruby tmux -y && \ gem install ttytest2 # add this if you have issues # ENV RUBYOPT="-KU -E utf-8:utf-8" ``` -------------------------------- ### Send F-keys to terminal Source: https://github.com/a-eski/ttytest2/blob/main/README.md Demonstrates how to initialize a terminal and send function keys (F1-F12) using send_keys_exact. ```ruby @tty = TTYtest.new_terminal(%{PS1='$ ' /bin/sh}, width: 80, height: 24) @tty.send_keys_exact(%(F1)) @tty.send_keys_exact(%(F2)) # ... @tty.send_keys_exact('F11') @tty.send_keys_exact('F12') ``` -------------------------------- ### Initialize ttytest2 Terminal Instances Source: https://github.com/a-eski/ttytest2/blob/main/README.md Demonstrates various ways to initialize a terminal instance, including default settings and custom shell configurations. ```ruby require 'ttytest' # these are all equivalent @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh)) @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 24) @tty = TTYtest.new_default_sh_terminal @tty = TTYtest.new_sh_terminal @tty = TTYtest.new_sh_terminal(width: 80, height: 24) # you can also use other shells, like bash @tty = TTYtest.new_terminal('/bin/bash') @tty = TTYtest.new_terminal('/bin/bash', width: 80, height: 24) # you can specify further options, see section Configurables. ``` -------------------------------- ### Push new version to GitHub Source: https://github.com/a-eski/ttytest2/blob/main/notes.txt Commands to create a version tag and push it to the origin repository. ```bash git tag v1.6.1 git push origin --tags ``` -------------------------------- ### Simple Terminal Integration Test Source: https://github.com/a-eski/ttytest2/blob/main/README.md Demonstrates initializing a terminal session, sending input, and performing various assertions on terminal contents and cursor position. ```ruby require 'ttytest' @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7) @tty.assert_row(0, '$') @tty.assert_cursor_position(2, 0) @tty.send_line('echo "Hello, world"')) @tty.assert_contents <<~TTY $ echo "Hello, world" Hello, world $ TTY @tty.assert_cursor_position(2, 2) @tty.assert_contents_at(0, 0, '$ echo "Hello, world"') @tty.assert_row_starts_with(0, '$ echo') @tty.assert_row_ends_with(0, '"Hello, world"') @tty.assert_row_starts_with(1, 'Hello') @tty.assert_row_ends_with(1, ', world') @tty.print_rows # prints out the contents of the terminal as an array: # ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ""] @tty.print # prints out the contents of the terminal: # $ echo "Hello, world" # Hello, world # $ ``` -------------------------------- ### Output Helpers Source: https://github.com/a-eski/ttytest2/blob/main/README.md Convenience methods for simulating specific terminal keys and actions. ```APIDOC ## send_newline / send_newlines(number_of_times) - Simulates hitting enter. ## send_return / send_returns(number_of_times) - Simulates hitting return (\r). ## send_backspace / send_backspaces(number_of_times) - Simulates hitting backspace. ## send_delete / send_deletes(number_of_times) - Simulates hitting delete. ## send_right_arrow / send_right_arrows(number_of_times) - Simulates right arrow key. ## send_left_arrow / send_left_arrows(number_of_times) - Simulates left arrow key. ## send_up_arrow / send_up_arrows(number_of_times) - Simulates up arrow key. ## send_down_arrow / send_down_arrows(number_of_times) - Simulates down arrow key. ## send_home / send_end - Simulates Home and End keys. ## send_clear - Clears the terminal screen. ## send_escape / send_escapes(number_of_times) - Simulates escape key. ## send_tab / send_tabs(number_of_times) - Simulates tab key. ``` -------------------------------- ### Terminal Initialization Source: https://github.com/a-eski/ttytest2/blob/main/README.md Methods to initialize a new tmux terminal instance for testing. ```APIDOC ## TTYtest.new_terminal(cmd, width, height, max_wait_time, use_return_for_newline) ### Description Initializes a new tmux terminal instance and runs the specified command. ### Parameters - **cmd** (string) - Required - The command to run in the terminal. - **width** (integer) - Optional - Terminal width. - **height** (integer) - Optional - Terminal height. - **max_wait_time** (integer) - Optional - Maximum time to wait for assertions. - **use_return_for_newline** (boolean) - Optional - Whether to use return for newline. ## TTYtest.new_default_sh_terminal() ### Description Initializes a new tmux terminal instance using sh with a default width of 80 and height of 24. ## TTYtest.new_sh_terminal(width, height, max_wait_time, use_return_for_newline) ### Description Initializes a new tmux terminal instance using sh. ``` -------------------------------- ### Base Functions Source: https://github.com/a-eski/ttytest2/blob/main/README.md Core methods for sending raw input to the terminal pane. ```APIDOC ## send_keys(output) - Sends output to the terminal for canonical apps. ## send_keys_one_at_a_time(output) - Sends output character by character for noncanonical apps. ## send_keys_exact(output) - Sends keys exactly as provided, including tmux-specific arguments like DC or Escape. ``` -------------------------------- ### Assertions Source: https://github.com/a-eski/ttytest2/blob/main/README.md Methods for asserting terminal state, content, and file system properties. ```APIDOC ## Row Assertions - `assert_row(row_number, expected_text)` - `assert_row_is_empty(row_number)` - `assert_row_at(row_number, column_start_position, column_end_position, expected_text)` - `assert_row_like(row_number, expected_text)` - `assert_row_starts_with(row_number, expected_text)` - `assert_row_ends_with(row_number, expected_text)` - `assert_row_regexp(row_number, regexp_str)` - `assert_rows_each_match_regexp(row_start, row_end, regexp_str)` - `assert_rows_match_regexp(row_start, row_end, regexp_str, remove_newlines: false)` ## Column Assertions - `assert_column(col_number, expected_text)` - `assert_column_is_empty(col_number)` - `assert_column_at(col_number, row_start, row_end, expected_str)` - `assert_column_starts_with(col_number, expected_text)` - `assert_column_ends_with(col_number, expected_text)` - `assert_column_regexp(col_number, regexp_str)` - `assert_columns_each_match_regexp(col_start, col_end, regexp_str)` - `assert_columns_match_regexp(col_start, col_end, regexp_str, remove_newlines: false)` ## Cursor Assertions - `assert_cursor_position(x: x, y: y)` - `assert_cursor_visible` - `assert_cursor_hidden` ## Screen Contents Assertions - `assert_contents(lines_of_terminal)` - `assert_contents_at(row_start, row_end, expected_text)` - `assert_contents_include(expected)` - `assert_contents_empty` - `assert_contents_match_regexp(regexp_str)` ## File Assertions - `assert_file_exists(file_path)` - `assert_file_doesnt_exist(file_path)` - `assert_file_contains(file_path, needle)` - `assert_file_has_permissions(file_path, permissions)` - `assert_file_has_line_count(file_path, expected_count)` ``` -------------------------------- ### Push new version to RubyGems.org Source: https://github.com/a-eski/ttytest2/blob/main/notes.txt Commands to build the gem from the gemspec and push the resulting file to RubyGems. ```bash gem build ttytest2.gemspec gem push ttytest2-1.6.1.gem ``` -------------------------------- ### Ergonomic Functions Source: https://github.com/a-eski/ttytest2/blob/main/README.md High-level methods for simulating typing commands and handling line-based input. ```APIDOC ## send_line(line) - Simulates typing a command and hitting enter. ## send_line_then_sleep(line, sleep_time) - Simulates typing a command, hitting enter, and waiting for a specified duration. ## send_lines(lines) - Simulates sending multiple lines, each followed by an enter key. ## send_lines_then_sleep(lines, sleep_time) - Simulates sending multiple lines, then sleeping after all lines are sent. ## send_line_then_sleep_and_repeat(lines, sleep_time) - Simulates sending lines with a sleep interval between each line. ## send_line_exact(line) - Sends a line exactly as is to tmux. ## send_line_exact_then_sleep(line, sleep_time) - Sends a line exactly as is, then sleeps. ## send_lines_exact(lines) - Sends multiple lines exactly as they are. ## send_lines_exact_then_sleep(lines, sleep_time) - Sends multiple lines exactly as they are, then sleeps. ## send_line_exact_then_sleep_and_repeat(lines, sleep_time) - Sends multiple lines exactly as they are with a sleep interval between each. ``` -------------------------------- ### Configure use_return_for_newline Source: https://github.com/a-eski/ttytest2/blob/main/README.md Configures the terminal to use carriage return ('/r') instead of newline ('/n') for line-sending methods. This is useful for environments that interpret these characters differently. ```ruby @tty = TTYtest::new_terminal('', use_return_for_newline: true) # specified to use return in place of newline @tty.send_line('hello, world!') # will have return sent after 'hello, world!' @tty.use_return_for_newline = false @tty.assert_row(0, 'echo Hello, world') # will have newline sent after 'echo Hello, world' ``` -------------------------------- ### TTYtest Key Constants Source: https://github.com/a-eski/ttytest2/blob/main/README.md Lists available constants for special terminal keys and control sequences that can be used with send_keys_exact. ```ruby # can use like: send_keys_exact(TTYtest::CTRLA) TTYtest::CTRLA TTYtest::CTRLB TTYtest::CTRLC TTYtest::CTRLD TTYtest::CTRLF TTYtest::BELL # ring the terminal bell TTYtest::BACKSPACE TTYtest::TAB TTYtest::NEWLINE # \n TTYtest::ENTER # \n TTYtest::VERTICAL_TAB # \v TTYtest::SHIFT_ENTER # \v TTYtest::FORM_FEED # \f or New Page NP TTYtest::CTRLL TTYtest::RETURN # \r TTYtest::CTRLU TTYtest::CTRLW TTYtest::ESCAPE # 27 decimal or ^[ or /033 TTYtest::CTRL_ TTYtest::DELETE TTYtest::UP_ARROW TTYtest::DOWN_ARROW TTYtest::RIGHT_ARROW TTYtest::LEFT_ARROW TTYtest::HOME_KEY TTYtest::END_KEY TTYtest::CLEAR # clear the screen ``` -------------------------------- ### Troubleshoot terminal output Source: https://github.com/a-eski/ttytest2/blob/main/README.md Methods for inspecting terminal state, including printing rows or the full capture to the console, or accessing them programmatically as arrays or strings. ```ruby @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7) @tty.send_line('echo "Hello, world"')) # If you want to print the current terminal rows as an array of lines, you can use @tty.print_rows. @tty.print_rows # prints out the contents of the terminal as an array: # ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ""] # you can use @tty.rows to access the entire pane, split by line into an array. # if you want to programatically access the rows, you can do so using @tty.rows. p @tty.rows # this is equivalent to above statement @tty.print_rows. # If you want to print the current terminal contents, you can use @tty.print. @tty.print # prints out the contents of the terminal: # $ echo "Hello, world" # Hello, world # $ # you can use @tty.capture to access the entire pane. # if you want to programatically access the entire pane, you can do so using @tty.capture. p "\n#{@tty.capture}" # this is equivalent to above statement @tty.print ``` -------------------------------- ### Configure max_wait_time Source: https://github.com/a-eski/ttytest2/blob/main/README.md Sets the duration in seconds that ttytest2 waits for an assertion to pass before failing. This can be defined during initialization or updated on an existing terminal instance. ```ruby @tty = TTYtest::new_terminal('', max_wait_time: 1) # sets the max wait time to 1 second @tty.assert_row(0, 'echo Hello, world') # this assertion would fail after 1 second @tty.max_wait_time = 3 @tty.assert_row(0, 'echo Hello, world') # this assertion would fail after 3 seconds ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.