Machine state, sequences and sessions
Terminal <smart-terminal>
Terminal displays a stream of lines, such as an instrument session or an event log, at a high rate.
<smart-terminal> · 9 properties, 6 methods, 2 events · source/modules/smart.terminal.js
Usage in Blazor
The Razor component is <Terminal> in Smart.Blazor.Industrial: every property is a parameter in PascalCase, every event an EventCallback<Event> named On<Event> whose ev["Detail"] is the typed detail class, and the methods are called on the @ref. String choices are enums. In a Blazor Web App (.NET 8 and later) the page needs an interactive render mode, for example @rendermode InteractiveServer; a statically rendered component stays empty.
@using Smart.Blazor.Industrial
@* .NET 8 and later: an interactive render mode, on the page or for the whole app *@
@rendermode InteractiveServer
<Terminal @ref="terminal" Filter="/^ERR/" Interactive="true"
OnCommand="OnCommand" />
@code {
Terminal terminal;
void OnCommand(Event ev)
{
TerminalCommandEventDetail detail = ev["Detail"];
}
// Task<bool> Write(string text)
void Call() => terminal.Write("value");
}
Properties
| Parameter | Type, default | Description |
|---|---|---|
Announce | bool | Sets or retrieves whether new lines are announced to assistive technology. Off by default and rate-limited when on. Errors are announced immediately; other lines are announced at most once every few seconds. |
AnsiColors | bool | Sets or retrieves whether ANSI SGR escape codes are rendered as colours. The eight basic foreground colours, bold and reset are supported, which is what bench instruments and serial devices emit. When disabled, the colour codes are removed. Other escape sequences - erase line, cursor moves and visibility, window titles - and control characters such as NUL and BEL are always removed, and a carriage return goes back to the start of the line, so a progress line written over itself reads as its last state. |
AutoScroll | bool | Sets or retrieves whether the view follows the newest line. The view follows only while it is already scrolled to the bottom. Boolean attributes are presence-based, so set the property from script to turn it off. |
Filter | string | Sets or retrieves a filter, either as plain text matched case-insensitively or as a /regex/. The filter affects the view only: a filtered-out line stays in the buffer, so clearing the filter restores the history. An incomplete regular expression falls back to a substring match while it is being typed. Lines that leave the buffer leave the view by which lines they are, so a filtered view keeps every matching line still in the buffer. |
Interactive | bool | Sets or retrieves whether a command line is shown. Pressing Enter echoes the command as a transcript line and raises the command event. The application appends the response, because the component does not know what is connected. |
MaxLines | int | Sets or retrieves how many lines the ring buffer holds. Lowering it trims the oldest immediately. Never goes below one. |
Paused | bool | Sets or retrieves whether the terminal is frozen. A paused terminal keeps what it holds and drops anything appended, and write returns false so the application knows the line was not taken. While paused the command line sends nothing: the line stays in the box, the box says why, and Enter sends it once the terminal is resumed. |
Prompt | string | Sets or retrieves the prompt of the command line, which is also used as the prefix when a command is echoed. |
TimestampFormat | TerminalTimestampFormat | Sets or retrieves how each line is stamped. |
Methods
| Method | Description |
|---|---|
Task<bool> Write(string text) | Appends one line. Returns false when the terminal is paused and the line was dropped. The text is escaped, so device output cannot inject markup.text string The line.level string info, warn, error, success, command or response. Drives the colour. Defaults to info. |
Task<bool> WriteMany(IEnumerable<object> lines) | Appends several lines with one scroll and one announcement. Accepts strings or { text, level } objects.lines string[] | object[] The lines, oldest first.level string Applied to any entry given as a bare string. |
void Clear() | Empties the buffer and the view. |
void ScrollToEnd() | Scrolls to the newest line and resumes following new lines. Intended for a "jump to end" control. |
Task<object[]> Snapshot() | Returns the lines in the buffer, oldest first, as a copy that is not changed by later writes. |
Task<string> ToText() | Returns the buffer as plain text, oldest first, including the timestamps when they are enabled, for export, a report or the clipboard.filtered boolean Only the lines the filter currently admits. |
Events
Every event is an EventCallback<Event>; Event is a dictionary and ev["Detail"] converts to the detail class named under the event.
| Event | Description and detail |
|---|---|
OnCommand | This event is triggered when a command is entered on the command line. The component echoes the command; the application appends the response. It is not raised while the terminal is disabled or paused, nor by the Enter that ends an IME composition. Up and Down on the command line bring back the last 50 commands sent.Command string What was typed, without the prompt. |
OnLineAppended | This event is triggered when a line is appended.Line object The line: { id, text, level, at }.Length int How many lines the buffer now holds. |
Types
enum TerminalTimestampFormat
TerminalTimestampFormat.None TerminalTimestampFormat.Time TerminalTimestampFormat.Datetime TerminalTimestampFormat.Elapsed
CSS variables
The component declares 4 CSS variables; the CSS page shows how to set them.
--smart-terminal-height --smart-terminal-background --smart-terminal-color --smart-terminal-font