Terminal

A terminal that runs the commands added to it. It comes with `help` and `clear`; every other command is added by the page. The `run` function of a command returns the component to show as its output. The terminal places that component among its own children, so the styles of the page reach it, and removes it when the screen is cleared. The terminal has a fixed height of 80 logical pixels and scrolls its lines. Set `height` in CSS to change it. Inside a `pix-window` it grows to fill a maximized window. Enter runs what was typed, the up and down arrows walk through the commands already typed, Tab completes the name of a command and Control + L clears the screen.

Import

Importing the library registers <pix-terminal>.

import '@halleyfante/pix';

Basic

Inside an application

Attributes

NameTypeDefaultDescription
promptstring'$'Text shown before each command.

Properties

NameTypeDescription
commandsTerminalCommand[]The commands this terminal can run, in alphabetical order.
historystring[]The commands typed so far, oldest first.

Methods

MethodDescription
PixTerminal.addCommand(command: TerminalCommand): voidAdds a command to every terminal on the page, including the ones created later.
addCommand(command: TerminalCommand): voidAdds a command to this terminal only. It replaces a command of the same name added to every terminal.
run(text: string): Promise<void>Runs a command as if it had been typed. Resolves when the command finishes.
write(output: TerminalOutput): voidShows an element, usually a component, as a new line on the screen.
clear(): voidRemoves every line from the screen. The typed commands are kept.

Events

NameDescription
commandA command was run. `event.detail.text` holds what was typed.