MockTerminal class cli
A pretend terminal for tests: scripted keys in, captured output out.
Queue up what the "user" types with type, press and line, then run prompts inside run. Everything they draw lands in output, and screen replays it to show what the user would see at the end.
final terminal = MockTerminal()
..press(Key.down)
..press(Key.enter);
final colour = terminal.run(() => Prompts.menu('Colour', ['Red', 'Blue']));
expect(colour, 'Blue');
expect(terminal.screen.last, contains('Blue'));
Constructors
- MockTerminal({int columns = 80, int rows = 24, bool interactive = true})
-
Creates a terminal
columnswide androwstall.
Properties
- columns ↔ int
-
How many columns wide the screen is.
getter/setter pairoverride-getter
- echoMode ↔ bool
-
Whether typed keys are shown on screen by the terminal itself.
getter/setter pairoverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasInput ↔ bool
-
Whether keys come from a person at a keyboard (not a pipe or file).
getter/setter pairoverride-getter
- hasOutput ↔ bool
-
Whether output goes to a screen (not a pipe or file).
getter/setter pairoverride-getter
- interactive → bool
-
Whether this acts like a real keyboard and screen.
no setter
- lineMode ↔ bool
-
Whether input arrives a whole line at a time, after Enter.
getter/setter pairoverride
- output → String
-
Everything written so far, escape codes and all.
no setter
- rows ↔ int
-
How many rows tall the screen is.
getter/setter pairoverride-getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
screen
→ List<
String> -
The screen as the user would see it now, one string per row.
no setter
- supportsAnsi ↔ bool
-
Whether the screen understands escape codes for moving the cursor.
getter/setter pairoverride-getter
Methods
-
bytes(
List< int> bytes) → void - Queues raw input bytes, for escape sequences press doesn't cover.
-
clearOutput(
) → void - Forgets the captured output.
-
ctrl(
String letter) → void -
Queues Ctrl and
letter, likectrl('d'). -
line(
String text) → void - Queues a whole typed line, for prompts in PromptMode.line.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
press(
Key key, {int times = 1}) → void - Queues a special key, like Key.down or Key.enter.
-
readByte(
) → int -
Reads one byte of input, waiting for it. Gives back -1 at the end.
override
-
readLine(
) → String? -
Reads one line of input, waiting for Enter. Gives back null at the end.
override
-
run<
T> (T body()) → T -
Runs
bodywith this as Terminal.current and the prompt mode worked out from it. -
toString(
) → String -
A string representation of this object.
inherited
-
type(
String text) → void -
Queues
textas typed characters. -
write(
String text) → void -
Writes
textto the screen as it is.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited