Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

terminal-window

A web component that simulates a terminal: readers type commands, and you decide in JavaScript what each command prints. It reads Vanilla Breeze surface, text, border and radius tokens directly, and the VB stylesheet maps the prompt, cursor and status colors as well.

At a glance

Package@profpowell/terminal-window, version 2.1.0
Elements<terminal-window>
Renders inShadow DOM
Sourcegithub.com/ProfPowell/terminal-window
Documentationprofpowell.github.io/terminal-window
LicenceMIT
In Vanilla BreezeNot bundled. Load it yourself. The VB stylesheet includes the rules that theme it.

Install

Load the component from a CDN. It is one file with no dependencies and no stylesheet.

Or install it from npm and import it in your own script.

Demo

A terminal on a Vanilla Breeze page with two custom commands and the built-in file commands. Click in it and type help, status or ls.

Usage

Add the element and give it a height. It fills the height of its container. The built-in commands are help, clear, echo and history.

Register your own commands in JavaScript. A handler receives the words typed after the command name as an array, and the terminal itself. The string it returns is printed. A handler can be async.

For a scripted demonstration, make the terminal read-only and run commands from code. Note that typing-effect must be written with the value true.

Reference

Attributes

"Boolean" means the attribute is on when present. Where the table says false to turn off, the feature is on unless the attribute is set to false.

AttributeValuesDefaultPurpose
modedark, lightFollows the page, then the operating system, then lightFixes the color scheme.
themedark, lightNoneOlder name for mode. Used when mode is not set.
titleTextTerminalTitle in the header.
promptText$ Text shown before the input.
welcomeTextNoneMessage printed when the terminal loads.
autofocusBooleanOffFocuses the input when the terminal loads.
readonlyBooleanOffTurns off typed input. Commands can still be run from code.
cursor-styleblock, underline, barblockCursor shape.
cursor-blinkfalse to turn offOnBlinks the cursor.
typing-effecttrue to turn onOffPrints output one character at a time. The bare attribute does not turn it on.
typing-speedMilliseconds per character30Speed of the typing effect.
force-animationsBooleanOffKeeps the typing effect and cursor blink even when the reader has asked for reduced motion. Meant for testing.
font-familyCSS font list'Consolas', 'Monaco', 'Courier New', monospaceFont of the terminal text.
font-sizeCSS length14pxSize of the terminal text.
line-heightNumber1.4Line height of the terminal text.
max-linesNumber1000Most output lines kept.
show-headerfalse to hideShownThe header bar.
show-controlsfalse to hideShownThe close, minimize and fullscreen buttons.
show-copyfalse to hideShownThe copy button and its menu.
show-theme-togglefalse to hideShownThe light and dark toggle button.
enable-vfsBooleanOffAdds a virtual file system, held in memory, with the commands ls, cd, pwd, mkdir, touch, rm and cat.
persist-historyBooleanOffSaves the command history in the reader's browser.

Methods and properties

MethodPurpose
registerCommand(name, handler)Adds a command. handler(args, terminal) returns the text to print, or a promise of it.
unregisterCommand(name)Removes a command.
registerAlias(alias, command)Makes alias run another command string.
executeCommand(input, addToHistory)Runs a command line as if it were typed. Returns a promise.
executeSequence(commands, delay)Runs several command lines in turn, waiting delay milliseconds after each. The default is 1000.
print(text, type)Prints text. type is 'output' (the default), 'error', 'info' or 'success'. ANSI escape codes in the text set colors and bold, italic and underline.
updateLastLine(text)Replaces the last printed line. Use it for progress output.
clear()Clears the output.
toggleMode(), setTheme(theme)Switches between light and dark, or sets one.
setPrompt(text), setCursorStyle(style), setCursorBlink(on), setReadonly(on)Change the matching setting.
setTypingEffect(on, speed), skipTypingEffect(), setForceAnimations(on)Control the typing effect.
setInputMask(on)Shows asterisks in place of typed characters, for password prompts.
getHistory(), setHistory(list), clearHistory()Read, replace and clear the command history.
getContent(), copyContent(mode)Returns the terminal text, or copies it. mode is 'all', 'commands', 'output' or 'selection'.
focus(), scrollToBottom()Focus the input, or scroll to the newest line.
close(), minimize(), toggleFullscreen()The actions of the three window buttons. close() hides the element.
setI18n(strings)Replaces button labels and messages, for translation.

The element has three slots: title, actions (extra header buttons) and before-output.

Events

EventFired whenDetail
commandA command is run{ command, args, input }
command-resultA command finishes{ command, args, result }
command-errorA command fails or is not found{ command, error }
outputA line is printed{ type, content }
copyContent is copied{ text, mode }
interruptThe reader presses Ctrl+CNone
closeThe terminal is closedNone
minimizeThe terminal is minimized or restored{ minimized }
fullscreenFullscreen is turned on or off{ fullscreen }

CSS custom properties

There are 43 properties, all starting with --terminal-window-. The table lists the suffix. Set them on the element or on any ancestor.

GroupProperties
Windowbg, header-bg, secondary-bg, border-color, border-radius, inner-radius, text-color, text-muted, text-secondary, font-family
Terminal textprompt-color, cursor-color, command-color, output-color, error-color, info-color, success-color, selection-bg
Buttonsbtn-bg, btn-hover-bg, btn-text
Window controlscontrol-close, control-minimize, control-maximize
Scrollbarscrollbar-track, scrollbar-thumb, scrollbar-thumb-hover
ANSI colorsansi-black, ansi-red, ansi-green, ansi-yellow, ansi-blue, ansi-magenta, ansi-cyan, ansi-white, and a ansi-bright- form of each

The inner elements are also exposed as CSS parts for ::part(), including terminal, header, controls, title, body, output, input-line, prompt and cursor. See the terminal-window documentation for the full detail.

With Vanilla Breeze

A token is a CSS custom property that holds one design value, such as --color-surface. Two things connect the component to Vanilla Breeze tokens.

First, the component itself reads these VB tokens as fallbacks.

VB tokenDrives
--color-surfaceTerminal background
--color-surface-raisedHeader and secondary backgrounds
--color-borderBorders
--color-textMain text
--color-text-mutedMuted text
--radius-mOuter corner radius
--radius-sRadius of buttons and menus

Second, the VB stylesheet contains a token bridge: a rule with the selector terminal-window that sets the component's --terminal-window-* properties from VB tokens. It ships in vanilla-breeze.css and vanilla-breeze-core.css, so there is no extra file to load and no attribute to add. Besides the tokens above, the bridge sets these.

VB tokenSet on
--color-successPrompt, success messages and the fullscreen button
--color-errorError messages and the close button
--color-warningThe minimize button
--color-infoInfo messages
--color-interactiveCursor and text selection
--color-text, --color-text-mutedTyped commands, and printed output

For each value the order is: the --terminal-window-* property if it is set, then the VB token where the component reads one, then the built-in color for the current mode. The bridge does not set the ANSI colors, the header button colors or the scrollbar colors, so those keep the component's built-in values.

The font is an exception. The component and the bridge both point --terminal-window-font-family at --font-mono, but in version 2.1.0 the element also applies its font-family attribute, default included, directly to the terminal, and that wins. To use the VB monospace font, set the attribute.

Light or dark is chosen separately. With no mode or theme attribute, the component follows data-mode, data-theme or a dark class on <html> or <body>, then the page's computed color-scheme, then the operating system preference. It updates when these change.

The bridge sits in a cascade layer, so any rule you write outside a layer wins. To change one terminal, set the property on it.

Accessibility

↑