@gjermundgaraba/clankermux 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/client/attachment.d.ts +8 -30
- package/dist/client/attachment.js +33 -32
- package/dist/client/client.d.ts +1 -7
- package/dist/client/client.js +20 -50
- package/dist/client/connection.d.ts +0 -18
- package/dist/client/connection.js +0 -17
- package/dist/client/copy.d.ts +3 -20
- package/dist/client/copy.js +22 -44
- package/dist/client/index.d.ts +1 -6
- package/dist/client/index.js +1 -3
- package/dist/client/keyboard.d.ts +1 -27
- package/dist/client/keyboard.js +18 -34
- package/dist/client/listeners.d.ts +10 -0
- package/dist/client/listeners.js +35 -0
- package/dist/client/mount.d.ts +10 -5
- package/dist/client/mount.js +71 -103
- package/dist/client/osc52.d.ts +1 -4
- package/dist/client/osc52.js +31 -23
- package/dist/client/profile.d.ts +0 -6
- package/dist/client/profile.js +0 -6
- package/dist/client/worker.d.ts +16 -10
- package/dist/client/worker.js +201 -301
- package/dist/engine/decoder.d.ts +0 -20
- package/dist/engine/decoder.js +12 -35
- package/dist/engine/index.d.ts +7 -49
- package/dist/engine/index.js +37 -67
- package/dist/engine/keys.d.ts +0 -7
- package/dist/engine/keys.js +9 -15
- package/dist/engine/render.d.ts +21 -17
- package/dist/engine/render.js +67 -37
- package/dist/engine/selection.d.ts +0 -17
- package/dist/engine/selection.js +9 -34
- package/dist/proto/messages.d.ts +800 -475
- package/dist/proto/messages.js +1 -0
- package/dist/renderer/index.d.ts +7 -6
- package/dist/renderer/index.js +73 -54
- package/package.json +1 -5
package/dist/engine/decoder.d.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
import { type Engine, Terminal } from "./index.ts";
|
|
2
|
-
/** Position just past the `READY` record, once every byte through it is in `buf`. */
|
|
3
2
|
export declare function readyEnd(buf: Uint8Array, len?: number): number | undefined;
|
|
4
|
-
/** Position just past the next `PAGE` or `FINISH` record at or after `pos`. */
|
|
5
3
|
export declare function stepEnd(buf: Uint8Array, pos: number, len?: number): number | undefined;
|
|
6
|
-
/**
|
|
7
|
-
* An incremental snapshot decoder over a buffer of known capacity, filled
|
|
8
|
-
* as bytes arrive. The library reads the buffer lazily, so `ready` and
|
|
9
|
-
* `nextPage` are called only once the bytes they consume are in place.
|
|
10
|
-
*
|
|
11
|
-
* This leans on the engine's behaviour, not its contract: the header asks
|
|
12
|
-
* for an immutable buffer. A `GhosttyReader` callback from wasm would
|
|
13
|
-
* need a JS function placed in the module's function table, which takes
|
|
14
|
-
* a generated wasm wrapper per signature; filling the buffer behind the
|
|
15
|
-
* decoder is less machinery. The engine is pinned; its decoder test
|
|
16
|
-
* pushes the bytes piecewise, so an engine that validated ahead would
|
|
17
|
-
* fail there before shipping.
|
|
18
|
-
*/
|
|
19
4
|
export declare class Decoder {
|
|
20
5
|
readonly engine: Engine;
|
|
21
6
|
readonly capacity: number;
|
|
@@ -29,17 +14,12 @@ export declare class Decoder {
|
|
|
29
14
|
setMaxContinuationBytes(max: number): void;
|
|
30
15
|
push(bytes: Uint8Array): void;
|
|
31
16
|
private get source();
|
|
32
|
-
/** Whether every byte through `READY` is buffered. */
|
|
33
17
|
readyAvailable(): boolean;
|
|
34
18
|
stepAvailable(): boolean;
|
|
35
|
-
/** Decodes through `READY`; the terminal is then renderable. */
|
|
36
19
|
ready(): Terminal;
|
|
37
|
-
/** Decodes one history page. False once `FINISH` is validated. */
|
|
38
20
|
nextPage(): boolean;
|
|
39
21
|
terminal(): Terminal | undefined;
|
|
40
|
-
/** Whether `FINISH` was validated: the snapshot is complete. */
|
|
41
22
|
finished(): boolean;
|
|
42
|
-
/** Frees the decoder and its buffer; the terminal, finished or not, is the caller's. */
|
|
43
23
|
release(): Terminal | undefined;
|
|
44
24
|
free(): void;
|
|
45
25
|
}
|
package/dist/engine/decoder.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
1
|
+
import { Terminal } from "./index.js";
|
|
2
|
+
const MAGIC_LEN = 8;
|
|
3
|
+
const VERSION_LEN = 2;
|
|
4
|
+
const ENVELOPE_LEN = MAGIC_LEN + VERSION_LEN;
|
|
5
|
+
const TAG_LEN = 2;
|
|
6
|
+
const PAYLOAD_LENGTH_LEN = 4;
|
|
7
|
+
const CRC32C_LEN = 4;
|
|
8
|
+
const RECORD_HEADER_LEN = TAG_LEN + PAYLOAD_LENGTH_LEN + CRC32C_LEN;
|
|
6
9
|
const TAG_PAGE = 3;
|
|
7
10
|
const TAG_READY = 5;
|
|
8
11
|
const TAG_FINISH = 6;
|
|
9
|
-
/** The record starting at `pos`: its tag and the position just past it. */
|
|
10
12
|
function recordAt(buf, len, pos) {
|
|
11
13
|
if (pos + RECORD_HEADER_LEN > len)
|
|
12
14
|
return undefined;
|
|
13
15
|
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
14
16
|
const tag = view.getUint16(pos, true);
|
|
15
|
-
const payload = view.getUint32(pos +
|
|
17
|
+
const payload = view.getUint32(pos + TAG_LEN, true);
|
|
16
18
|
const end = pos + RECORD_HEADER_LEN + payload;
|
|
17
19
|
return end <= len ? [tag, end] : undefined;
|
|
18
20
|
}
|
|
@@ -26,27 +28,12 @@ function endOfStep(buf, len, pos, last) {
|
|
|
26
28
|
pos = record[1];
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
/** Position just past the `READY` record, once every byte through it is in `buf`. */
|
|
30
31
|
export function readyEnd(buf, len = buf.length) {
|
|
31
32
|
return endOfStep(buf, len, ENVELOPE_LEN, (tag) => tag === TAG_READY);
|
|
32
33
|
}
|
|
33
|
-
/** Position just past the next `PAGE` or `FINISH` record at or after `pos`. */
|
|
34
34
|
export function stepEnd(buf, pos, len = buf.length) {
|
|
35
35
|
return endOfStep(buf, len, pos, (tag) => tag === TAG_PAGE || tag === TAG_FINISH);
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* An incremental snapshot decoder over a buffer of known capacity, filled
|
|
39
|
-
* as bytes arrive. The library reads the buffer lazily, so `ready` and
|
|
40
|
-
* `nextPage` are called only once the bytes they consume are in place.
|
|
41
|
-
*
|
|
42
|
-
* This leans on the engine's behaviour, not its contract: the header asks
|
|
43
|
-
* for an immutable buffer. A `GhosttyReader` callback from wasm would
|
|
44
|
-
* need a JS function placed in the module's function table, which takes
|
|
45
|
-
* a generated wasm wrapper per signature; filling the buffer behind the
|
|
46
|
-
* decoder is less machinery. The engine is pinned; its decoder test
|
|
47
|
-
* pushes the bytes piecewise, so an engine that validated ahead would
|
|
48
|
-
* fail there before shipping.
|
|
49
|
-
*/
|
|
50
37
|
export class Decoder {
|
|
51
38
|
engine;
|
|
52
39
|
capacity;
|
|
@@ -60,7 +47,6 @@ export class Decoder {
|
|
|
60
47
|
this.engine = engine;
|
|
61
48
|
this.capacity = capacity;
|
|
62
49
|
this.buffer = engine.alloc(capacity);
|
|
63
|
-
// Never let the decoder see another allocation's leftovers.
|
|
64
50
|
engine.memory.fill(0, this.buffer, this.buffer + capacity);
|
|
65
51
|
this.decoder = engine.construct("ghostty_snapshot_decoder_new_buf", this.buffer, capacity);
|
|
66
52
|
}
|
|
@@ -80,14 +66,12 @@ export class Decoder {
|
|
|
80
66
|
get source() {
|
|
81
67
|
return this.engine.memory.subarray(this.buffer, this.buffer + this.capacity);
|
|
82
68
|
}
|
|
83
|
-
/** Whether every byte through `READY` is buffered. */
|
|
84
69
|
readyAvailable() {
|
|
85
70
|
return readyEnd(this.source, this.filled) !== undefined;
|
|
86
71
|
}
|
|
87
72
|
stepAvailable() {
|
|
88
73
|
return !this.complete && stepEnd(this.source, this.consumed, this.filled) !== undefined;
|
|
89
74
|
}
|
|
90
|
-
/** Decodes through `READY`; the terminal is then renderable. */
|
|
91
75
|
ready() {
|
|
92
76
|
const end = readyEnd(this.source, this.filled);
|
|
93
77
|
if (end === undefined)
|
|
@@ -96,29 +80,22 @@ export class Decoder {
|
|
|
96
80
|
this.consumed = end;
|
|
97
81
|
return this.term;
|
|
98
82
|
}
|
|
99
|
-
/** Decodes one history page. False once `FINISH` is validated. */
|
|
100
83
|
nextPage() {
|
|
101
84
|
const end = stepEnd(this.source, this.consumed, this.filled);
|
|
102
85
|
if (end === undefined)
|
|
103
86
|
throw new Error("next page not buffered");
|
|
104
|
-
const
|
|
87
|
+
const page = this.engine.present("ghostty_snapshot_decoder_next", this.decoder);
|
|
105
88
|
this.consumed = end;
|
|
106
|
-
if (
|
|
89
|
+
if (!page)
|
|
107
90
|
this.complete = true;
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
if (code !== this.engine.result.SUCCESS)
|
|
111
|
-
throw new EngineError("ghostty_snapshot_decoder_next", code);
|
|
112
|
-
return true;
|
|
91
|
+
return page;
|
|
113
92
|
}
|
|
114
93
|
terminal() {
|
|
115
94
|
return this.term;
|
|
116
95
|
}
|
|
117
|
-
/** Whether `FINISH` was validated: the snapshot is complete. */
|
|
118
96
|
finished() {
|
|
119
97
|
return this.complete;
|
|
120
98
|
}
|
|
121
|
-
/** Frees the decoder and its buffer; the terminal, finished or not, is the caller's. */
|
|
122
99
|
release() {
|
|
123
100
|
const term = this.term;
|
|
124
101
|
this.term = undefined;
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ export { Decoder, readyEnd } from "./decoder.ts";
|
|
|
2
2
|
export { KeyEncoder, isText, keyName } from "./keys.ts";
|
|
3
3
|
export type { KeyInput } from "./keys.ts";
|
|
4
4
|
export { FLAG, NO_COLOR, RenderState } from "./render.ts";
|
|
5
|
-
export type { Cell, Frame, FrameRow } from "./render.ts";
|
|
5
|
+
export type { Cell, Frame, FrameRow, PackedCells, PackedFrame } from "./render.ts";
|
|
6
6
|
export { ENGINE } from "./pin.ts";
|
|
7
7
|
export { SelectionGesture } from "./selection.ts";
|
|
8
8
|
export type { CellPoint } from "./selection.ts";
|
|
9
|
-
/** Struct fields to set: numbers, or the fields of a nested struct. */
|
|
10
9
|
type Packed = {
|
|
11
10
|
[field: string]: number | Packed;
|
|
12
11
|
};
|
|
@@ -19,7 +18,6 @@ export interface Scrollbar {
|
|
|
19
18
|
/** The viewport's rows. */
|
|
20
19
|
len: number;
|
|
21
20
|
}
|
|
22
|
-
/** Position and width of a bit field, from the manifest. */
|
|
23
21
|
export interface BitField {
|
|
24
22
|
lsb: number;
|
|
25
23
|
width: number;
|
|
@@ -29,11 +27,11 @@ export declare class EngineError extends Error {
|
|
|
29
27
|
readonly code: number;
|
|
30
28
|
constructor(call: string, code: number);
|
|
31
29
|
}
|
|
32
|
-
/** A loaded ghostty-vt.wasm instance. */
|
|
33
30
|
export declare class Engine {
|
|
34
31
|
private readonly exports;
|
|
35
32
|
private readonly types;
|
|
36
|
-
|
|
33
|
+
private memoryView;
|
|
34
|
+
private dataView;
|
|
37
35
|
readonly result: {
|
|
38
36
|
SUCCESS: number;
|
|
39
37
|
OUT_OF_SPACE: number;
|
|
@@ -42,61 +40,39 @@ export declare class Engine {
|
|
|
42
40
|
};
|
|
43
41
|
private constructor();
|
|
44
42
|
static load(wasm: BufferSource): Promise<Engine>;
|
|
45
|
-
/**
|
|
43
|
+
/** Cached views are valid only until wasm grows its linear memory. */
|
|
46
44
|
get memory(): Uint8Array;
|
|
47
45
|
get view(): DataView;
|
|
48
46
|
call(name: string, ...args: number[]): number;
|
|
49
|
-
/** Calls a function returning GhosttyResult and throws on failure. */
|
|
50
47
|
check(name: string, ...args: number[]): void;
|
|
48
|
+
present(name: string, ...args: number[]): boolean;
|
|
51
49
|
alloc(len: number): number;
|
|
52
50
|
free(ptr: number, len: number): void;
|
|
53
|
-
/** Runs `f` with `bytes` copied into wasm memory, or with a null
|
|
54
|
-
* pointer for no bytes (which the allocator cannot serve). */
|
|
55
51
|
withBytes<T>(bytes: Uint8Array, f: (ptr: number) => T): T;
|
|
56
|
-
/** Runs `f` with a scratch allocation of `len` bytes. */
|
|
57
52
|
scratch<T>(len: number, f: (ptr: number) => T): T;
|
|
58
|
-
/** Runs `f` with an opaque-handle slot; the handle is taken out before the slot is freed. */
|
|
59
53
|
private withSlot;
|
|
60
|
-
/** Creates an opaque handle through a `(allocator, out_slot, ...args)` constructor. */
|
|
61
54
|
construct(name: string, ...args: number[]): number;
|
|
62
|
-
/** Takes an opaque handle from a `(...args, out_slot)` call. */
|
|
63
55
|
take(name: string, ...args: number[]): number;
|
|
64
56
|
private cString;
|
|
65
57
|
private struct;
|
|
66
|
-
/** Builds a zeroed, sized struct with the given fields set. */
|
|
67
58
|
pack(name: string, values: Packed): Uint8Array;
|
|
68
|
-
/** Reads one numeric or boolean field of a struct at `ptr`. */
|
|
69
59
|
field(name: string, ptr: number, key: string): number;
|
|
70
|
-
/** A bit field of a packed type: `path` names the field, or a union
|
|
71
|
-
* field, its arm and the arm's field. */
|
|
72
60
|
bits(name: string, ...path: [field: string] | [field: string, arm: string, inner: string]): BitField;
|
|
73
|
-
/** Reads a bit field of a 64-bit packed value at `ptr`. */
|
|
74
61
|
readBits(ptr: number, field: BitField): number;
|
|
75
|
-
/** Runs an encoder that reports `OUT_OF_SPACE` with the needed size,
|
|
76
|
-
* growing the output buffer until it fits. */
|
|
77
62
|
growing(name: string, initial: number, encode: (buf: number, cap: number, len: number) => number): Uint8Array;
|
|
78
|
-
/** Runs an `*_alloc` call that returns bytes through `(ptr, len)` out
|
|
79
|
-
* parameters and frees them after copying. */
|
|
80
63
|
allocated(call: (ptr: number, len: number) => void): Uint8Array;
|
|
81
|
-
/** The offset of a struct field, for nested reads. */
|
|
82
64
|
offsetOf(name: string, key: string): number;
|
|
83
65
|
enumValue(name: string, member: string): number;
|
|
84
66
|
hasEnumValue(name: string, member: string): boolean;
|
|
85
67
|
sizeOf(name: string): number;
|
|
86
|
-
|
|
68
|
+
alignOf(name: string): number;
|
|
69
|
+
private type;
|
|
87
70
|
readString(ptr: number): string;
|
|
88
|
-
/** A `GhosttyColorRgb` at `ptr` as 0xRRGGBB. */
|
|
89
71
|
readRgb(ptr: number): number;
|
|
90
72
|
terminalNew(cols: number, rows: number): Terminal;
|
|
91
|
-
/** Decodes a complete snapshot held in memory. */
|
|
92
73
|
decodeSnapshot(bytes: Uint8Array): Terminal;
|
|
93
|
-
/**
|
|
94
|
-
* Paste text encoded for the PTY: unsafe bytes blanked, wrapped in
|
|
95
|
-
* bracketed paste when `bracketed`, newlines to carriage returns otherwise.
|
|
96
|
-
*/
|
|
97
74
|
encodePaste(text: string, bracketed: boolean): Uint8Array;
|
|
98
75
|
}
|
|
99
|
-
/** `ghostty_terminal_new` with the given `GhosttyTerminal` handle wrapped. */
|
|
100
76
|
export declare class Terminal {
|
|
101
77
|
readonly engine: Engine;
|
|
102
78
|
readonly handle: number;
|
|
@@ -106,39 +82,21 @@ export declare class Terminal {
|
|
|
106
82
|
get cols(): number;
|
|
107
83
|
get rows(): number;
|
|
108
84
|
get scrollbackRows(): number;
|
|
109
|
-
/** Whether the alternate screen (full-screen programs) is active; it
|
|
110
|
-
* has no history to scroll. */
|
|
111
85
|
get alternate(): boolean;
|
|
112
86
|
get scrollbar(): Scrollbar;
|
|
113
|
-
/** Moves the viewport `rows` rows (up when negative) through the
|
|
114
|
-
* history, or to its top or the live screen at its bottom. Output does
|
|
115
|
-
* not move a viewport scrolled into the history. */
|
|
116
87
|
scroll(to: number | "top" | "bottom"): void;
|
|
117
88
|
get title(): string;
|
|
118
|
-
/** An untracked `GhosttyGridRef` to the viewport cell at `at`, valid
|
|
119
|
-
* until the terminal changes. */
|
|
120
89
|
gridRef(at: {
|
|
121
90
|
x: number;
|
|
122
91
|
y: number;
|
|
123
92
|
}): Uint8Array;
|
|
124
|
-
/** Installs `selection` (a `GhosttySelection`) as the terminal's, which
|
|
125
|
-
* the terminal then tracks through output, scrolling and resizes, or
|
|
126
|
-
* clears it. */
|
|
127
93
|
select(selection: Uint8Array | undefined): void;
|
|
128
|
-
/** The selection's text: soft-wrapped lines joined, trailing blanks
|
|
129
|
-
* trimmed, as Ghostty copies it; undefined with no selection. */
|
|
130
94
|
selectionText(): string | undefined;
|
|
131
|
-
/** Whether the active screen has a selection. */
|
|
132
95
|
get selected(): boolean;
|
|
133
|
-
/** Whether DEC private mode `number` is set. */
|
|
134
96
|
mode(number: number): boolean;
|
|
135
|
-
/** No cell size in pixels: `RESIZED` carries none. */
|
|
136
97
|
resize(cols: number, rows: number): void;
|
|
137
|
-
/** Sets a default colour (0xRRGGBB), as OSC 10, 11 and 12 report it. */
|
|
138
98
|
setColor(kind: "foreground" | "background" | "cursor", color: number): void;
|
|
139
|
-
/** The whole terminal, history included, as a snapshot. */
|
|
140
99
|
snapshot(): Uint8Array;
|
|
141
|
-
/** The active screen as plain text, one line per row. */
|
|
142
100
|
formatPlain(): string;
|
|
143
101
|
free(): void;
|
|
144
102
|
}
|
package/dist/engine/index.js
CHANGED
|
@@ -12,11 +12,11 @@ export class EngineError extends Error {
|
|
|
12
12
|
this.code = code;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
/** A loaded ghostty-vt.wasm instance. */
|
|
16
15
|
export class Engine {
|
|
17
16
|
exports;
|
|
18
17
|
types;
|
|
19
|
-
|
|
18
|
+
memoryView;
|
|
19
|
+
dataView;
|
|
20
20
|
result;
|
|
21
21
|
constructor(exports) {
|
|
22
22
|
this.exports = exports;
|
|
@@ -34,12 +34,18 @@ export class Engine {
|
|
|
34
34
|
const { instance } = await WebAssembly.instantiate(wasm, {});
|
|
35
35
|
return new Engine(instance.exports);
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
37
|
+
/** Cached views are valid only until wasm grows its linear memory. */
|
|
38
38
|
get memory() {
|
|
39
|
-
|
|
39
|
+
const buffer = this.exports.memory.buffer;
|
|
40
|
+
if (this.memoryView?.buffer !== buffer)
|
|
41
|
+
this.memoryView = new Uint8Array(buffer);
|
|
42
|
+
return this.memoryView;
|
|
40
43
|
}
|
|
41
44
|
get view() {
|
|
42
|
-
|
|
45
|
+
const buffer = this.exports.memory.buffer;
|
|
46
|
+
if (this.dataView?.buffer !== buffer)
|
|
47
|
+
this.dataView = new DataView(buffer);
|
|
48
|
+
return this.dataView;
|
|
43
49
|
}
|
|
44
50
|
call(name, ...args) {
|
|
45
51
|
const fn = this.exports[name];
|
|
@@ -47,12 +53,19 @@ export class Engine {
|
|
|
47
53
|
throw new Error(`wasm export ${name} missing`);
|
|
48
54
|
return fn(...args);
|
|
49
55
|
}
|
|
50
|
-
/** Calls a function returning GhosttyResult and throws on failure. */
|
|
51
56
|
check(name, ...args) {
|
|
52
57
|
const code = this.call(name, ...args);
|
|
53
58
|
if (code !== this.result.SUCCESS)
|
|
54
59
|
throw new EngineError(name, code);
|
|
55
60
|
}
|
|
61
|
+
present(name, ...args) {
|
|
62
|
+
const code = this.call(name, ...args);
|
|
63
|
+
if (code === this.result.NO_VALUE)
|
|
64
|
+
return false;
|
|
65
|
+
if (code !== this.result.SUCCESS)
|
|
66
|
+
throw new EngineError(name, code);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
56
69
|
alloc(len) {
|
|
57
70
|
const ptr = this.call("ghostty_wasm_alloc", len);
|
|
58
71
|
if (ptr === 0)
|
|
@@ -62,8 +75,6 @@ export class Engine {
|
|
|
62
75
|
free(ptr, len) {
|
|
63
76
|
this.call("ghostty_wasm_free", ptr, len);
|
|
64
77
|
}
|
|
65
|
-
/** Runs `f` with `bytes` copied into wasm memory, or with a null
|
|
66
|
-
* pointer for no bytes (which the allocator cannot serve). */
|
|
67
78
|
withBytes(bytes, f) {
|
|
68
79
|
if (bytes.length === 0)
|
|
69
80
|
return f(0);
|
|
@@ -76,7 +87,6 @@ export class Engine {
|
|
|
76
87
|
this.free(ptr, bytes.length);
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
|
-
/** Runs `f` with a scratch allocation of `len` bytes. */
|
|
80
90
|
scratch(len, f) {
|
|
81
91
|
const ptr = this.alloc(len);
|
|
82
92
|
try {
|
|
@@ -86,7 +96,6 @@ export class Engine {
|
|
|
86
96
|
this.free(ptr, len);
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
|
-
/** Runs `f` with an opaque-handle slot; the handle is taken out before the slot is freed. */
|
|
90
99
|
withSlot(f) {
|
|
91
100
|
const slot = this.call("ghostty_wasm_alloc_opaque");
|
|
92
101
|
try {
|
|
@@ -96,14 +105,12 @@ export class Engine {
|
|
|
96
105
|
this.call("ghostty_wasm_free_opaque", slot);
|
|
97
106
|
}
|
|
98
107
|
}
|
|
99
|
-
/** Creates an opaque handle through a `(allocator, out_slot, ...args)` constructor. */
|
|
100
108
|
construct(name, ...args) {
|
|
101
109
|
return this.withSlot((slot) => {
|
|
102
110
|
this.check(name, 0, slot, ...args);
|
|
103
111
|
return this.call("ghostty_wasm_take_opaque", slot);
|
|
104
112
|
});
|
|
105
113
|
}
|
|
106
|
-
/** Takes an opaque handle from a `(...args, out_slot)` call. */
|
|
107
114
|
take(name, ...args) {
|
|
108
115
|
return this.withSlot((slot) => {
|
|
109
116
|
this.check(name, ...args, slot);
|
|
@@ -123,7 +130,6 @@ export class Engine {
|
|
|
123
130
|
throw new Error(`unknown struct ${name}`);
|
|
124
131
|
return info;
|
|
125
132
|
}
|
|
126
|
-
/** Builds a zeroed, sized struct with the given fields set. */
|
|
127
133
|
pack(name, values) {
|
|
128
134
|
const info = this.struct(name);
|
|
129
135
|
const out = new Uint8Array(info.size);
|
|
@@ -153,7 +159,6 @@ export class Engine {
|
|
|
153
159
|
}
|
|
154
160
|
return out;
|
|
155
161
|
}
|
|
156
|
-
/** Reads one numeric or boolean field of a struct at `ptr`. */
|
|
157
162
|
field(name, ptr, key) {
|
|
158
163
|
const field = this.struct(name).fields[key];
|
|
159
164
|
if (!field)
|
|
@@ -171,8 +176,6 @@ export class Engine {
|
|
|
171
176
|
throw new Error(`${name}.${key}: unsupported size ${field.size}`);
|
|
172
177
|
}
|
|
173
178
|
}
|
|
174
|
-
/** A bit field of a packed type: `path` names the field, or a union
|
|
175
|
-
* field, its arm and the arm's field. */
|
|
176
179
|
bits(name, ...path) {
|
|
177
180
|
const info = this.types[name];
|
|
178
181
|
if (!info || info.kind !== "packed")
|
|
@@ -188,13 +191,16 @@ export class Engine {
|
|
|
188
191
|
throw new Error(`${name}.${field} has no ${arm}.${inner}`);
|
|
189
192
|
return { lsb: top.lsb + nested.lsb, width: nested.width };
|
|
190
193
|
}
|
|
191
|
-
/** Reads a bit field of a 64-bit packed value at `ptr`. */
|
|
192
194
|
readBits(ptr, field) {
|
|
195
|
+
const bit = field.lsb % 32;
|
|
196
|
+
if (bit + field.width <= 32) {
|
|
197
|
+
const word = this.view.getUint32(ptr + 4 * Math.floor(field.lsb / 32), true) >>> bit;
|
|
198
|
+
// A 32-bit mask would be signed; preserve the unsigned full word.
|
|
199
|
+
return field.width === 32 ? word : word & (2 ** field.width - 1);
|
|
200
|
+
}
|
|
193
201
|
const value = this.view.getBigUint64(ptr, true);
|
|
194
202
|
return Number((value >> BigInt(field.lsb)) & ((1n << BigInt(field.width)) - 1n));
|
|
195
203
|
}
|
|
196
|
-
/** Runs an encoder that reports `OUT_OF_SPACE` with the needed size,
|
|
197
|
-
* growing the output buffer until it fits. */
|
|
198
204
|
growing(name, initial, encode) {
|
|
199
205
|
let cap = initial;
|
|
200
206
|
for (;;) {
|
|
@@ -212,8 +218,6 @@ export class Engine {
|
|
|
212
218
|
cap = out;
|
|
213
219
|
}
|
|
214
220
|
}
|
|
215
|
-
/** Runs an `*_alloc` call that returns bytes through `(ptr, len)` out
|
|
216
|
-
* parameters and frees them after copying. */
|
|
217
221
|
allocated(call) {
|
|
218
222
|
return this.scratch(8, (out) => {
|
|
219
223
|
call(out, out + 4);
|
|
@@ -227,7 +231,6 @@ export class Engine {
|
|
|
227
231
|
}
|
|
228
232
|
});
|
|
229
233
|
}
|
|
230
|
-
/** The offset of a struct field, for nested reads. */
|
|
231
234
|
offsetOf(name, key) {
|
|
232
235
|
const field = this.struct(name).fields[key];
|
|
233
236
|
if (!field)
|
|
@@ -248,18 +251,22 @@ export class Engine {
|
|
|
248
251
|
return info?.kind === "enum" && member in info.values;
|
|
249
252
|
}
|
|
250
253
|
sizeOf(name) {
|
|
254
|
+
return this.type(name).size;
|
|
255
|
+
}
|
|
256
|
+
alignOf(name) {
|
|
257
|
+
return this.type(name).align;
|
|
258
|
+
}
|
|
259
|
+
type(name) {
|
|
251
260
|
const info = this.types[name];
|
|
252
261
|
if (!info)
|
|
253
262
|
throw new Error(`unknown type ${name}`);
|
|
254
|
-
return info
|
|
263
|
+
return info;
|
|
255
264
|
}
|
|
256
|
-
/** Reads a GhosttyString at `ptr` using the manifest's layout. */
|
|
257
265
|
readString(ptr) {
|
|
258
266
|
const data = this.field("GhosttyString", ptr, "ptr");
|
|
259
267
|
const len = this.field("GhosttyString", ptr, "len");
|
|
260
268
|
return new TextDecoder().decode(this.memory.subarray(data, data + len));
|
|
261
269
|
}
|
|
262
|
-
/** A `GhosttyColorRgb` at `ptr` as 0xRRGGBB. */
|
|
263
270
|
readRgb(ptr) {
|
|
264
271
|
const channel = (key) => this.field("GhosttyColorRgb", ptr, key);
|
|
265
272
|
return ((channel("r") << 16) | (channel("g") << 8) | channel("b")) >>> 0;
|
|
@@ -267,7 +274,6 @@ export class Engine {
|
|
|
267
274
|
terminalNew(cols, rows) {
|
|
268
275
|
return new Terminal(this, this.construct("ghostty_terminal_new", cols, rows));
|
|
269
276
|
}
|
|
270
|
-
/** Decodes a complete snapshot held in memory. */
|
|
271
277
|
decodeSnapshot(bytes) {
|
|
272
278
|
return this.withBytes(bytes, (src) => {
|
|
273
279
|
const decoder = this.construct("ghostty_snapshot_decoder_new_buf", src, bytes.length);
|
|
@@ -279,10 +285,6 @@ export class Engine {
|
|
|
279
285
|
}
|
|
280
286
|
});
|
|
281
287
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Paste text encoded for the PTY: unsafe bytes blanked, wrapped in
|
|
284
|
-
* bracketed paste when `bracketed`, newlines to carriage returns otherwise.
|
|
285
|
-
*/
|
|
286
288
|
encodePaste(text, bracketed) {
|
|
287
289
|
const data = new TextEncoder().encode(text);
|
|
288
290
|
if (data.length === 0)
|
|
@@ -290,7 +292,6 @@ export class Engine {
|
|
|
290
292
|
return this.withBytes(data, (src) => this.growing("ghostty_paste_encode", data.length + 16, (buf, cap, len) => this.call("ghostty_paste_encode", src, data.length, bracketed ? 1 : 0, buf, cap, len)));
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
|
-
/** `ghostty_terminal_new` with the given `GhosttyTerminal` handle wrapped. */
|
|
294
295
|
export class Terminal {
|
|
295
296
|
engine;
|
|
296
297
|
handle;
|
|
@@ -318,8 +319,6 @@ export class Terminal {
|
|
|
318
319
|
get scrollbackRows() {
|
|
319
320
|
return this.get("SCROLLBACK_ROWS", 4);
|
|
320
321
|
}
|
|
321
|
-
/** Whether the alternate screen (full-screen programs) is active; it
|
|
322
|
-
* has no history to scroll. */
|
|
323
322
|
get alternate() {
|
|
324
323
|
return this.get("ACTIVE_SCREEN", 4) === this.engine.enumValue("GhosttyTerminalScreen", "ALTERNATE");
|
|
325
324
|
}
|
|
@@ -331,9 +330,6 @@ export class Terminal {
|
|
|
331
330
|
return { total: u64("total"), offset: u64("offset"), len: u64("len") };
|
|
332
331
|
});
|
|
333
332
|
}
|
|
334
|
-
/** Moves the viewport `rows` rows (up when negative) through the
|
|
335
|
-
* history, or to its top or the live screen at its bottom. Output does
|
|
336
|
-
* not move a viewport scrolled into the history. */
|
|
337
333
|
scroll(to) {
|
|
338
334
|
const e = this.engine;
|
|
339
335
|
const size = e.sizeOf("GhosttyTerminalScrollViewport");
|
|
@@ -349,17 +345,10 @@ export class Terminal {
|
|
|
349
345
|
}
|
|
350
346
|
get title() {
|
|
351
347
|
const size = this.engine.sizeOf("GhosttyString");
|
|
352
|
-
return this.engine.scratch(size, (out) =>
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return "";
|
|
356
|
-
if (code !== this.engine.result.SUCCESS)
|
|
357
|
-
throw new EngineError("ghostty_terminal_get", code);
|
|
358
|
-
return this.engine.readString(out);
|
|
359
|
-
});
|
|
348
|
+
return this.engine.scratch(size, (out) => this.engine.present("ghostty_terminal_get", this.handle, this.engine.enumValue("GhosttyTerminalData", "TITLE"), out)
|
|
349
|
+
? this.engine.readString(out)
|
|
350
|
+
: "");
|
|
360
351
|
}
|
|
361
|
-
/** An untracked `GhosttyGridRef` to the viewport cell at `at`, valid
|
|
362
|
-
* until the terminal changes. */
|
|
363
352
|
gridRef(at) {
|
|
364
353
|
const e = this.engine;
|
|
365
354
|
const point = e.sizeOf("GhosttyPoint");
|
|
@@ -378,9 +367,6 @@ export class Terminal {
|
|
|
378
367
|
return e.memory.slice(ptr + point, ptr + point + ref);
|
|
379
368
|
});
|
|
380
369
|
}
|
|
381
|
-
/** Installs `selection` (a `GhosttySelection`) as the terminal's, which
|
|
382
|
-
* the terminal then tracks through output, scrolling and resizes, or
|
|
383
|
-
* clears it. */
|
|
384
370
|
select(selection) {
|
|
385
371
|
const option = this.engine.enumValue("GhosttyTerminalOption", "SELECTION");
|
|
386
372
|
if (!selection)
|
|
@@ -388,8 +374,6 @@ export class Terminal {
|
|
|
388
374
|
else
|
|
389
375
|
this.engine.withBytes(selection, (ptr) => this.engine.check("ghostty_terminal_set", this.handle, option, ptr));
|
|
390
376
|
}
|
|
391
|
-
/** The selection's text: soft-wrapped lines joined, trailing blanks
|
|
392
|
-
* trimmed, as Ghostty copies it; undefined with no selection. */
|
|
393
377
|
selectionText() {
|
|
394
378
|
const e = this.engine;
|
|
395
379
|
const options = e.pack("GhosttyTerminalSelectionFormatOptions", {
|
|
@@ -401,11 +385,8 @@ export class Terminal {
|
|
|
401
385
|
e.view.setUint32(out, 0, true);
|
|
402
386
|
e.view.setUint32(out + 4, 0, true);
|
|
403
387
|
// The options are passed by value, which the wasm ABI passes by address.
|
|
404
|
-
|
|
405
|
-
if (code === e.result.NO_VALUE)
|
|
388
|
+
if (!e.present("ghostty_terminal_selection_format_alloc", this.handle, 0, optionsPtr, out, out + 4))
|
|
406
389
|
return undefined;
|
|
407
|
-
if (code !== e.result.SUCCESS)
|
|
408
|
-
throw new EngineError("ghostty_terminal_selection_format_alloc", code);
|
|
409
390
|
const ptr = e.view.getUint32(out, true);
|
|
410
391
|
const len = e.view.getUint32(out + 4, true);
|
|
411
392
|
try {
|
|
@@ -416,21 +397,14 @@ export class Terminal {
|
|
|
416
397
|
}
|
|
417
398
|
}));
|
|
418
399
|
}
|
|
419
|
-
/** Whether the active screen has a selection. */
|
|
420
400
|
get selected() {
|
|
421
401
|
const e = this.engine;
|
|
422
402
|
const size = e.sizeOf("GhosttySelection");
|
|
423
403
|
return e.scratch(size, (out) => {
|
|
424
404
|
e.view.setUint32(out, size, true);
|
|
425
|
-
|
|
426
|
-
if (code === e.result.NO_VALUE)
|
|
427
|
-
return false;
|
|
428
|
-
if (code !== e.result.SUCCESS)
|
|
429
|
-
throw new EngineError("ghostty_terminal_get", code);
|
|
430
|
-
return true;
|
|
405
|
+
return e.present("ghostty_terminal_get", this.handle, e.enumValue("GhosttyTerminalData", "SELECTION"), out);
|
|
431
406
|
});
|
|
432
407
|
}
|
|
433
|
-
/** Whether DEC private mode `number` is set. */
|
|
434
408
|
mode(number) {
|
|
435
409
|
const config = this.engine.pack("GhosttyTerminalModeConfig", { mode: number });
|
|
436
410
|
return this.engine.withBytes(config, (ptr) => {
|
|
@@ -438,21 +412,17 @@ export class Terminal {
|
|
|
438
412
|
return this.engine.field("GhosttyTerminalModeConfig", ptr, "value") !== 0;
|
|
439
413
|
});
|
|
440
414
|
}
|
|
441
|
-
/** No cell size in pixels: `RESIZED` carries none. */
|
|
442
415
|
resize(cols, rows) {
|
|
443
416
|
this.engine.check("ghostty_terminal_resize", this.handle, cols, rows, 0, 0);
|
|
444
417
|
}
|
|
445
|
-
/** Sets a default colour (0xRRGGBB), as OSC 10, 11 and 12 report it. */
|
|
446
418
|
setColor(kind, color) {
|
|
447
419
|
const option = this.engine.enumValue("GhosttyTerminalOption", `COLOR_${kind.toUpperCase()}`);
|
|
448
420
|
const rgb = this.engine.pack("GhosttyColorRgb", { r: (color >> 16) & 0xff, g: (color >> 8) & 0xff, b: color & 0xff });
|
|
449
421
|
this.engine.withBytes(rgb, (ptr) => this.engine.check("ghostty_terminal_set", this.handle, option, ptr));
|
|
450
422
|
}
|
|
451
|
-
/** The whole terminal, history included, as a snapshot. */
|
|
452
423
|
snapshot() {
|
|
453
424
|
return this.engine.allocated((ptr, len) => this.engine.check("ghostty_snapshot_encode_alloc", this.handle, 0, ptr, len));
|
|
454
425
|
}
|
|
455
|
-
/** The active screen as plain text, one line per row. */
|
|
456
426
|
formatPlain() {
|
|
457
427
|
const options = this.engine.pack("GhosttyFormatterTerminalOptions", {
|
|
458
428
|
emit: this.engine.enumValue("GhosttyFormatterFormat", "PLAIN"),
|
package/dist/engine/keys.d.ts
CHANGED
|
@@ -19,21 +19,14 @@ export interface KeyInput {
|
|
|
19
19
|
* key: Option on macOS, AltGr elsewhere. The text is sent as typed. */
|
|
20
20
|
altComposed?: boolean;
|
|
21
21
|
}
|
|
22
|
-
/** `KeyboardEvent.code` as a `GhosttyKey` member name: `KeyA` → `A`, `Digit0` → `DIGIT_0`. */
|
|
23
22
|
export declare function keyName(code: string): string;
|
|
24
|
-
/** Whether `key` is text the key produces rather than a key name such as
|
|
25
|
-
* "Enter" or "ArrowUp" (which, per UI Events, is ASCII letters and digits
|
|
26
|
-
* starting with a capital, two or more of them; text of that shape is one
|
|
27
|
-
* character). */
|
|
28
23
|
export declare function isText(key: string): boolean;
|
|
29
|
-
/** Encodes browser key events with the engine, following the terminal's modes. */
|
|
30
24
|
export declare class KeyEncoder {
|
|
31
25
|
readonly engine: Engine;
|
|
32
26
|
private readonly encoder;
|
|
33
27
|
private readonly event;
|
|
34
28
|
private readonly unidentified;
|
|
35
29
|
constructor(engine: Engine);
|
|
36
|
-
/** The bytes to send for `input`, empty when the key encodes to nothing. */
|
|
37
30
|
encode(term: Terminal, input: KeyInput): Uint8Array;
|
|
38
31
|
free(): void;
|
|
39
32
|
}
|