Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ wterm ("dub-term") renders to the DOM — native text selection, copy/paste, fin
- **24-bit color** — full RGB SGR support
- **Auto-resize** — `ResizeObserver`-based terminal resizing
- **WebSocket transport** — connect to a PTY backend with binary framing and reconnection
- **Mouse and focus reporting** — DOM input for SGR mouse tracking and terminal focus events

## Development

Expand Down
16 changes: 16 additions & 0 deletions apps/docs/src/app/api-reference/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,26 @@ When no URL is provided, the ~12 KB WASM binary is decoded from a base64 string
<td><code>usingAltScreen(): boolean</code></td>
<td>Whether the alternate screen buffer is active</td>
</tr>
<tr>
<td><code>mouseTracking(): number</code></td>
<td>Active mouse tracking mode (<code>0</code>, <code>1000</code>, or <code>1002</code>)</td>
</tr>
<tr>
<td><code>mouseSgr(): boolean</code></td>
<td>Whether SGR mouse encoding (mode 1006) is active</td>
</tr>
<tr>
<td><code>focusEvents(): boolean</code></td>
<td>Whether focus reporting (mode 1004) is active</td>
</tr>
<tr>
<td><code>synchronizedOutput(): boolean</code></td>
<td>Whether synchronized output mode (2026) is active</td>
</tr>
<tr>
<td><code>synchronizedOutputGeneration(): number</code></td>
<td>Monotonic generation for synchronized output blocks</td>
</tr>
</tbody>
</table>

Expand Down
2 changes: 2 additions & 0 deletions apps/docs/src/app/core/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

`@wterm/core` provides the headless terminal engine and WebSocket transport. Use it when you need direct access to the WASM bridge for a custom renderer, headless testing, or a server-connected terminal without the DOM layer.

With `@wterm/dom`, terminal applications can enable SGR mouse tracking (modes 1000, 1002, and 1006) and focus reporting (mode 1004). Pointer and focus reports are emitted through `onData`.

## Install

```bash
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/src/app/vanilla/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The `WTerm` constructor accepts all [shared terminal options](/api-reference#ter

See [WTerm Methods](/api-reference#wterm-methods) for the full list of instance methods (`init`, `write`, `resize`, `focus`, `destroy`).

When a terminal application enables SGR mouse tracking or focus reporting, WTerm sends those reports through `onData` with keyboard input and host responses.

## Themes

Import the stylesheet and apply a theme class to the terminal element:
Expand Down
5 changes: 4 additions & 1 deletion packages/@wterm/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install @wterm/core

## Pluggable Cores

`@wterm/core` defines a `TerminalCore` interface that any terminal emulation backend can implement. The built-in `WasmBridge` implements it using wterm's lightweight Zig WASM binary (~12 KB). For full-featured emulation (Kitty protocols, proper grapheme handling, mouse tracking, etc.), use [`@wterm/ghostty`](https://www.npmjs.com/package/@wterm/ghostty) which implements the same interface using libghostty (~400 KB).
`@wterm/core` defines a `TerminalCore` interface that any terminal emulation backend can implement. The built-in `WasmBridge` implements it using wterm's lightweight Zig WASM binary (~12 KB). For additional protocols and proper grapheme handling, use [`@wterm/ghostty`](https://www.npmjs.com/package/@wterm/ghostty), which implements the same interface using libghostty (~400 KB).

```ts
import { WTerm } from "@wterm/dom";
Expand Down Expand Up @@ -72,6 +72,9 @@ const cursor = bridge.getCursor(); // { row, col, visible }
| `cursorKeysApp()` | Whether cursor keys are in application mode |
| `bracketedPaste()` | Whether bracketed paste mode is active |
| `usingAltScreen()` | Whether the alternate screen buffer is active |
| `mouseTracking()` | Active mouse tracking mode (`0`, `1000`, or `1002`) |
| `mouseSgr()` | Whether SGR mouse encoding is active |
| `focusEvents()` | Whether focus reporting is active |
| `synchronizedOutput()` | Whether synchronized output mode (2026) is active |
| `synchronizedOutputGeneration()` | Monotonic generation for synchronized output blocks |

Expand Down
3 changes: 3 additions & 0 deletions packages/@wterm/core/src/terminal-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export interface TerminalCore {
cursorKeysApp(): boolean;
bracketedPaste(): boolean;
usingAltScreen(): boolean;
mouseTracking?(): 0 | 1000 | 1002;
mouseSgr?(): boolean;
focusEvents?(): boolean;
synchronizedOutput?(): boolean;
synchronizedOutputGeneration?(): number;

Expand Down
13 changes: 13 additions & 0 deletions packages/@wterm/core/src/wasm-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ interface WasmExports {
getCursorKeysApp(): number;
getBracketedPaste(): number;
getUsingAltScreen(): number;
getMouseTracking(): number;
getMouseSgr(): number;
getFocusEvents(): number;
getSynchronizedOutput(): number;
getSynchronizedOutputGeneration(): number;
getTitlePtr(): number;
Expand Down Expand Up @@ -167,6 +170,16 @@ export class WasmBridge implements TerminalCore {
usingAltScreen(): boolean {
return this.exports.getUsingAltScreen() !== 0;
}
mouseTracking(): 0 | 1000 | 1002 {
const mode = this.exports.getMouseTracking();
return mode === 1000 || mode === 1002 ? mode : 0;
}
mouseSgr(): boolean {
return this.exports.getMouseSgr() !== 0;
}
focusEvents(): boolean {
return this.exports.getFocusEvents() !== 0;
}
synchronizedOutput(): boolean {
return this.exports.getSynchronizedOutput() !== 0;
}
Expand Down
Binary file modified packages/@wterm/core/wasm/wterm.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/@wterm/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ new WTerm(element: HTMLElement, options?: WTermOptions)
| `focus()` | Focus the terminal element |
| `destroy()` | Clean up event listeners and DOM |

When a terminal application enables modes 1000 or 1002 with SGR encoding (1006), pointer input is sent through `onData`. Focus reports are sent when mode 1004 is active.

WTerm honors synchronized output mode (CSI `?2026`) by painting the block atomically when the mode closes. Each synchronized block can hold rendering for at most one second from its opening sequence. Ordinary payload does not extend that deadline. If the deadline expires, WTerm resumes painting until a fresh synchronized block begins.

### `WebSocketTransport`
Expand Down
Loading
Loading