@gjermundgaraba/clankermux 0.0.0-stage → 0.1.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/dist/client/attachment.d.ts +71 -0
- package/dist/client/attachment.js +240 -0
- package/dist/client/connection.d.ts +51 -0
- package/dist/client/connection.js +171 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +4 -0
- package/dist/client/keyboard.d.ts +24 -0
- package/dist/client/keyboard.js +32 -0
- package/dist/client/mount.d.ts +46 -0
- package/dist/client/mount.js +139 -0
- package/dist/client/osc52.d.ts +14 -0
- package/dist/client/osc52.js +88 -0
- package/dist/client/profile.d.ts +10 -0
- package/dist/client/profile.js +30 -0
- package/dist/client/worker.d.ts +59 -0
- package/dist/client/worker.js +449 -0
- package/dist/engine/decoder.d.ts +45 -0
- package/dist/engine/decoder.js +137 -0
- package/dist/engine/index.d.ts +110 -0
- package/dist/engine/index.js +372 -0
- package/dist/engine/keys.d.ts +39 -0
- package/dist/engine/keys.js +66 -0
- package/dist/engine/pin.d.ts +2 -0
- package/dist/engine/pin.js +3 -0
- package/dist/engine/render.d.ts +79 -0
- package/dist/engine/render.js +224 -0
- package/dist/proto/frame.d.ts +47 -0
- package/dist/proto/frame.js +78 -0
- package/dist/proto/index.d.ts +3 -0
- package/dist/proto/index.js +3 -0
- package/dist/proto/messages.d.ts +218 -0
- package/dist/proto/messages.js +1 -0
- package/dist/proto/stream.d.ts +11 -0
- package/dist/proto/stream.js +30 -0
- package/dist/renderer/index.d.ts +44 -0
- package/dist/renderer/index.js +138 -0
- package/ghostty-vt.wasm +0 -0
- package/package.json +48 -3
- package/README.md +0 -3
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/** Style flag bits of a [`Cell`]. */
|
|
2
|
+
export const FLAG = {
|
|
3
|
+
BOLD: 1,
|
|
4
|
+
ITALIC: 2,
|
|
5
|
+
FAINT: 4,
|
|
6
|
+
BLINK: 8,
|
|
7
|
+
INVERSE: 16,
|
|
8
|
+
INVISIBLE: 32,
|
|
9
|
+
STRIKETHROUGH: 64,
|
|
10
|
+
OVERLINE: 128,
|
|
11
|
+
/** The cell is the left half of a wide character. */
|
|
12
|
+
WIDE: 256,
|
|
13
|
+
/** The cell is the right half of a wide character; draw nothing. */
|
|
14
|
+
SPACER: 512,
|
|
15
|
+
};
|
|
16
|
+
/** No explicit colour; the renderer uses the default. */
|
|
17
|
+
export const NO_COLOR = -1;
|
|
18
|
+
/** `GhosttyRenderStateCursorVisualStyle` by name. */
|
|
19
|
+
const CURSOR_STYLES = ["bar", "block", "underline", "block_hollow"];
|
|
20
|
+
/**
|
|
21
|
+
* The engine's render state: updated from a terminal, read into a
|
|
22
|
+
* [`Frame`] of the rows that changed, then cleaned.
|
|
23
|
+
*/
|
|
24
|
+
export class RenderState {
|
|
25
|
+
engine;
|
|
26
|
+
state;
|
|
27
|
+
iterator;
|
|
28
|
+
cells;
|
|
29
|
+
keys;
|
|
30
|
+
tags;
|
|
31
|
+
wide;
|
|
32
|
+
/** `GhosttyCell` bit fields, from the manifest. */
|
|
33
|
+
cell;
|
|
34
|
+
cursorStyles;
|
|
35
|
+
constructor(engine) {
|
|
36
|
+
this.engine = engine;
|
|
37
|
+
this.state = engine.construct("ghostty_render_state_new");
|
|
38
|
+
this.iterator = engine.construct("ghostty_render_state_row_iterator_new");
|
|
39
|
+
this.cells = engine.construct("ghostty_render_state_row_cells_new");
|
|
40
|
+
const values = (name, members) => Object.fromEntries(members.map((m) => [m, engine.enumValue(name, m)]));
|
|
41
|
+
this.keys = {
|
|
42
|
+
data: values("GhosttyRenderStateData", ["COLS", "ROWS", "DIRTY", "ROW_ITERATOR", "COLORS", "CURSOR"]),
|
|
43
|
+
row: values("GhosttyRenderStateRowData", ["CELLS"]),
|
|
44
|
+
cell: values("GhosttyRenderStateRowCellsData", [
|
|
45
|
+
"RAW",
|
|
46
|
+
"STYLE",
|
|
47
|
+
"BG_COLOR",
|
|
48
|
+
"FG_COLOR",
|
|
49
|
+
"HAS_STYLING",
|
|
50
|
+
"GRAPHEMES_UTF8",
|
|
51
|
+
]),
|
|
52
|
+
};
|
|
53
|
+
this.tags = {
|
|
54
|
+
codepoint: engine.enumValue("GhosttyCellContentTag", "CODEPOINT"),
|
|
55
|
+
grapheme: engine.enumValue("GhosttyCellContentTag", "CODEPOINT_GRAPHEME"),
|
|
56
|
+
};
|
|
57
|
+
this.wide = {
|
|
58
|
+
wide: engine.enumValue("GhosttyCellWide", "WIDE"),
|
|
59
|
+
tail: engine.enumValue("GhosttyCellWide", "SPACER_TAIL"),
|
|
60
|
+
};
|
|
61
|
+
this.cell = {
|
|
62
|
+
tag: engine.bits("GhosttyCell", "content_tag"),
|
|
63
|
+
codepoint: engine.bits("GhosttyCell", "content", "CODEPOINT", "codepoint"),
|
|
64
|
+
wide: engine.bits("GhosttyCell", "wide"),
|
|
65
|
+
};
|
|
66
|
+
this.cursorStyles = new Map(CURSOR_STYLES.map((style) => [engine.enumValue("GhosttyRenderStateCursorVisualStyle", style.toUpperCase()), style]));
|
|
67
|
+
}
|
|
68
|
+
/** Captures the terminal and returns the rows that changed since the last `clean`. */
|
|
69
|
+
update(term) {
|
|
70
|
+
const e = this.engine;
|
|
71
|
+
e.check("ghostty_render_state_update", this.state, term.handle);
|
|
72
|
+
const u16 = (key) => e.scratch(4, (out) => {
|
|
73
|
+
e.check("ghostty_render_state_get", this.state, key, out);
|
|
74
|
+
return e.view.getUint16(out, true);
|
|
75
|
+
});
|
|
76
|
+
const cols = u16(this.keys.data["COLS"]);
|
|
77
|
+
const rows = u16(this.keys.data["ROWS"]);
|
|
78
|
+
const dirty = e.scratch(4, (out) => {
|
|
79
|
+
e.check("ghostty_render_state_get", this.state, this.keys.data["DIRTY"], out);
|
|
80
|
+
return e.view.getInt32(out, true);
|
|
81
|
+
});
|
|
82
|
+
const full = dirty === e.enumValue("GhosttyRenderStateDirty", "FULL");
|
|
83
|
+
const { background, foreground, cursorColor } = e.withBytes(e.pack("GhosttyRenderStateColors", {}), (colors) => {
|
|
84
|
+
e.check("ghostty_render_state_get", this.state, this.keys.data["COLORS"], colors);
|
|
85
|
+
const rgb = (key) => e.readRgb(colors + e.offsetOf("GhosttyRenderStateColors", key));
|
|
86
|
+
return {
|
|
87
|
+
background: rgb("background"),
|
|
88
|
+
foreground: rgb("foreground"),
|
|
89
|
+
cursorColor: e.field("GhosttyRenderStateColors", colors, "cursor_has_value") ? rgb("cursor") : NO_COLOR,
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
const cursor = e.withBytes(e.pack("GhosttyRenderStateCursor", {}), (ptr) => {
|
|
93
|
+
e.check("ghostty_render_state_get", this.state, this.keys.data["CURSOR"], ptr);
|
|
94
|
+
const f = (key) => e.field("GhosttyRenderStateCursor", ptr, key);
|
|
95
|
+
return f("viewport_has_value")
|
|
96
|
+
? {
|
|
97
|
+
x: f("viewport_x"),
|
|
98
|
+
y: f("viewport_y"),
|
|
99
|
+
visible: f("visible") !== 0,
|
|
100
|
+
blinking: f("blinking") !== 0,
|
|
101
|
+
style: this.cursorStyles.get(f("visual_style")) ?? "block",
|
|
102
|
+
color: cursorColor,
|
|
103
|
+
}
|
|
104
|
+
: undefined;
|
|
105
|
+
});
|
|
106
|
+
const lines = [];
|
|
107
|
+
// Iterator and cells containers are passed by address of their handle.
|
|
108
|
+
e.scratch(8, (out) => {
|
|
109
|
+
e.view.setUint32(out, this.iterator, true);
|
|
110
|
+
e.check("ghostty_render_state_get", this.state, this.keys.data["ROW_ITERATOR"], out);
|
|
111
|
+
while (e.call("ghostty_render_state_row_iterator_next_dirty", this.iterator, out + 4)) {
|
|
112
|
+
const y = e.view.getUint16(out + 4, true);
|
|
113
|
+
lines.push({ y, cells: this.readRow(cols) });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return { cols, rows, full, background, foreground, cursor, lines };
|
|
117
|
+
}
|
|
118
|
+
readRow(cols) {
|
|
119
|
+
const e = this.engine;
|
|
120
|
+
e.scratch(4, (out) => {
|
|
121
|
+
e.view.setUint32(out, this.cells, true);
|
|
122
|
+
e.check("ghostty_render_state_row_get", this.iterator, this.keys.row["CELLS"], out);
|
|
123
|
+
});
|
|
124
|
+
const styleSize = e.sizeOf("GhosttyStyle");
|
|
125
|
+
const cells = [];
|
|
126
|
+
// Scratch: raw cell (8), colour (3, padded to 8), the 8-aligned style,
|
|
127
|
+
// a UTF-8 buffer struct and its bytes.
|
|
128
|
+
const utf8Cap = 64;
|
|
129
|
+
e.scratch(16 + styleSize + e.sizeOf("GhosttyBuffer") + utf8Cap, (scratch) => {
|
|
130
|
+
const raw = scratch;
|
|
131
|
+
const color = scratch + 8;
|
|
132
|
+
const style = scratch + 16;
|
|
133
|
+
const buffer = style + styleSize;
|
|
134
|
+
const utf8 = buffer + e.sizeOf("GhosttyBuffer");
|
|
135
|
+
while (e.call("ghostty_render_state_row_cells_next", this.cells) && cells.length < cols) {
|
|
136
|
+
e.check("ghostty_render_state_row_cells_get", this.cells, this.keys.cell["RAW"], raw);
|
|
137
|
+
const tag = e.readBits(raw, this.cell.tag);
|
|
138
|
+
const wide = e.readBits(raw, this.cell.wide);
|
|
139
|
+
let text = "";
|
|
140
|
+
if (tag === this.tags.codepoint) {
|
|
141
|
+
const cp = e.readBits(raw, this.cell.codepoint);
|
|
142
|
+
if (cp !== 0)
|
|
143
|
+
text = String.fromCodePoint(cp);
|
|
144
|
+
}
|
|
145
|
+
else if (tag === this.tags.grapheme) {
|
|
146
|
+
text = this.graphemes(buffer, utf8, utf8Cap);
|
|
147
|
+
}
|
|
148
|
+
let flags = 0;
|
|
149
|
+
let underline = 0;
|
|
150
|
+
if (wide === this.wide.wide)
|
|
151
|
+
flags |= FLAG.WIDE;
|
|
152
|
+
if (wide === this.wide.tail)
|
|
153
|
+
flags |= FLAG.SPACER;
|
|
154
|
+
const fg = this.color(this.keys.cell["FG_COLOR"], color);
|
|
155
|
+
const bg = this.color(this.keys.cell["BG_COLOR"], color);
|
|
156
|
+
e.check("ghostty_render_state_row_cells_get", this.cells, this.keys.cell["HAS_STYLING"], raw);
|
|
157
|
+
if (e.memory[raw]) {
|
|
158
|
+
e.view.setUint32(style, styleSize, true);
|
|
159
|
+
e.check("ghostty_render_state_row_cells_get", this.cells, this.keys.cell["STYLE"], style);
|
|
160
|
+
const f = (key) => e.field("GhosttyStyle", style, key) !== 0;
|
|
161
|
+
if (f("bold"))
|
|
162
|
+
flags |= FLAG.BOLD;
|
|
163
|
+
if (f("italic"))
|
|
164
|
+
flags |= FLAG.ITALIC;
|
|
165
|
+
if (f("faint"))
|
|
166
|
+
flags |= FLAG.FAINT;
|
|
167
|
+
if (f("blink"))
|
|
168
|
+
flags |= FLAG.BLINK;
|
|
169
|
+
if (f("inverse"))
|
|
170
|
+
flags |= FLAG.INVERSE;
|
|
171
|
+
if (f("invisible"))
|
|
172
|
+
flags |= FLAG.INVISIBLE;
|
|
173
|
+
if (f("strikethrough"))
|
|
174
|
+
flags |= FLAG.STRIKETHROUGH;
|
|
175
|
+
if (f("overline"))
|
|
176
|
+
flags |= FLAG.OVERLINE;
|
|
177
|
+
underline = e.field("GhosttyStyle", style, "underline");
|
|
178
|
+
}
|
|
179
|
+
cells.push({ text, fg, bg, flags, underline });
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return cells;
|
|
183
|
+
}
|
|
184
|
+
color(key, out) {
|
|
185
|
+
const e = this.engine;
|
|
186
|
+
const code = e.call("ghostty_render_state_row_cells_get", this.cells, key, out);
|
|
187
|
+
if (code === e.result.INVALID_VALUE)
|
|
188
|
+
return NO_COLOR;
|
|
189
|
+
if (code !== e.result.SUCCESS)
|
|
190
|
+
throw new Error(`cell colour: ${code}`);
|
|
191
|
+
return e.readRgb(out);
|
|
192
|
+
}
|
|
193
|
+
graphemes(buffer, utf8, cap) {
|
|
194
|
+
const e = this.engine;
|
|
195
|
+
e.view.setUint32(buffer + e.offsetOf("GhosttyBuffer", "ptr"), utf8, true);
|
|
196
|
+
e.view.setUint32(buffer + e.offsetOf("GhosttyBuffer", "cap"), cap, true);
|
|
197
|
+
e.view.setUint32(buffer + e.offsetOf("GhosttyBuffer", "len"), 0, true);
|
|
198
|
+
const code = e.call("ghostty_render_state_row_cells_get", this.cells, this.keys.cell["GRAPHEMES_UTF8"], buffer);
|
|
199
|
+
if (code === e.result.SUCCESS) {
|
|
200
|
+
const len = e.field("GhosttyBuffer", buffer, "len");
|
|
201
|
+
return new TextDecoder().decode(e.memory.slice(utf8, utf8 + len));
|
|
202
|
+
}
|
|
203
|
+
if (code !== e.result.OUT_OF_SPACE)
|
|
204
|
+
throw new Error(`cell graphemes: ${code}`);
|
|
205
|
+
// The buffer struct reports the needed length; retry through it.
|
|
206
|
+
const needed = e.field("GhosttyBuffer", buffer, "len");
|
|
207
|
+
return new TextDecoder().decode(e.growing("ghostty_render_state_row_cells_get", needed, (big, bigCap, len) => {
|
|
208
|
+
e.view.setUint32(buffer + e.offsetOf("GhosttyBuffer", "ptr"), big, true);
|
|
209
|
+
e.view.setUint32(buffer + e.offsetOf("GhosttyBuffer", "cap"), bigCap, true);
|
|
210
|
+
const again = e.call("ghostty_render_state_row_cells_get", this.cells, this.keys.cell["GRAPHEMES_UTF8"], buffer);
|
|
211
|
+
e.view.setUint32(len, e.field("GhosttyBuffer", buffer, "len"), true);
|
|
212
|
+
return again;
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
/** Marks the frame as drawn. */
|
|
216
|
+
clean() {
|
|
217
|
+
this.engine.check("ghostty_render_state_clean", this.state);
|
|
218
|
+
}
|
|
219
|
+
free() {
|
|
220
|
+
this.engine.call("ghostty_render_state_row_cells_free", this.cells);
|
|
221
|
+
this.engine.call("ghostty_render_state_row_iterator_free", this.iterator);
|
|
222
|
+
this.engine.call("ghostty_render_state_free", this.state);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const HEADER_LEN = 10;
|
|
2
|
+
export declare const FrameType: {
|
|
3
|
+
readonly Hello: 1;
|
|
4
|
+
readonly Request: 2;
|
|
5
|
+
readonly Open: 16;
|
|
6
|
+
readonly Input: 17;
|
|
7
|
+
readonly Viewport: 18;
|
|
8
|
+
readonly Close: 19;
|
|
9
|
+
readonly Welcome: 129;
|
|
10
|
+
readonly Reply: 130;
|
|
11
|
+
readonly Event: 131;
|
|
12
|
+
readonly Error: 143;
|
|
13
|
+
readonly Attached: 144;
|
|
14
|
+
readonly Snapshot: 145;
|
|
15
|
+
readonly SnapshotReady: 146;
|
|
16
|
+
readonly SnapshotEnd: 147;
|
|
17
|
+
readonly Output: 148;
|
|
18
|
+
readonly Resized: 149;
|
|
19
|
+
readonly Exited: 150;
|
|
20
|
+
readonly Gap: 151;
|
|
21
|
+
readonly Closed: 153;
|
|
22
|
+
};
|
|
23
|
+
export type FrameType = (typeof FrameType)[keyof typeof FrameType];
|
|
24
|
+
export interface Header {
|
|
25
|
+
type: FrameType;
|
|
26
|
+
channel: number;
|
|
27
|
+
length: number;
|
|
28
|
+
}
|
|
29
|
+
export type FrameErrorKind = "unknown_type" | "too_long" | "short" | "length_mismatch";
|
|
30
|
+
export declare class FrameError extends Error {
|
|
31
|
+
readonly kind: FrameErrorKind;
|
|
32
|
+
constructor(kind: FrameErrorKind, message: string);
|
|
33
|
+
}
|
|
34
|
+
/** Parses a header, ignoring `flags`. */
|
|
35
|
+
export declare function parseHeader(bytes: Uint8Array, maxFrame: number): Header;
|
|
36
|
+
export declare function encodeFrame(type: FrameType, channel: number, payload: Uint8Array): Uint8Array;
|
|
37
|
+
export interface Frame {
|
|
38
|
+
header: Header;
|
|
39
|
+
payload: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
/** Parses one message that carries exactly one frame. */
|
|
42
|
+
export declare function parseFrame(message: Uint8Array, maxFrame: number): Frame;
|
|
43
|
+
/** `OUTPUT` payload: the stream offset of the first byte (u64 LE), then the bytes. */
|
|
44
|
+
export declare function parseOutput(payload: Uint8Array): {
|
|
45
|
+
offset: number;
|
|
46
|
+
bytes: Uint8Array;
|
|
47
|
+
} | undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const HEADER_LEN = 10;
|
|
2
|
+
export const FrameType = {
|
|
3
|
+
Hello: 0x01,
|
|
4
|
+
Request: 0x02,
|
|
5
|
+
Open: 0x10,
|
|
6
|
+
Input: 0x11,
|
|
7
|
+
Viewport: 0x12,
|
|
8
|
+
Close: 0x13,
|
|
9
|
+
Welcome: 0x81,
|
|
10
|
+
Reply: 0x82,
|
|
11
|
+
Event: 0x83,
|
|
12
|
+
Error: 0x8f,
|
|
13
|
+
Attached: 0x90,
|
|
14
|
+
Snapshot: 0x91,
|
|
15
|
+
SnapshotReady: 0x92,
|
|
16
|
+
SnapshotEnd: 0x93,
|
|
17
|
+
Output: 0x94,
|
|
18
|
+
Resized: 0x95,
|
|
19
|
+
Exited: 0x96,
|
|
20
|
+
Gap: 0x97,
|
|
21
|
+
Closed: 0x99,
|
|
22
|
+
};
|
|
23
|
+
const KNOWN_TYPES = new Set(Object.values(FrameType));
|
|
24
|
+
function isFrameType(byte) {
|
|
25
|
+
return KNOWN_TYPES.has(byte);
|
|
26
|
+
}
|
|
27
|
+
export class FrameError extends Error {
|
|
28
|
+
kind;
|
|
29
|
+
// Erasable syntax only: node runs this package's sources with type
|
|
30
|
+
// stripping (the headless driver).
|
|
31
|
+
constructor(kind, message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.kind = kind;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Parses a header, ignoring `flags`. */
|
|
37
|
+
export function parseHeader(bytes, maxFrame) {
|
|
38
|
+
if (bytes.length < HEADER_LEN)
|
|
39
|
+
throw new FrameError("short", "message shorter than a frame header");
|
|
40
|
+
const type = bytes[0];
|
|
41
|
+
if (!isFrameType(type)) {
|
|
42
|
+
throw new FrameError("unknown_type", `unknown frame type 0x${type.toString(16).padStart(2, "0")}`);
|
|
43
|
+
}
|
|
44
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, HEADER_LEN);
|
|
45
|
+
const channel = view.getUint32(2, true);
|
|
46
|
+
const length = view.getUint32(6, true);
|
|
47
|
+
if (length > maxFrame)
|
|
48
|
+
throw new FrameError("too_long", `frame length ${length} exceeds max_frame ${maxFrame}`);
|
|
49
|
+
return { type, channel, length };
|
|
50
|
+
}
|
|
51
|
+
export function encodeFrame(type, channel, payload) {
|
|
52
|
+
const out = new Uint8Array(HEADER_LEN + payload.length);
|
|
53
|
+
const view = new DataView(out.buffer);
|
|
54
|
+
out[0] = type;
|
|
55
|
+
view.setUint32(2, channel, true);
|
|
56
|
+
view.setUint32(6, payload.length, true);
|
|
57
|
+
out.set(payload, HEADER_LEN);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/** Parses one message that carries exactly one frame. */
|
|
61
|
+
export function parseFrame(message, maxFrame) {
|
|
62
|
+
const header = parseHeader(message, maxFrame);
|
|
63
|
+
const payload = message.subarray(HEADER_LEN);
|
|
64
|
+
if (header.length !== payload.length) {
|
|
65
|
+
throw new FrameError("length_mismatch", `frame length ${header.length} with ${payload.length} payload bytes`);
|
|
66
|
+
}
|
|
67
|
+
return { header, payload };
|
|
68
|
+
}
|
|
69
|
+
/** `OUTPUT` payload: the stream offset of the first byte (u64 LE), then the bytes. */
|
|
70
|
+
export function parseOutput(payload) {
|
|
71
|
+
if (payload.length < 8)
|
|
72
|
+
return undefined;
|
|
73
|
+
const view = new DataView(payload.buffer, payload.byteOffset, 8);
|
|
74
|
+
const offset = view.getUint32(4, true) * 2 ** 32 + view.getUint32(0, true);
|
|
75
|
+
if (!Number.isSafeInteger(offset))
|
|
76
|
+
return undefined;
|
|
77
|
+
return { offset, bytes: payload.subarray(8) };
|
|
78
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
export declare const VERSION = 1;
|
|
2
|
+
export interface Peer {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Hello {
|
|
7
|
+
version: number;
|
|
8
|
+
client: Peer;
|
|
9
|
+
engine?: string;
|
|
10
|
+
capabilities: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface Limits {
|
|
13
|
+
max_frame: number;
|
|
14
|
+
control_body: number;
|
|
15
|
+
ring: number;
|
|
16
|
+
input_queue: number;
|
|
17
|
+
scrollback: number;
|
|
18
|
+
continuation: number;
|
|
19
|
+
label: number;
|
|
20
|
+
text: number;
|
|
21
|
+
markers: number;
|
|
22
|
+
records: number;
|
|
23
|
+
page: number;
|
|
24
|
+
hello_timeout: number;
|
|
25
|
+
remove_grace: number;
|
|
26
|
+
}
|
|
27
|
+
export interface Welcome {
|
|
28
|
+
version: number;
|
|
29
|
+
server: Peer;
|
|
30
|
+
engine: string;
|
|
31
|
+
incarnation: string;
|
|
32
|
+
capabilities: string[];
|
|
33
|
+
limits: Limits;
|
|
34
|
+
}
|
|
35
|
+
export interface Request {
|
|
36
|
+
id: number;
|
|
37
|
+
method: string;
|
|
38
|
+
params: unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface Reply {
|
|
41
|
+
id: number;
|
|
42
|
+
result: unknown;
|
|
43
|
+
}
|
|
44
|
+
export type ErrorCode = "protocol_error" | "version_mismatch" | "invalid_request" | "limit_exceeded" | "no_such_session" | "not_running" | "running" | "signal_failed" | "engine_mismatch" | "channel_in_use" | "read_only" | "input_overflow" | "too_slow" | "internal";
|
|
45
|
+
export interface ErrorMessage {
|
|
46
|
+
id?: number;
|
|
47
|
+
code: ErrorCode;
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
50
|
+
export type OnExit = "remove" | "keep";
|
|
51
|
+
export type Status = "running" | "exited" | "restored";
|
|
52
|
+
export type Exit = {
|
|
53
|
+
code: number;
|
|
54
|
+
} | {
|
|
55
|
+
signal: string;
|
|
56
|
+
};
|
|
57
|
+
/** One program status record (OSC 7501). */
|
|
58
|
+
export interface StatusRecord {
|
|
59
|
+
id: string;
|
|
60
|
+
state: string;
|
|
61
|
+
kind?: string;
|
|
62
|
+
app?: string;
|
|
63
|
+
title?: string;
|
|
64
|
+
msg?: string;
|
|
65
|
+
progress?: number;
|
|
66
|
+
updated_at: string;
|
|
67
|
+
}
|
|
68
|
+
export interface Session {
|
|
69
|
+
id: string;
|
|
70
|
+
label: string;
|
|
71
|
+
status: Status;
|
|
72
|
+
argv: string[];
|
|
73
|
+
cwd: string;
|
|
74
|
+
pid?: number;
|
|
75
|
+
cols: number;
|
|
76
|
+
rows: number;
|
|
77
|
+
title: string;
|
|
78
|
+
pwd: string;
|
|
79
|
+
on_exit: OnExit;
|
|
80
|
+
created_at: string;
|
|
81
|
+
exited_at?: string;
|
|
82
|
+
exit?: Exit;
|
|
83
|
+
offset: number;
|
|
84
|
+
marker: number;
|
|
85
|
+
attachments: number;
|
|
86
|
+
program_status?: StatusRecord[];
|
|
87
|
+
}
|
|
88
|
+
export interface Page {
|
|
89
|
+
sessions: Session[];
|
|
90
|
+
next?: string;
|
|
91
|
+
}
|
|
92
|
+
export interface Read {
|
|
93
|
+
text: string;
|
|
94
|
+
cols: number;
|
|
95
|
+
rows: number;
|
|
96
|
+
cursor?: {
|
|
97
|
+
x: number;
|
|
98
|
+
y: number;
|
|
99
|
+
};
|
|
100
|
+
offset: number;
|
|
101
|
+
status: Status;
|
|
102
|
+
}
|
|
103
|
+
export interface ListParams {
|
|
104
|
+
after?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface SessionParams {
|
|
107
|
+
session: string;
|
|
108
|
+
}
|
|
109
|
+
export interface SignalParams {
|
|
110
|
+
session: string;
|
|
111
|
+
signal: string;
|
|
112
|
+
}
|
|
113
|
+
export interface SetLabelParams {
|
|
114
|
+
session: string;
|
|
115
|
+
label: string;
|
|
116
|
+
}
|
|
117
|
+
export interface SetSizeParams {
|
|
118
|
+
session: string;
|
|
119
|
+
cols: number;
|
|
120
|
+
rows: number;
|
|
121
|
+
}
|
|
122
|
+
export interface ReadParams {
|
|
123
|
+
session: string;
|
|
124
|
+
scrollback?: number;
|
|
125
|
+
}
|
|
126
|
+
export interface WriteParams {
|
|
127
|
+
session: string;
|
|
128
|
+
/** Base64. */
|
|
129
|
+
data: string;
|
|
130
|
+
}
|
|
131
|
+
export interface CreateParams {
|
|
132
|
+
label?: string;
|
|
133
|
+
argv?: string[];
|
|
134
|
+
cwd?: string;
|
|
135
|
+
env?: Record<string, string>;
|
|
136
|
+
cols?: number;
|
|
137
|
+
rows?: number;
|
|
138
|
+
on_exit?: OnExit;
|
|
139
|
+
}
|
|
140
|
+
export type Event = {
|
|
141
|
+
event: "session_created";
|
|
142
|
+
session: Session;
|
|
143
|
+
} | {
|
|
144
|
+
event: "session_changed";
|
|
145
|
+
session: Session;
|
|
146
|
+
} | {
|
|
147
|
+
event: "session_exited";
|
|
148
|
+
session: Session;
|
|
149
|
+
} | {
|
|
150
|
+
event: "session_removed";
|
|
151
|
+
id: string;
|
|
152
|
+
} | {
|
|
153
|
+
event: "program_status_changed";
|
|
154
|
+
id: string;
|
|
155
|
+
record: StatusRecord;
|
|
156
|
+
} | {
|
|
157
|
+
event: "program_status_removed";
|
|
158
|
+
id: string;
|
|
159
|
+
record_ids: string[];
|
|
160
|
+
};
|
|
161
|
+
export type Scheme = "light" | "dark";
|
|
162
|
+
export interface Profile {
|
|
163
|
+
fg?: string;
|
|
164
|
+
bg?: string;
|
|
165
|
+
cursor?: string;
|
|
166
|
+
scheme?: Scheme;
|
|
167
|
+
}
|
|
168
|
+
/** `OPEN.viewport`: the terminal size in cells and, optionally, pixels. */
|
|
169
|
+
export interface Size {
|
|
170
|
+
cols: number;
|
|
171
|
+
rows: number;
|
|
172
|
+
cell_width?: number;
|
|
173
|
+
cell_height?: number;
|
|
174
|
+
}
|
|
175
|
+
/** The `VIEWPORT` payload. */
|
|
176
|
+
export interface Viewport extends Size {
|
|
177
|
+
profile?: Profile;
|
|
178
|
+
}
|
|
179
|
+
export interface Resume {
|
|
180
|
+
incarnation: string;
|
|
181
|
+
offset: number;
|
|
182
|
+
marker: number;
|
|
183
|
+
}
|
|
184
|
+
export interface Open {
|
|
185
|
+
session: string;
|
|
186
|
+
read_only?: boolean;
|
|
187
|
+
viewport?: Size;
|
|
188
|
+
profile?: Profile;
|
|
189
|
+
resume?: Resume;
|
|
190
|
+
}
|
|
191
|
+
export interface Attached {
|
|
192
|
+
mode: "snapshot" | "resume";
|
|
193
|
+
offset: number;
|
|
194
|
+
marker: number;
|
|
195
|
+
cols: number;
|
|
196
|
+
rows: number;
|
|
197
|
+
session: Session;
|
|
198
|
+
/** Total length of the snapshot that follows, in mode `snapshot`. */
|
|
199
|
+
snapshot_bytes?: number;
|
|
200
|
+
}
|
|
201
|
+
export interface Resized {
|
|
202
|
+
seq: number;
|
|
203
|
+
offset: number;
|
|
204
|
+
cols: number;
|
|
205
|
+
rows: number;
|
|
206
|
+
}
|
|
207
|
+
export interface Exited {
|
|
208
|
+
seq: number;
|
|
209
|
+
offset: number;
|
|
210
|
+
exit: Exit;
|
|
211
|
+
}
|
|
212
|
+
export interface Gap {
|
|
213
|
+
from: number;
|
|
214
|
+
to: number;
|
|
215
|
+
}
|
|
216
|
+
export interface Closed {
|
|
217
|
+
reason: "closed" | "removed" | "stopping";
|
|
218
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = 1;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits an ordered byte stream into frames, for carriers that are not
|
|
3
|
+
* message-oriented (a Unix or TCP socket). One call to `feed` per chunk;
|
|
4
|
+
* each complete frame comes back as its own bytes, header included.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StreamFramer {
|
|
7
|
+
private buffer;
|
|
8
|
+
private readonly maxFrame;
|
|
9
|
+
constructor(maxFrame: number);
|
|
10
|
+
feed(chunk: Uint8Array): Uint8Array[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HEADER_LEN, parseHeader } from "./frame.js";
|
|
2
|
+
/**
|
|
3
|
+
* Splits an ordered byte stream into frames, for carriers that are not
|
|
4
|
+
* message-oriented (a Unix or TCP socket). One call to `feed` per chunk;
|
|
5
|
+
* each complete frame comes back as its own bytes, header included.
|
|
6
|
+
*/
|
|
7
|
+
export class StreamFramer {
|
|
8
|
+
buffer = new Uint8Array(0);
|
|
9
|
+
maxFrame;
|
|
10
|
+
constructor(maxFrame) {
|
|
11
|
+
this.maxFrame = maxFrame;
|
|
12
|
+
}
|
|
13
|
+
feed(chunk) {
|
|
14
|
+
const joined = new Uint8Array(this.buffer.length + chunk.length);
|
|
15
|
+
joined.set(this.buffer);
|
|
16
|
+
joined.set(chunk, this.buffer.length);
|
|
17
|
+
const frames = [];
|
|
18
|
+
let pos = 0;
|
|
19
|
+
while (joined.length - pos >= HEADER_LEN) {
|
|
20
|
+
const header = parseHeader(joined.subarray(pos), this.maxFrame);
|
|
21
|
+
const end = pos + HEADER_LEN + header.length;
|
|
22
|
+
if (end > joined.length)
|
|
23
|
+
break;
|
|
24
|
+
frames.push(joined.slice(pos, end));
|
|
25
|
+
pos = end;
|
|
26
|
+
}
|
|
27
|
+
this.buffer = joined.slice(pos);
|
|
28
|
+
return frames;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Frame } from "../engine/index.ts";
|
|
2
|
+
/** The cell grid in CSS pixels and the fonts to draw with. */
|
|
3
|
+
export interface Metrics {
|
|
4
|
+
cellWidth: number;
|
|
5
|
+
cellHeight: number;
|
|
6
|
+
/** Distance from the top of a cell to the text baseline. */
|
|
7
|
+
baseline: number;
|
|
8
|
+
font: string;
|
|
9
|
+
boldFont: string;
|
|
10
|
+
italicFont: string;
|
|
11
|
+
boldItalicFont: string;
|
|
12
|
+
}
|
|
13
|
+
/** CSS colours used where the frame has none: only the cursor, since the
|
|
14
|
+
* frame always carries default foreground and background colours. */
|
|
15
|
+
export interface Palette {
|
|
16
|
+
cursor: string;
|
|
17
|
+
}
|
|
18
|
+
/** The part of `CanvasRenderingContext2D` the renderer uses. */
|
|
19
|
+
export interface Context2D {
|
|
20
|
+
fillStyle: string | CanvasGradient | CanvasPattern;
|
|
21
|
+
font: string;
|
|
22
|
+
globalAlpha: number;
|
|
23
|
+
fillRect(x: number, y: number, w: number, h: number): void;
|
|
24
|
+
fillText(text: string, x: number, y: number): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Draws frames onto a 2D context: changed rows only, then the cursor.
|
|
28
|
+
* Rows are cached so the row the cursor leaves can be redrawn.
|
|
29
|
+
*/
|
|
30
|
+
export declare class CanvasRenderer {
|
|
31
|
+
private readonly ctx;
|
|
32
|
+
private readonly metrics;
|
|
33
|
+
private readonly palette;
|
|
34
|
+
private rows;
|
|
35
|
+
private cursorRow;
|
|
36
|
+
private cols;
|
|
37
|
+
private background;
|
|
38
|
+
private foreground;
|
|
39
|
+
constructor(ctx: Context2D, metrics: Metrics, palette: Palette);
|
|
40
|
+
draw(frame: Frame): void;
|
|
41
|
+
private drawRow;
|
|
42
|
+
private font;
|
|
43
|
+
private drawCursor;
|
|
44
|
+
}
|