FakeCliTerminal class final

A CliTerminal that captures what is written and replays what is typed, in one of the three modes or with every capability given.

  • FakeCliTerminal() is CliMode.nonInteractive: a pipe, nobody to answer.
  • FakeCliTerminal.plain is CliMode.plain: a terminal without ANSI, whose readLine answers its lines in turn.
  • FakeCliTerminal.interactive is CliMode.interactive: a terminal width × height cells, whose inline session runs on a terminal in memory (backend) that gets its input, keys as a terminal sends them ('\x1B[B' the down arrow, '\r' Enter, '\x03' Ctrl+C), and whose screen is an emulator fed everything written to it, the session's frames and the lines written around it.

out and err keep what was written as lines, outside a session; interrupts counts the Ctrl+C the console passed on. clock is where the session's time comes from: a FakeClock given here moves only as the test moves it, the wall clock without one.

test('writes the result to the output', () {
  final terminal = FakeCliTerminal();
  Cli(terminal: terminal).info('done');
  expect(terminal.out.toString(), 'done\n');
});

Constructors

FakeCliTerminal({bool ansi = false, bool interactiveInput = false, bool outputIsTerminal = false, bool? errorIsTerminal, bool? hyperlinks, ColorMode colorMode = ColorMode.trueColor, bool styledUnderlines = true, bool? probedStyledUnderlines, int? columns, int width = 80, int height = 24, List<String> lines = const [], List<String> input = const [], FakeClock? fakeClock, bool progressReports = false})
A terminal of the capabilities given, all off by default: nobody answers, the output is a pipe. lines answer readLine, input is typed into the inline session, columns is its width (null for none where output is no terminal), width × height the screen's size where it is one; fakeClock times the session. progressReports says the terminal shows a program's progress in its tab (OSC 9;4), which the inline session then writes; styledUnderlines false that it shows no underline styles, as Terminal.app, and probedStyledUnderlines what the inline session's probe finds of them, styledUnderlines by default: false beside a true one is Terminal.app over ssh, which its environment doesn't tell.
FakeCliTerminal.interactive({List<String> input = const [], int width = 80, int height = 24, FakeClock? fakeClock, bool progressReports = false})
Somebody answers at a terminal that redraws, width × height cells: the inline session gets input as typed. fakeClock times it, the wall clock without one; progressReports as above.
FakeCliTerminal.plain({List<String> lines = const [], int width = 80, int height = 24, FakeClock? fakeClock})
Somebody answers at a terminal that takes no ANSI (NO_COLOR, a dumb terminal): readLine answers lines in turn, then null. fakeClock is where the time of a progress comes from.

Properties

backend → HeadlessTerminal?
The terminal in memory the inline session runs on, once it is opened.
no setter
capabilities → CliCapabilities
What this terminal can do.
final
clock → CliClock
Where the time of the session and its timers comes from.
final
closed → bool
Whether it was closed (close); readLine answers null since.
no setter
colorMode → ColorMode
The colors styled output is written in.
final
columns → int?
Width in columns; null when output is not a terminal and nothing says how wide it is.
no setter
err → StringSink
The error output: its toString is everything written to it, outside an inline session.
latefinal
exitCode ↔ int
The code the process ends with: on the process's terminal, exitCode of dart:io, which Cli.run sets when its body fails. Elsewhere it is kept here, 0 until it is set, so that a test reads it without ending its own process with it.
getter/setter pairinherited
hashCode → int
The hash code for this object.
no setterinherited
height → int
The screen's height in cells.
final
interrupts → int
How many times the console passed a Ctrl+C on (interrupt).
no setter
mode → CliMode
How it may be talked to (CliCapabilities.mode).
no setterinherited
opened → int
How many times the inline terminal was opened: one at a time, again once the last one is closed (a session ended by a Ctrl+C, then another), as the process's own terminal is.
no setter
out → StringSink
The output: its toString is everything written to it, outside an inline session.
latefinal
progressReports → bool
Whether the terminal shows a program's progress in its tab or taskbar (OSC 9;4): the inline session's TerminalProgress writes it to backend's frames only then.
final
reads → int
How many times readLine was called: a line read, or the end of input.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
screen → Vt
The screen, an emulator fed what reaches the terminal: the lines written to out (and to err where it is the terminal) and the frames of the inline session, in the order they came. Read screenLines, which is up to date, rather than this directly.
final
screenLines → List<String>
The lines of the screen, the scrollback first, without the blanks that end them, the blank lines at the bottom left out.
no setter
width → int
The screen's width in cells.
final

Methods

close() → Future<void>
Lets go of what it holds: on the process's terminal, stdin, once a readLine listened to it, so that the process can end. Nothing is read after it. Cli.close calls it; nothing by default.
flush() → Future<void>
Flushes out and err where they buffer.
interrupt() → void
What a Ctrl+C nothing live took does once the inline session has ended and handed the terminal back: on the process's terminal it sends the process SIGINT, so it ends as it would at a cooked terminal, unless the program watches the signal.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openInline() → Future<TerminalBackend>
Opens the terminal an inline twk app runs on, in the interactive mode: raw input, the normal screen. Called when the Cli's inline session starts, and again for a new one once a Ctrl+C ended the last (its terminal closed by then); the app closes it when the session ends.
readLine({bool hidden = false}) → Future<String?>
Reads one line as the terminal reads it, without its line break; null at the end of input. hidden switches echo off while it reads, where input is a terminal.
toString() → String
A string representation of this object.
inherited
type(String keys) → void
Types keys into the inline session, as a terminal sends them; kept for it until it opens.

Operators

operator ==(Object other) → bool
The equality operator.
inherited