TestTerminal

class TestTerminal(width: Int = 80, height: Int = 24) : Terminal(source)

A mock implementation of Terminal for use in unit and integration tests.

It allows simulating user input, tracking terminal state changes (like cursor movement or raw mode transitions), and capturing raw ANSI output.

Parameters

width

The initial width of the terminal.

height

The initial height of the terminal.

Constructors

Link copied to clipboard
constructor(width: Int = 80, height: Int = 24)

Properties

Link copied to clipboard
var cursorX: Int

The current horizontal position of the cursor (0-indexed).

Link copied to clipboard
var cursorY: Int

The current vertical position of the cursor (0-indexed).

Link copied to clipboard
var isCursorHidden: Boolean

Whether the terminal cursor is currently hidden.

Link copied to clipboard
var isRawMode: Boolean

Whether the terminal is currently in raw mode.

Link copied to clipboard
var windowTitle: String

The current window title.

Functions

Link copied to clipboard
open override fun clear()
Link copied to clipboard
open override fun clearLine()
Link copied to clipboard
open override fun enterRawMode()
Link copied to clipboard
open override fun exitRawMode()
Link copied to clipboard
open override fun flush()
Link copied to clipboard
open override fun hideCursor()
Link copied to clipboard
open override fun moveCursor(x: Int, y: Int)
Link copied to clipboard
fun output(): String

Returns the raw ANSI output captured since the last clear.

Link copied to clipboard
open override fun poll(timeoutMs: Int): Boolean

In a test environment, poll returns true immediately if there are pending events.

Link copied to clipboard
open override fun read(): Event?
Link copied to clipboard
fun resize(width: Int, height: Int)

Simulates a terminal resize event.

Link copied to clipboard
fun sendChar(c: Char)

Simulates the user typing a single character.

Link copied to clipboard
fun sendKey(key: Key, modifiers: Set<KeyModifier> = emptySet())

Simulates the user pressing a specific key.

Link copied to clipboard
open override fun setTitle(title: String)
Link copied to clipboard
open override fun showCursor()
Link copied to clipboard
open override fun size(): Size
Link copied to clipboard
open override fun write(text: String)