[ DOCS ] /docs/console
Console
Opening it#
- Press ` (backtick) anywhere that is not a text field. Press it again to close.
- Press ⌘/Ctrl + K and choose Open console.
- Click Console in the top bar (it shows as
>_on narrow screens).
The console has a Docs ↗ link in its header that comes back here. The page behind it stays interactive, so you can try a script and the effect at the same time.
Docked panel and sheet#
On a window at least 1024 px wide the console docks on the right edge and the page reflows into the space beside it. Layouts on this site respond to the width of the page, not the window, so the page rearranges itself instead of being covered.
- Resize by dragging the thin bar on the console's left edge, or focus it and press ←/→ (20 px a step, 80 with Shift). The console is never narrower than 360 px and always leaves 480 px for the page.
- The width is remembered, and a docked console that was open stays open on your next visit.
- Docked, Esc closes it only when focus is inside it, and Tab is not trapped, because the page is still in use.
On narrower windows it is a sheet over the bottom of the screen, up to 70% of the window high. It behaves as a dialog: Esc closes it, Tab stays inside, and focus returns to where it was when it closes.
The editor#
The editor highlights Eitri with the language's tree-sitter grammar, which is fetched the first time the console opens, so colours appear a moment after the text. It has a line gutter and does not wrap lines.
| Keys | What it does |
|---|---|
| ⌘/Ctrl + Enter | Run the script. |
| Tab | Insert four spaces at the cursor (it replaces a selection). |
| Ctrl + M | Toggle whether Tab moves focus out of the editor, for keyboard users. A toast says which mode is on. |
Typing changes nothing on the page until you run the script.
Output, Tokens, AST, Bytecode, Docs#
Output#
The outcome of the last run and how long it took to compile and run, then everything the script printed with site.print and every toast it showed (marked toast). The outcome is one of:
- OK: the script ran and the page was updated.
- Compile error: the script was rejected before it ran. The report shows the line with a caret under the problem.
- Runtime fault: the script ran and stopped, for example on an integer overflow, an index out of bounds or because it used up its step budget.
- Host error: the runtime itself could not be started.
A run that is not OK does not change the page, so a half-typed script never flickers the look. Faults inside later callbacks (a timer, an event handler) are added to the output as error lines and shown once as a toast.
import site from "site"
let count = site.projects.len()
site.print(count)
error[E0301]: type mismatch: expected `string`, found `i64`
╭─ script.eit:4:12
│
4 │ site.print(count)
│ ^^^^^import site from "site"
var n: i64 = 9223372036854775807
n = n + 1
site.print("${n}")
fault: integer overflow
╭─ script.eit:4:5
│
4 │ n = n + 1
│ ^^^^^ in `<module>`Tokens, AST and Bytecode#
Three views of the script in the editor that follow your typing (about 200 ms after you stop) while their tab is open. You do not need to run anything. They are useful for learning what the compiler makes of a line. The same three-line script as above gives:
import site from "site"
let n = 2 + 3
site.print("n is ${n}")
0..6 Import import
7..11 Ident site
12..16 Ident from
17..23 Str "site"
23..24 Newline \n
24..27 Let let
28..29 Ident n
30..31 Eq =
32..33 Int 2
34..35 Plus +ModuleDecl <line:1:1, line:3:24>
├─ImportDecl <line:1:1, col:23> col:8 site "site"
├─VarDecl <line:2:1, col:13> col:5 n 'i64' let
│ └─BinaryOperator <col:9, col:13> 'i64' '+'
│ ├─IntegerLiteral <col:9> 'i64' 2
│ └─IntegerLiteral <col:13> 'i64' 3
└─CallExpr <line:3:1, col:23> 'void'
├─MemberExpr <col:1, col:10> 'void (string)' .print
│ └─DeclRefExpr <col:1, col:4> Module 'site'
└─Interpolation <col:12, col:22> 'string'
├─StringLiteral <col:13, col:17> 'string' n is
└─DeclRefExpr <col:20> 'i64' Var 'n'; script.eit
declare void @site.print(string)
define void @<module>() frame(3) {
literal h6e20697320
literal h4c30303030303030356e2069732069
bb0:
%r1 = ldi i64 2 ; 0000 00020103 @32..33
%r0 = addi.chk.s %r1, 3 ; 0001 03010025 @32..37
%r2 = mov %r0 ; 0002 00000200 @57..58
%r1 = str.interpolate %r2, 1 ; 0003 010201cd @49..60
call.host void @site.print(string %r1) ; 0004 0000009f site0 @38..61
ret ; 0005 000000a1 @0..0
}Docs#
The SDK declaration files with a button per module and the import line to use, highlighted. They are the same files the SDK reference is generated from.
Examples#
The Examples… menu next to Run replaces the editor text with a ready-made script. It does not run it; look at it, change it, then press Run. Each one is run against the real runtime by the site's checks.
| Group | Examples |
|---|---|
| Look | Terminal mode, Night shift |
| Content | Newest first, Rust spotlight, Welcome back |
| Actions & prompts | Theme picker, Ask my name, Panic button |
| Keys | Vim navigation |
| Events | Konami code, Hover sparks, Screensaver, Click counter, Scroll spy, Tab watcher |
| Timers | Live clock readout, Countdown |
import site from "site"
import fx from "site/fx"
import sound from "site/sound"
// Sparks fly off a project card when the pointer touches it, with a tiny
// blip. The event carries the card's slug; it is null for other events.
site.on("project.hover", e => {
if let slug = e.slug {
fx.sparks(slug)
sound.beep(880, 40)
}
})
Reset clears the saved script, drops everything the script registered, restores the default page and puts the starter script back in the editor. It also removes #eitri= from the address bar.
Share links#
Share copies the current page address with the script appended as #eitri=<base64url>: the script as UTF-8, base64url encoded, not compressed. Whoever opens the link gets the script in their editor with the console open and a "Shared script" notice. It does not run until they press Run, and it is not saved for them until then.
The part after # is never sent to a server. A long script makes a long link. Because a script runs when you press Run, read it first and treat links like any other code: they run inside the same sandbox and limits as anything you type, and they can only do what the SDK allows.
Saved scripts#
When Run finishes with OK, the script is saved in local storage. A script that does not compile or faults is not saved. On your next visit it runs again just after the page loads, as a silent replay:
- Look and content changes, actions, handlers, key bindings, modes and timers all come back.
- Toasts, sounds, one-shot effects (
site/fx), prompts,site.gotoandsite.opendo not happen, so the page does not jump or make noise on arrival. site.visitscounts the page loads that replayed a saved script, this one included.
import site from "site"
import fx from "site/fx"
import ui from "site/ui"
// site.visits counts the page loads that replayed a saved script, this one
// included, so the first visit and the later ones can be told apart.
if site.visits <= 1 {
fx.typeout("hello, first time here?")
} else {
fx.typeout("welcome back, visit #${site.visits}")
ui.toast("good to see you again", .Info)
}
A #eitri= link in the address wins over the saved script: the saved script does not replay, and the shared one only loads into the editor. Local storage can be unavailable (some private modes); the console then works but nothing is remembered.
Safe mode and reset#
A saved script can misbehave: a prompt that keeps coming back, flashing, keys it should not own. Three ways out:
- Open the site with
?safe(for examplehttps://junaadh.com/?safe). The saved script is cleared, nothing runs and the parameter is removed from the address. - Press Esc twice in a row while a script is saved or running. It restores the default page and clears the saved script, even while a prompt is open.
- A prompt opened by a script has a Reset site button in its title bar.
To keep a script from taking the page over, a prompt or the palette that a timer or event opens (rather than a key, the palette or Run) is refused while one is already open and for 5 seconds after the last one. Flashes and look flips (theme.invert, theme.flicker, fx.flash) are limited to 2 per second in total and are ignored under prefers-reduced-motion. Every ctrl, alt and meta chord, enter, space, tab, escape, f1 to f12 and the backtick are reserved and cannot be bound.
What a run is#
Each press of Run starts from a clean slate:
- The look and the content (title, project order, hidden, highlighted and badged projects, readouts, banner) return to their defaults, and the previous program is dropped: its actions, event handlers, key bindings, modes and timers are gone.
- The script runs from the top, in a new context. Its variables start fresh.
- Calls into the page are recorded while it runs and applied together when it finishes without a fault.
The script's last line is not the end of it. Actions, handlers, key bindings and timers it registered stay alive, with the variables they close over, until the next run, a call to site.stop(), or Reset. Each callback runs with a fresh step budget and the clock of the moment it is called.
Limits#
Scripts are untrusted code, so everything is capped. Exceeding a runtime limit is a fault; the page-side caps quietly drop or clamp the extra. The first four come from the Eitri build in use (crates/eitri-wasm), the rest from the site's runtime (lib/eitri/model.ts).
| Limit | Value |
|---|---|
| Step budget | 2,000,000 steps per run and per callback. Each call and each backward jump costs one. |
| Memory | 32 MiB for the whole program, including the compiled code. |
| Script size | 64 KiB of source. |
| Recorded calls | 10,000 per run or callback; the site applies at most 400 of them. |
| Live callbacks | 256 (actions, handlers, timers and open prompts together). |
| Actions | 64 |
| Key bindings | 128 |
| Timers | 20 at once. after waits at least 100 ms, every at least 250 ms, and neither more than 24 hours. |
| Handlers | 16 per event. |
| One-shot effects | 24 per run or callback (toasts, effects, sounds, navigation). |
| Readout rows, badges | 8 rows; 3 badges per project card. |
| Console output | The last 500 lines. |
Timers that repeat pause while the tab is hidden. Pointer-hover events are limited to ten a second per project and other events to twenty a second. Text lengths and numeric ranges are listed with each function in the SDK reference.