TuiTester class final
Runs a Model in a real Program, headless, for tests.
Each program gets a fixed width x height (also its first
WindowSizeMsg), an empty environment, plain mode off, no renderer, no
stdin and no signal handlers. Style.defaultProfile is pinned to
profile and Style.hasDarkBackground starts as darkBackground
(a COLORFGBG in environment or a sent BackgroundColorMsg changes it,
as in a terminal); both are restored when the run ends. Requests that need a terminal reply (such as
RequestBackgroundColorMsg) get fixed answers. options are applied
last, for example withTickInterval.
Every view is recorded after each update, so screen is current as soon as a call such as press completes. Commands still run asynchronously: use waitFor for their results.
Style defaults are process-wide, so run one tester at a time, and call
dispose in a tear-down (for example addTearDown(t.dispose)).
There is no fake clock: timers and ticks run in real time. Test a spinner
or timer with a short withTickInterval and waitFor.
Constructors
-
TuiTester(Model model, {int width = 80, int height = 24, ColorProfile profile = ColorProfile.noColor, bool darkBackground = true, Map<
String, String> environment = const {}, List<ProgramOption> options = const []}) -
Runs
modelin a new Program. -
TuiTester.run(Future<
Object?> body(), {int width = 80, int height = 24, ColorProfile profile = ColorProfile.noColor, bool darkBackground = true, Map<String, String> environment = const {}, List<ProgramOption> options = const []}) -
Runs
body, and drives each Program it creates and starts, one after another. Programs created outsidebodydo not use this tester.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- height ↔ int
-
The window size programs start with (see resize).
getter/setter pair
- isRunning → bool
-
Whether the run (the model, or the body of TuiTester.run) is still
going.
no setter
- model → Model?
-
The current model (after the last update); null before any program.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- screen → String
-
The current view as text: escape codes removed, trailing spaces trimmed
on every line. This is the view's text, not a terminal emulation: it is
not cut to width or height.
no setter
- styledScreen → String
-
The current view's content with its escape codes.
no setter
- width ↔ int
-
The window size programs start with (see resize).
getter/setter pair
Methods
-
dispose(
) → Future< void> - Stops the running program, waits up to 2 s, and restores the Style defaults. Safe to call more than once; never throws.
-
done(
{Duration timeout = const Duration(seconds: 2)}) → Future< TuiResult> -
Waits for the run to end on its own (for example an OutcomeModel with
an outcome), and returns the result. Throws TuiTestFailure when
timeoutpasses first; rethrows an error the run ended with. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paste(
String text) → Future< void> -
Pastes
textas a bracketed paste: PasteStartMsg, PasteMsg and PasteEndMsg, as a terminal sends it. -
press(
String key) → Future< void> -
Presses one key, given as its keystroke name, for example
enter,ctrl+c,shift+tab,alt+left,pgdown,f5,spaceora. -
quit(
{Duration timeout = const Duration(seconds: 2)}) → Future< TuiResult> - Sends QuitMsg to the running program, then waits as done does.
-
resize(
int width, int height) → Future< void> - Sends a WindowSizeMsg for the new size. Later programs start with it.
-
send(
Msg msg) → Future< void> -
Sends
msgand completes once the program has handled it. Throws StateError after dispose. -
toString(
) → String -
A string representation of this object.
inherited
-
type(
String text) → Future< void> -
Types
text, one KeyPressMsg per Unicode scalar value, as a terminal sends it (a space arrives asspace, a newline asenter). -
waitFor(
bool test(String screen), {Duration timeout = const Duration(seconds: 2)}) → Future< String> -
Waits until
testis true for screen, and returns that screen.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited