Input
A surface reports user interactions as events, but only for the events your program explicitly requests. Most interactions stay local to the terminal—typing in a text field, toggling a checkbox, hovering, and scrolling. The host notifies your program only when needed, such as when a user commits a field value.
host → ESC ] 7279 ; a=ev:s=card:e=click:t=go ; {"area": {"c": 0, "r": 0, "w": 4, "h": 1}} ST
Events arrive on the program's stdin alongside regular keyboard input
(§9). s identifies the surface, e is the event
type, and t is the target element's id. The payload is MessagePack (shown
decoded in these examples).
Because id is how your program identifies elements, assign an id to every
element whose events you want to receive; a button without an id does not
report clicks. Use ASCII for IDs, because hosts normalize non-ASCII characters
(for example, café is reported as caf_) (§3.2).
See Keyboard and focus for key routing, focus, and blur.
What asks for each event
Element-level events are enabled on individual elements, while surface-level events are enabled on the placement. Unrequested events are never sent:
| event | enabled by | frequency |
|---|---|---|
click, change, input, submit |
element type, or click / input in data-on |
on every occurrence |
caret |
caret in a text field's data-on |
on selection change, at most once per frame |
press |
p=1 on the placement |
on every press |
dragstart, drag, dragend |
drag in data-on (and drop for drop targets) |
per element, cell, or step crossed |
gesturestart, gesture, gestureend |
gesture in data-on (Pointers and touch) |
gesture at most once per frame |
wheel |
wheel in data-on (Pointers and touch) |
summed, at most once per frame |
contextmenu |
contextmenu in data-on |
on each context-menu gesture: a right click, a long press, a pen's barrel button |
auxclick |
aux in data-on (rightbutton for the secondary button) |
on each release where the button was pressed |
hover |
v=1 on the placement |
on target change, at most once per frame |
view |
view in data-on |
once scrolling settles, otherwise at most once per frame |
fit |
f=1 on the placement |
at most once per frame |
focus, blur |
always enabled (keyboard state is always reported) | on every change |
command |
a=edit, or a named item in the program's menu |
on each matching key or menu selection |
caps |
capability query | on each capability change |
pointer |
capability query | when the user switches to another kind of pointer (Pointers and touch) |
Events are opt-in because they are written to the terminal's input stream. If a document remained active after its program exited, clicks or edits would inject escape sequences into the shell. Programs must detach surfaces they leave on screen (§5.5); detached surfaces emit no events.
data-on accepts a space-separated list of tokens, such as
data-on="click drag". The placement flags p, f, and v apply to the
entire surface: 1 enables reporting, 0 disables it, and the setting persists
until changed (§5.2). fit notifies your
program when the document's required row count changes, and caps notifies it
when host capabilities change.
Pointer and layout events require a visible surface. A hidden surface or one
scrolled out of view does not emit press, drag events, hover, fit, or
view. When the surface becomes visible again, the host reports any pending
changes.
click, press, drag, gesturestart, and wheel events include mods, a
bitmask of held modifier keys: 1 (shift), 2 (alt), 4 (ctrl), and
8 (super). mods is omitted when no modifiers are held. The same events,
but for drag and dragend, carry pointer, the kind of pointer that made
them: "mouse", "pen", or "touch"
(Pointers and touch). Ignore unrecognized
event types and fields, as future protocol versions may add new ones.
Clicks
The host emits click when the user activates a <button>, a link, a
<summary>, or an <input> of type button, submit, or reset. Other
elements opt in with data-on="click". The event targets the nearest matching
element walking outward from the clicked point.
<button id=save value=draft>Save</button>
<li id=row-7 data-on=click>…</li>
host → ESC ] 7279 ; a=ev:s=editor:e=click:t=save ; {"area": {"c": 2, "r": 5, "w": 6, "h": 1}, "value": "draft"} ST
areais the element's bounding box in cells, zero-indexed from the surface's top-left corner. Use it to anchor popups or menus next to the element. If the element is partially scrolled out of view,areastill reports its full bounds, socandrmay be negative.valueis included if the element has avalueattribute.counttracks multi-click runs:2for a double click,3for a triple click. Every click in the sequence is emitted, so a double click produces aclickfollowed by aclickwith"count": 2.
Keyboard activation (space or enter on a focused button) also emits click
with area, always as a single click. Only hosts advertising the count
feature report click counts, using the user's system double-click settings
(§4). If count is unavailable,
provide an alternative trigger for double-click actions.
Links
Clicking a link emits a normal click event; surfaces never navigate on their
own. Because the link's href identifies it, t is omitted. The payload
includes the raw href attribute and url, the address resolved against the
document's base URL (§7.3):
host → ESC ] 7279 ; a=ev:s=post:e=click ; {"area": {"c": 12, "r": 3, "w": 5, "h": 1}, "href": "../about", "url": "https://example.com/about"} ST
Your program decides how to handle the click—for example, rendering another view
or opening the URL with the OS. url is omitted if resolution falls under
https://hotty.invalid/, which is the default base URL when a document has no
<base href>. In that case, relative links include only href.
A link with target="_blank" is treated as a terminal hyperlink, equivalent
to an OSC 8 hyperlink in terminal cells. The host handles it directly using the
terminal's configured gesture, visual feedback, and security settings.
Terminal hyperlinks do not emit click events, nor press events when the host
intercepts the gesture. A target="_blank" link without a resolved url is not
treated as a hyperlink.
Forms
Form controls are handled locally by the host, and your program receives their values as they commit. Toggling checkboxes, selecting options, and typing text require no round-trips. Each control emits events according to its type:
| event | when | detail |
|---|---|---|
change |
immediately when a checkbox or radio button is toggled or a <select> option is picked; for text fields, on enter in an <input> or on blur if the value changed |
{"checked": bool, "value": str, "rev": int} for checkboxes and radio buttons; {"value": str, "rev": int} otherwise |
input |
on every edit to a control with data-on="input" |
{"value": str, "rev": int}, plus "sel": [int, int] if data-on="input caret" is set |
caret |
when the user moves the selection in a text field with data-on="caret" and no input event was emitted |
{"sel": [int, int], "rev": int} |
submit |
when a submit button is activated or enter is pressed in a text field (emitted after change) |
{"fields": [[str, str]]}: each named control's name and value in document order |
Here is a search input that streams every keystroke. As the user types "ad"
and presses enter, the host emits two input events, commits the field with
change, and submits the form:
<form id=search>
<input id=q name=q data-on=input>
</form>
host → ESC ] 7279 ; a=ev:s=find:e=input:t=q ; {"value": "a", "rev": 1} ST
host → ESC ] 7279 ; a=ev:s=find:e=input:t=q ; {"value": "ad", "rev": 2} ST
host → ESC ] 7279 ; a=ev:s=find:e=change:t=q ; {"value": "ad", "rev": 2} ST
host → ESC ] 7279 ; a=ev:s=find:e=submit:t=search ; {"fields": [["q", "ad"]]} ST
submituses name-value pairs because multiple controls can share a name (such as checkboxes in a group). A form with no named controls sends[]. Forms never make network requests;submitis the entire action.- Text field commits occur when the user presses
enterin an<input>(whether inside a<form>or not; new in 0.6) or when the field loses focus, including when the surface loses the keyboard.changeis sent only if the value differs from the last committed value. Withoutdata-on="input",changeis the only event emitted for the field. revis a user-edit counter that increments on every user edit, toggle, check, or selection. Caret movement and programmatic updates do not incrementrev. Passrevback ina=fieldto update a control safely (see below).- Programmatic updates via a delta to
value,checked, orselectedoverride the control's state, except while the user is actively editing that control (Updates).
Changing what the user is changing
Note
New in 0.5.
To modify a control that the user may be editing—for example, to apply
autocomplete in place—send a=field (§6.4) with the
last rev your program received. The host applies the update only if the
control's current rev still matches, preserving the field's id, undo
history, and keybindings, and placing the caret after the inserted text.
host → ESC ] 7279 ; a=ev:s=find:e=input:t=q ; {"value": "sr", "rev": 2} ST
program → ESC ] 7279 ; a=field:s=find:t=q ; {"rev": 2, "from": 0, "to": 2, "text": "src/"} ST
-
Payload fields:
revplus one of:valueto replace the entire value;textto replace the current selection or the byte rangefrom..to;checkedfor checkboxes and radio buttons.
Include
sel([anchor, caret]) to set the selection after the edit, or sendselalone to move the selection without changing the text. -
Byte offsets: positions are UTF-8 byte offsets (for example,
éis 2 bytes). JavaScript programs must convert from UTF-16 code units. -
Conflict handling: if the user edited the control before
a=fieldarrived, the host leaves the control unchanged and returnsESTALEwith the control's currentrev. Wait for the next event and recompute the update rather than retrying blindly, which would overwrite user input. -
No echo events:
a=fielddoes not emitinputorchange. If a field loses focus after being modified only by the program, nochangeis emitted. -
Undo: the host records an
a=fieldedit as a single undo step, just like a user edit. -
Caret position: a field's caret starts at the end of its value and remains where the user left it while another element is focused.
Presses
A placement with p=1 reports every pointer press inside its bounds, regardless
of whether the user pressed a control, plain text, or empty space. Use this to
track which surface is active—for example, selecting a card in a dashboard.
program → ESC ] 7279 ; a=place:s=cpu:c=40:r=6:p=1 ST
host → ESC ] 7279 ; a=ev:s=cpu:e=press:t=cpu-card ; {"area": {"c": 0, "r": 0, "w": 40, "h": 6}} ST
tis the nearest ancestor (or target) element with anid. If no ancestor has anid, bothtandareaare omitted.- Ordering:
pressis always emitted before any other event triggered by the same interaction (change,focus, andclickon release). - Triggers:
pressfires for a primary mouse button press, a tap, or a touch that transitions into a drag. It does not fire when the pointer passes through the surface, for mouse or pen presses with Alt held, or when the host consumes the press for a hyperlink gesture.
Drags
Add data-on="drag" to an element to track pointer movement from press to
release (§9.1). Drags support interactions that clicks
cannot, such as range selection across a grid, drag-and-drop reordering, and
sliders.
dragstartfires on press.tis the element withdata-on="drag", which must have anidor no drag starts.dragfires whenever the element under the pointer changes.tis the nearest element under the pointer that has anidanddragordropindata-on. If no such element is under the pointer,dragfires on each cell boundary crossed instead.dragendfires once on release, regardless of where the pointer is.
Every drag event includes c and r, the pointer's cell coordinates relative
to the surface's top-left corner. A touch's drag also carries finger, so two
fingers can drag at once (Pointers and touch). Coordinates continue outside the surface and
can be negative above or to the left. Because drag fires on target or step
changes rather than every pixel moved, event traffic stays low.
Sub-element steps: add data-steps="20" to divide an element's width into
20 discrete steps, adding x (0..20) to every drag event. Use
data-steps="0 20" to divide height instead, reporting y. A drag event is
also emitted whenever the step changes, as in this volume slider:
<div id=volume data-on=drag data-steps=20 style="touch-action: pan-y">…</div>
host → ESC ] 7279 ; a=ev:s=mixer:e=dragstart:t=volume ; {"c": 4, "r": 1, "x": 5} ST
host → ESC ] 7279 ; a=ev:s=mixer:e=drag:t=volume ; {"c": 5, "r": 1, "x": 6} ST
…
host → ESC ] 7279 ; a=ev:s=mixer:e=dragend:t=volume ; {"c": 7, "r": 1, "x": 9} ST
Steps are measured against the dragged element's bounds and clamped, even if the pointer leaves the element. This lets a slider continue tracking when a finger or cursor drifts off the track.
Drop targets: mark an element with data-on="drop" and an id so drags can
target it without making the element itself draggable. If a drop target also
defines data-steps, drag events over it include tx and ty for the step
within that target.
A list row with data-on="drag drop" and data-steps="0 1" acts as both a
draggable item and a drop target split into top and bottom halves (drop before
or after). A tree folder with data-steps="0 2" splits into three zones:
before, inside, and after.
- Pointer capture: the host captures the pointer until release (like
setPointerCapturein the DOM), delivering all motion to the drag even over terminal cells, other surfaces, or outside the terminal window. - No text selection: dragging on an element with
data-on="drag"does not select text. - Click fallback: if the pointer is released on the same element where the
drag started, and that element also has
clickindata-on, the host emitsclickafterdragend. - Cancellation: if the placement is removed, the document is replaced, the
host loses pointer capture, or a gesture takes the finger over, the drag ends
early with a
dragendevent that omitstand carries"cut": true. Deltas and re-placements do not cancel an active drag.
What a cell holds
Note
New in 0.8.
When your program handles a drag outside hotty—such as a terminal multiplexer
dragging a pane using standard terminal mouse reporting—the surface receives no
pointer events. To hit-test which draggable or drop-target element sits at a
given surface cell, send a=hit:
ESC ] 7279 ; a=hit:s=nav:c=3:r=7:n=4 ST
The host replies with a=ok and {"t": str, "tx": int, "ty": int}: the nearest
element at (c, r) with an id and drag or drop in data-on, along with
its step coordinates if configured
(§9.7). a=hit has no side effects
(no focus change, hover update, or events); your program renders any drop
indicator itself via a delta.
Touch on a surface
A tap on a surface acts as a click, and a touch drag scrolls like a mouse wheel (§9). Over a scrollable document, touch drags scroll the document until it hits its scroll limit. Over a non-scrollable surface, touch drags fall through to the underlying terminal cells (terminal scrollback, or wheel input on the alternate screen).
To prevent surfaces from trapping touch scrolling, touch starts a drag only when the element explicitly disables panning along the drag axis:
touch-actioncontrols touch behavior via standard CSS. On an element withdata-on="drag", a touch begins a drag only iftouch-actiondisallows panning in the initial direction of movement.pan-yon a horizontal slider lets horizontal swipes drag the slider while vertical swipes still scroll.noneenables dragging in any direction. The default (auto) always scrolls. A first move as far across as down scrolls where a pan is allowed either way, and drags undernone.- Event order: when a touch becomes a drag, the host emits
press(if enabled) followed bydragstart, both at the touch start coordinates. - Taps and long presses: a tap emits
presson lift. A long press never becomes a drag. - Multi-touch: each finger drags, taps, or long-presses on its own, while
the others drag. Two fingers on an element with
gestureindata-onare a pinch the program hears; elsewhere, once a finger pans, the host owns the rest until all fingers lift (Pointers and touch).
Touch with Alt held never starts a drag, and touch movement does not trigger
hover. A host may optionally report hover on the target touched at the end of
a tap or touch drag.
Presses with Alt
A mouse or pen press with Alt held always bypasses surfaces and goes to the
underlying terminal cells (§9.2). If the
program has terminal mouse reporting enabled, it receives the press with the Alt
modifier set (for example, CSI < 8 ; <col> ; <row> M in SGR encoding).
This lets programs implement global gestures over their own surfaces—for example, a multiplexer moving panes with Alt+drag like a window manager.
- Surfaces see nothing: no
press,dragstart, orclickis emitted, no focus is taken, and no hyperlink is opened. If a surface currently holds the keyboard, it releases focus and emitsblur. - Sticky for the gesture: the modifier state at press time determines routing until release. Releasing Alt mid-drag does not transfer the gesture to a surface, and pressing Alt during an active surface drag does not cancel it.
- macOS: Alt corresponds to Option, regardless of the terminal's Option-as-Meta or character-composition settings.
- Mouse and pen only: touch taps always behave as clicks regardless of held modifier keys.
Where the pointer passes through
On hosts advertising the passthrough feature, a surface only captures pointer
events where an interactive CSS box is hit
(§9.3). The host performs
standard browser hit-testing and ignores boxes with pointer-events: none. This
allows an overlay frame around terminal cells to leave the interior cells
clickable:
<style>
html { pointer-events: none }
#close { pointer-events: auto }
</style>
<div class=frame><button id=close>Close</button></div>
Where hit-testing misses, the pointer falls through to whatever lies beneath—another surface or the terminal cells. Over terminal cells, your program receives normal mouse reporting as if no surface were present, the surface emits no events, and a press returns keyboard focus to the terminal.
Pointer ownership is fixed at press time until release. On hosts without
passthrough, the entire surface rectangle captures all pointer events. If your
program needs pointer access to cells beneath a surface, check for the
passthrough capability and avoid covering those cells when it is absent.
Hover
CSS :hover states and cursor shapes work locally without involving your
program. If your program also needs to know which element is under the pointer
(for example, to display a custom tooltip or clear a highlight), enable v=1 on
the placement (§9.4):
program → ESC ] 7279 ; a=place:s=chart:c=60:r=12:v=1 ST
host → ESC ] 7279 ; a=ev:s=chart:e=hover:t=bar-7 ; {"c": 31, "r": 4} ST
host → ESC ] 7279 ; a=ev:s=chart:e=hover ; {"out": true} ST
- Target changes only:
hoverfires when the nearest element with anidunder the pointer changes, reportingtand the pointer cell(c, r). Moving within the same element emits nothing, and events are throttled to at most one per frame. - Pointer leave:
{"out": true}fires when the pointer leaves the surface for terminal cells, another surface, apointer-events: noneregion, or outside the terminal window. An Alt+press also emitsout. - Suppressed during presses: while a pointer button is held, no
hoverevents are emitted (drags report their own targets). On release, the host reports the current hover target. - Mouse and pen only: touch motion does not emit
hover, though a host may report the element touched when a tap or touch drag lifts.
Hover reporting is gated by the hover capability. If a host lacks hover,
your program will not receive out events and should clear highlights on the
next key or press instead.
What is in view
Scrollable documents can report which marked elements are currently visible in
the viewport (§9.5). Add data-on="view" and an id
to each element you want to track—useful for highlighting active sections in a
table of contents or lazy-loading items in a long list.
host → ESC ] 7279 ; a=ev:s=guide:e=view ; {"in": {"install": {"c": 0, "r": -3, "w": 60, "h": 8}, "usage": {"c": 0, "r": 5, "w": 60, "h": 20}}, "end": false} ST
inmaps every currently visible tracked element'sidto its full bounding box. Because each event is a complete snapshot rather than a diff, your program does not need to track incremental visibility state.endistruewhen the document root is scrolled to the bottom.- Timing:
viewfires once after initial layout, and again whenever the payload changes. During active scrolling, the host waits for scrolling to settle before emitting.
To scroll an element into view programmatically, use the reveal delta op. To
scroll in key-sized increments from your own keymap, use the scroll op
(Updates).
Touch in the cells
Note
New in 0.4.
By default, touch dragging over terminal cells scrolls the terminal rather than
generating mouse drag events, so cell-rendered sliders or splitters work with a
mouse but not with touch. Use a=touch to declare cell rectangles where touch
drags along a specified axis should be translated into mouse drags
(§9.6):
program → ESC ] 7279 ; a=touch ; {"areas": [{"c": 10, "r": 20, "w": 30, "h": 1, "drag": "x"}]} ST
Each area specifies:
candr: top-left column and row, zero-indexed from the screen origin (note that terminal mouse reports are 1-indexed);wandh: width in columns and height in rows;drag: allowed drag axis—"x"(horizontal),"y"(vertical), or"xy"(either).
Inside a declared area, a touch moving along the configured axis is synthesized as a primary mouse button press at the start cell, drag motion as the finger moves, and release on lift. Your program receives standard terminal mouse events in whatever mode and encoding it enabled, with no extra event format to parse.
- Taps and orthogonal swipes: a tap inside an area synthesizes a press and release on lift (so a slider jumps to the tapped position). Swiping along the non-drag axis still scrolls.
- Active conditions: translation applies only while the program has mouse button reporting enabled and the terminal is not viewing scrollback.
- Lifetime: areas persist until replaced by another
a=touchor cleared with an emptya=touch. The main and alternate screens maintain separate area lists. - Screen-relative: coordinates are tied to screen cells, not buffer lines, so they do not move when terminal text scrolls. Resend areas when your UI moves, and clear them on exit.
- Surface precedence: if a touch starts on a surface that accepts pointer input, the surface handles it.
- Touch only: mouse and pen input are unaffected.
Hosts without touch support still accept a=touch, so you can send areas
unconditionally. Multiplexers that forward mouse input should forward each
pane's touch areas translated to the pane's screen offset. SDKs construct this
command with Touch (SDK design).