HeadlessTerminal
ConsoleMonster.Headless
A terminal with no window: the full app, prompt, menu or dashboard runs exactly as it would in a real terminal (the same VT output, alternate screen and cell diffs), while a built-in terminal model keeps the screen. Scripted keys, clicks and resizes go in; the composed screen comes out as cells, for CI, golden tests, recordings, the browser host and the debug socket.
Inheritance
- object
- HeadlessTerminal
Remarks
Pass it wherever a target is accepted (InteractiveOptions.Target, LiveSessionOptions.Target), or make it the ambient target with Terminal.Use. Setting CONSOLEMONSTER_HEADLESS=120x40 makes one the process default, so an unmodified app such as a CLI can be driven through DebugSocket. All members are thread-safe.
Usage
Explore 2 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Accepted by parameters 2
- Method BrowserHost.Start
- Method DebugSocket.Start
Constructors
public HeadlessTerminal(int width = 100, int height = 30, ColorDepth colors = TrueColor, GlyphTier glyphs = Full, CultureInfo? culture = null) #Creates a headless terminal.
Parameters
- width int = 100
- Width in cells (default 100).
- height int = 30
- Height in cells (default 30).
- colors ConsoleMonster.Capabilities.ColorDepth = TrueColor
- The colour depth the app sees (default true colour, so recordings keep every colour).
- glyphs ConsoleMonster.Capabilities.GlyphTier = Full
- The glyph tier (default full Unicode).
- culture System.Globalization.CultureInfo? = null
- The culture for numbers, dates and built-in labels; null for the invariant culture.
Methods
public void CompleteInput() #Ends the input once the queued events are read: the next read reports that input has ended, so an app run by a script finishes instead of waiting for a person. No more input can be sent afterwards.
public void Dispose() #Ends the input (see HeadlessTerminal.CompleteInput). Recordings stay open until their recorder is disposed.
public SessionRecorder Record(SessionRecordingOptions options) #Records everything this terminal shows from now on to an asciicast v2 file (a SessionRecorder in process mode), including log panels, footers, dialogs and prompts. The recording starts with the current screen. Export it with SessionRecording or Export-ConsoleRecording to HTML, SVG, GIF or APNG. Dispose the recorder to finish the file; input is never recorded and secret patterns are redacted as usual.
Parameters
- options ConsoleMonster.Sessions.SessionRecordingOptions
- The file, title and redaction settings; size and in-process mode are set from this terminal.
Exceptions
InvalidOperationException– A recording is already running.
public void Resize(int width, int height) #Resizes the screen now, as dragging a window would, and tells the app with a resize event.
Parameters
- width int
- The new width in cells (2 to 1000).
- height int
- The new height in cells (2 to 1000).
public void Send(string script) #Queues input in ScriptedInput syntax: key names (Down Enter Ctrl+K F2), repeats (Down*3), quoted text ("text"), paste:"text", resize:80x24 and pauses (wait:250, in real time, so recordings keep a reading pace). Steps are read in order; nothing is queued when the script is invalid, and at most 100000 steps wait at a time.
Parameters
- script string
- The script.
Exceptions
FormatException– The script is malformed.
public void Send(InputEvent input) #Queues one input event (a key, a character, a paste, or a mouse press or release from InputEvent.Mouse).
Parameters
- input ConsoleMonster.Input.InputEvent
- The event. Resize with HeadlessTerminal.Resize, which also changes the screen.
public CellBuffer Snapshot() #A copy of the visible screen as the user would see it: the app's alternate screen while it runs.
public bool TryGetWindow(out int left, out int top, out int width, out int height) #The visible window in cells: its position in the buffer and its size.
Parameters
- left int
- The leftmost visible column of the buffer (zero when the driver has no scrollable buffer).
- top int
- The topmost visible row of the buffer (zero when the driver has no scrollable buffer).
- width int
- The window width in cells.
- height int
- The window height in cells.
Returns
bool False when the size is unknown (for example, output is redirected); callers then use the profile's size.public void WaitForText(string text, TimeSpan timeout, CancellationToken cancellationToken = default) #Waits until the visible screen contains the text (ordinal, case-sensitive).
Parameters
- text string
- The text.
- timeout System.TimeSpan
- The longest wait.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the wait.
Exceptions
TimeoutException– The text did not appear in time.
Inherited Methods
Properties
public string Name { get; } #A short description for diagnostics, for example console or recording 80x24.
public TerminalProfile Profile { get; } #The profile at the current size: VT output, the chosen colour depth, glyph tier and culture, and hyperlinks.
public ITheme? Theme { get; set; } #The theme (default the dark theme, so the screen does not depend on the machine).
public ITerminalWriter? Writer { get; } #The writer that receives the output, or null for the process console. The target owns it: callers write and flush but never dispose it.
public IInputSource? Input { get; } #The input for prompts, menus and forms, or null. On the console null means the keyboard; on any other target it means nobody can answer, so prompts use their defaults or explain what is missing.
public long FrameCount { get; } #How many distinct screens have been drawn so far.
Events
public event Action<CellBuffer>? FrameRendered #Raised after each completed screen that differs from the previous one, with a copy of it. It is raised on the thread that drew the screen (often a render thread): keep handlers short and never draw from them.