terminal is a terminal emulator's screen: the page keeps a string and appends to it, and is handed the bytes the reader types. What those bytes mean is the page's to decide; here, a small shell written in Mote.
A shell
A shell written in the pageEvery key arrives as the bytes a terminal sends; an action edits a line, runs it and appends the answer. ls, cat, write and rm work on the fs battery's files.
80 × 24
0 run
last input: none yet
What it draws
Colours and stylesSGR: the 16 colours (a dark and a light set, chosen by the background), the 256, 24-bit, and the text styles. The page writes the test for the width the screen was fitted to.
Escape sequencesEach button appends a few bytes: cursor moves, erasing, a hyperlink, the alternate screen, the cursor's shape, a full reset.
the bytes last appended
Nothing yet.
Input and size
input: what keys sendThe handler is given the bytes. This one only writes them back, spelled out.
No input yet.
textas typed
Enter\r
BackspaceDEL (127)
Tab / Escape\t / ESC
ArrowsESC [ A B C D
Home / EndESC [ H / ESC [ F
DeleteESC [ 3 ~
Ctrl+letterthe control code: ^C is 3
Alt+keyESC, then the key
pastethe text, newlines as \r
cols, rows, scrollback, cursor, changeWith cols and rows the grid is that size. Without, it is fitted to the element, and change says the new size as COLSxROWS.
cols 36
rows 8
cursor (blinks)
scrollback
Fixed: cols=36 rows=8
Fitted
The string
output: appended, or resetWhen the new value starts with the old one, only the rest is written. Any other value clears the screen and writes it whole. It feeds the two screens above as well.
119 characters. CSI 20 h is written first, so a plain line feed also returns to column one.
ReplayCanned output on a timer: a build whose spinner redraws its own line with a carriage return, then the tests. cursor=false keeps it still.