Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -29,6 +29,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
12 changes: 12 additions & 0 deletions apps/docs/src/app/api-reference/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,18 @@ 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>
</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 |

### `WebSocketTransport`

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;

// -- Side outputs --
getTitle(): string | null;
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;
getTitlePtr(): number;
getTitleLen(): number;
getTitleChanged(): number;
Expand Down Expand Up @@ -164,6 +167,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;
}

getTitle(): string | null {
if (this.exports.getTitleChanged() === 0) return null;
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.

### `WebSocketTransport`

Connect to a PTY backend over WebSocket (re-exported from `@wterm/core`).
Expand Down
Loading
Loading