@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/keys.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const MODS = { SHIFT: 1 << 0, CTRL: 1 << 1, ALT: 1 << 2, SUPER: 1 << 3 };
|
|
2
|
-
/** `KeyboardEvent.code` as a `GhosttyKey` member name: `KeyA` → `A`, `Digit0` → `DIGIT_0`. */
|
|
3
2
|
export function keyName(code) {
|
|
4
3
|
if (/^F\d+$/.test(code))
|
|
5
4
|
return code;
|
|
@@ -9,10 +8,6 @@ export function keyName(code) {
|
|
|
9
8
|
.replace(/([0-9])([A-Z])/g, "$1_$2")
|
|
10
9
|
.toUpperCase();
|
|
11
10
|
}
|
|
12
|
-
/** Whether `key` is text the key produces rather than a key name such as
|
|
13
|
-
* "Enter" or "ArrowUp" (which, per UI Events, is ASCII letters and digits
|
|
14
|
-
* starting with a capital, two or more of them; text of that shape is one
|
|
15
|
-
* character). */
|
|
16
11
|
export function isText(key) {
|
|
17
12
|
if (key.length === 0)
|
|
18
13
|
return false;
|
|
@@ -21,7 +16,14 @@ export function isText(key) {
|
|
|
21
16
|
return false;
|
|
22
17
|
return key.length === 1 || !/^[A-Z][A-Za-z0-9]+$/.test(key);
|
|
23
18
|
}
|
|
24
|
-
|
|
19
|
+
function shiftProducedText(input, text) {
|
|
20
|
+
if (!input.shift || text === "")
|
|
21
|
+
return false;
|
|
22
|
+
const layoutUnknown = input.unshifted === undefined;
|
|
23
|
+
if (layoutUnknown)
|
|
24
|
+
return text !== " ";
|
|
25
|
+
return text !== input.unshifted;
|
|
26
|
+
}
|
|
25
27
|
export class KeyEncoder {
|
|
26
28
|
engine;
|
|
27
29
|
encoder;
|
|
@@ -33,13 +35,11 @@ export class KeyEncoder {
|
|
|
33
35
|
this.event = engine.construct("ghostty_key_event_new");
|
|
34
36
|
this.unidentified = engine.enumValue("GhosttyKey", "UNIDENTIFIED");
|
|
35
37
|
}
|
|
36
|
-
/** The bytes to send for `input`, empty when the key encodes to nothing. */
|
|
37
38
|
encode(term, input) {
|
|
38
39
|
const e = this.engine;
|
|
39
40
|
e.call("ghostty_key_encoder_setopt_from_terminal", this.encoder, term.handle);
|
|
40
41
|
const name = keyName(input.code);
|
|
41
42
|
const key = e.hasEnumValue("GhosttyKey", name) ? e.enumValue("GhosttyKey", name) : this.unidentified;
|
|
42
|
-
// Modifiers that composed the text are not modifiers of the key.
|
|
43
43
|
const composed = input.altComposed === true;
|
|
44
44
|
const mods = (input.shift ? MODS.SHIFT : 0) |
|
|
45
45
|
(input.ctrl && !composed ? MODS.CTRL : 0) |
|
|
@@ -49,13 +49,7 @@ export class KeyEncoder {
|
|
|
49
49
|
e.call("ghostty_key_event_set_key", this.event, key);
|
|
50
50
|
e.call("ghostty_key_event_set_mods", this.event, mods);
|
|
51
51
|
const text = isText(input.key) ? input.key : "";
|
|
52
|
-
|
|
53
|
-
// the kitty protocol's disambiguation sends the text (`:`, `A`) rather
|
|
54
|
-
// than shift and the key. It made it when the text is not the key's
|
|
55
|
-
// own character; with no layout to say (no map, or a key it does not
|
|
56
|
-
// cover, such as the numpad), when it is any text but a space.
|
|
57
|
-
const shiftMade = input.shift && text !== "" && (input.unshifted !== undefined ? text !== input.unshifted : text !== " ");
|
|
58
|
-
e.call("ghostty_key_event_set_consumed_mods", this.event, shiftMade ? MODS.SHIFT : 0);
|
|
52
|
+
e.call("ghostty_key_event_set_consumed_mods", this.event, shiftProducedText(input, text) ? MODS.SHIFT : 0);
|
|
59
53
|
e.call("ghostty_key_event_set_composing", this.event, input.composing ? 1 : 0);
|
|
60
54
|
const utf8 = new TextEncoder().encode(text);
|
|
61
55
|
return e.withBytes(utf8, (textPtr) => {
|
package/dist/engine/render.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Engine, type Scrollbar, type Terminal } from "./index.ts";
|
|
2
|
-
/** Style flag bits of a [`Cell`]. */
|
|
3
2
|
export declare const FLAG: {
|
|
4
3
|
readonly BOLD: 1;
|
|
5
4
|
readonly ITALIC: 2;
|
|
@@ -9,12 +8,9 @@ export declare const FLAG: {
|
|
|
9
8
|
readonly INVISIBLE: 32;
|
|
10
9
|
readonly STRIKETHROUGH: 64;
|
|
11
10
|
readonly OVERLINE: 128;
|
|
12
|
-
/** The cell is the left half of a wide character. */
|
|
13
11
|
readonly WIDE: 256;
|
|
14
|
-
/** The cell is the right half of a wide character; draw nothing. */
|
|
15
12
|
readonly SPACER: 512;
|
|
16
13
|
};
|
|
17
|
-
/** No explicit colour; the renderer uses the default. */
|
|
18
14
|
export declare const NO_COLOR = -1;
|
|
19
15
|
export interface Cell {
|
|
20
16
|
/** The grapheme, empty for a blank cell. */
|
|
@@ -26,16 +22,15 @@ export interface Cell {
|
|
|
26
22
|
/** `GhosttySgrUnderline`: 0 none, 1 single, 2 double, 3 curly, 4 dotted, 5 dashed. */
|
|
27
23
|
underline: number;
|
|
28
24
|
}
|
|
29
|
-
/** `GhosttyRenderStateCursorVisualStyle` by name. */
|
|
30
25
|
declare const CURSOR_STYLES: readonly ["bar", "block", "underline", "block_hollow"];
|
|
31
26
|
type CursorStyle = (typeof CURSOR_STYLES)[number];
|
|
32
|
-
export interface FrameRow {
|
|
27
|
+
export interface FrameRow<Cells = Cell[]> {
|
|
33
28
|
y: number;
|
|
34
|
-
cells:
|
|
29
|
+
cells: Cells;
|
|
35
30
|
/** The selected cells of the row, first and last inclusive. */
|
|
36
31
|
selection?: [number, number];
|
|
37
32
|
}
|
|
38
|
-
export interface Frame {
|
|
33
|
+
export interface Frame<Cells = Cell[]> {
|
|
39
34
|
cols: number;
|
|
40
35
|
rows: number;
|
|
41
36
|
/** Every row is included and the renderer should clear first. */
|
|
@@ -51,15 +46,25 @@ export interface Frame {
|
|
|
51
46
|
color: number;
|
|
52
47
|
} | undefined;
|
|
53
48
|
/** The rows that changed, or every row when `full`. */
|
|
54
|
-
lines: FrameRow[];
|
|
49
|
+
lines: FrameRow<Cells>[];
|
|
55
50
|
/** Where the viewport is in the history: scrolled back when it ends
|
|
56
51
|
* above the last row (`offset + len < total`). */
|
|
57
52
|
scrollbar: Scrollbar;
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
export declare const PACKED_STRIDE = 4;
|
|
55
|
+
export declare const PACKED_TEXT = 0;
|
|
56
|
+
export declare const PACKED_FG = 1;
|
|
57
|
+
export declare const PACKED_BG = 2;
|
|
58
|
+
export declare const PACKED_STYLE = 3;
|
|
59
|
+
export declare const PACKED_FLAGS_MASK = 65535;
|
|
60
|
+
export declare const PACKED_UNDERLINE_SHIFT = 16;
|
|
61
|
+
export interface PackedCells {
|
|
62
|
+
data: Int32Array<ArrayBuffer>;
|
|
63
|
+
/** Only multi-codepoint cells need strings; these are cloned on transfer. */
|
|
64
|
+
graphemes: string[];
|
|
65
|
+
}
|
|
66
|
+
export type PackedFrame = Frame<PackedCells>;
|
|
67
|
+
export declare function packedText(cells: PackedCells, x: number): string;
|
|
63
68
|
export declare class RenderState {
|
|
64
69
|
readonly engine: Engine;
|
|
65
70
|
private readonly state;
|
|
@@ -68,18 +73,17 @@ export declare class RenderState {
|
|
|
68
73
|
private readonly keys;
|
|
69
74
|
private readonly tags;
|
|
70
75
|
private readonly wide;
|
|
71
|
-
/** `GhosttyCell` bit fields, from the manifest. */
|
|
72
76
|
private readonly cell;
|
|
73
77
|
private readonly cursorStyles;
|
|
74
78
|
constructor(engine: Engine);
|
|
75
|
-
/** Captures the terminal and returns the rows that changed since the last `clean`. */
|
|
76
79
|
update(term: Terminal): Frame;
|
|
77
|
-
|
|
80
|
+
updatePacked(term: Terminal): PackedFrame;
|
|
81
|
+
takePackedFrame(term: Terminal): PackedFrame;
|
|
82
|
+
private frame;
|
|
78
83
|
private rowSelection;
|
|
79
84
|
private readRow;
|
|
80
85
|
private color;
|
|
81
86
|
private graphemes;
|
|
82
|
-
/** Marks the frame as drawn. */
|
|
83
87
|
clean(): void;
|
|
84
88
|
free(): void;
|
|
85
89
|
}
|
package/dist/engine/render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { EngineError } from "./index.js";
|
|
2
2
|
export const FLAG = {
|
|
3
3
|
BOLD: 1,
|
|
4
4
|
ITALIC: 2,
|
|
@@ -8,19 +8,33 @@ export const FLAG = {
|
|
|
8
8
|
INVISIBLE: 32,
|
|
9
9
|
STRIKETHROUGH: 64,
|
|
10
10
|
OVERLINE: 128,
|
|
11
|
-
/** The cell is the left half of a wide character. */
|
|
12
11
|
WIDE: 256,
|
|
13
|
-
/** The cell is the right half of a wide character; draw nothing. */
|
|
14
12
|
SPACER: 512,
|
|
15
13
|
};
|
|
16
|
-
/** No explicit colour; the renderer uses the default. */
|
|
17
14
|
export const NO_COLOR = -1;
|
|
18
|
-
/** `GhosttyRenderStateCursorVisualStyle` by name. */
|
|
19
15
|
const CURSOR_STYLES = ["bar", "block", "underline", "block_hollow"];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
export const PACKED_STRIDE = 4;
|
|
17
|
+
export const PACKED_TEXT = 0;
|
|
18
|
+
export const PACKED_FG = 1;
|
|
19
|
+
export const PACKED_BG = 2;
|
|
20
|
+
export const PACKED_STYLE = 3;
|
|
21
|
+
export const PACKED_FLAGS_MASK = 0xffff;
|
|
22
|
+
export const PACKED_UNDERLINE_SHIFT = 16;
|
|
23
|
+
function scratchLayout(e, types) {
|
|
24
|
+
const offsets = [];
|
|
25
|
+
let size = 0;
|
|
26
|
+
for (const name of types) {
|
|
27
|
+
const align = e.alignOf(name);
|
|
28
|
+
size = Math.ceil(size / align) * align;
|
|
29
|
+
offsets.push(size);
|
|
30
|
+
size += e.sizeOf(name);
|
|
31
|
+
}
|
|
32
|
+
return { offsets, size };
|
|
33
|
+
}
|
|
34
|
+
export function packedText(cells, x) {
|
|
35
|
+
const code = cells.data[x * PACKED_STRIDE + PACKED_TEXT];
|
|
36
|
+
return code < 0 ? cells.graphemes[-code - 1] : code === 0 ? "" : String.fromCodePoint(code);
|
|
37
|
+
}
|
|
24
38
|
export class RenderState {
|
|
25
39
|
engine;
|
|
26
40
|
state;
|
|
@@ -29,7 +43,6 @@ export class RenderState {
|
|
|
29
43
|
keys;
|
|
30
44
|
tags;
|
|
31
45
|
wide;
|
|
32
|
-
/** `GhosttyCell` bit fields, from the manifest. */
|
|
33
46
|
cell;
|
|
34
47
|
cursorStyles;
|
|
35
48
|
constructor(engine) {
|
|
@@ -65,8 +78,36 @@ export class RenderState {
|
|
|
65
78
|
};
|
|
66
79
|
this.cursorStyles = new Map(CURSOR_STYLES.map((style) => [engine.enumValue("GhosttyRenderStateCursorVisualStyle", style.toUpperCase()), style]));
|
|
67
80
|
}
|
|
68
|
-
/** Captures the terminal and returns the rows that changed since the last `clean`. */
|
|
69
81
|
update(term) {
|
|
82
|
+
return this.frame(term, (cols) => {
|
|
83
|
+
const cells = [];
|
|
84
|
+
this.readRow(cols, (codepoint, text, fg, bg, flags, underline) => {
|
|
85
|
+
cells.push({ text: codepoint ? String.fromCodePoint(codepoint) : text, fg, bg, flags, underline });
|
|
86
|
+
});
|
|
87
|
+
return cells;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
updatePacked(term) {
|
|
91
|
+
return this.frame(term, (cols) => {
|
|
92
|
+
const data = new Int32Array(cols * PACKED_STRIDE);
|
|
93
|
+
const graphemes = [];
|
|
94
|
+
let at = 0;
|
|
95
|
+
this.readRow(cols, (codepoint, text, fg, bg, flags, underline) => {
|
|
96
|
+
data[at + PACKED_TEXT] = text === "" ? codepoint : -graphemes.push(text);
|
|
97
|
+
data[at + PACKED_FG] = fg;
|
|
98
|
+
data[at + PACKED_BG] = bg;
|
|
99
|
+
data[at + PACKED_STYLE] = flags | (underline << PACKED_UNDERLINE_SHIFT);
|
|
100
|
+
at += PACKED_STRIDE;
|
|
101
|
+
});
|
|
102
|
+
return { data: data.subarray(0, at), graphemes };
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
takePackedFrame(term) {
|
|
106
|
+
const frame = this.updatePacked(term);
|
|
107
|
+
this.clean();
|
|
108
|
+
return frame;
|
|
109
|
+
}
|
|
110
|
+
frame(term, readRow) {
|
|
70
111
|
const e = this.engine;
|
|
71
112
|
e.check("ghostty_render_state_update", this.state, term.handle);
|
|
72
113
|
// Read with the update: the render state does not keep the scroll position.
|
|
@@ -112,7 +153,7 @@ export class RenderState {
|
|
|
112
153
|
e.check("ghostty_render_state_get", this.state, this.keys.data["ROW_ITERATOR"], out);
|
|
113
154
|
while (e.call("ghostty_render_state_row_iterator_next_dirty", this.iterator, out + 4)) {
|
|
114
155
|
const y = e.view.getUint16(out + 4, true);
|
|
115
|
-
const row = { y, cells:
|
|
156
|
+
const row = { y, cells: readRow(cols) };
|
|
116
157
|
const selection = this.rowSelection();
|
|
117
158
|
if (selection)
|
|
118
159
|
row.selection = selection;
|
|
@@ -121,47 +162,38 @@ export class RenderState {
|
|
|
121
162
|
});
|
|
122
163
|
return { cols, rows, full, background, foreground, cursor, lines, scrollbar };
|
|
123
164
|
}
|
|
124
|
-
/** The row's selected cells, or undefined when the selection misses it. */
|
|
125
165
|
rowSelection() {
|
|
126
166
|
const e = this.engine;
|
|
127
167
|
const size = e.sizeOf("GhosttyRenderStateRowSelection");
|
|
128
168
|
return e.scratch(size, (out) => {
|
|
129
169
|
e.view.setUint32(out, size, true);
|
|
130
|
-
|
|
131
|
-
if (code === e.result.NO_VALUE)
|
|
170
|
+
if (!e.present("ghostty_render_state_row_get", this.iterator, this.keys.row["SELECTION"], out))
|
|
132
171
|
return undefined;
|
|
133
|
-
if (code !== e.result.SUCCESS)
|
|
134
|
-
throw new Error(`row selection: ${code}`);
|
|
135
172
|
const field = (key) => e.field("GhosttyRenderStateRowSelection", out, key);
|
|
136
173
|
return [field("start_x"), field("end_x")];
|
|
137
174
|
});
|
|
138
175
|
}
|
|
139
|
-
readRow(cols) {
|
|
176
|
+
readRow(cols, write) {
|
|
140
177
|
const e = this.engine;
|
|
141
178
|
e.scratch(4, (out) => {
|
|
142
179
|
e.view.setUint32(out, this.cells, true);
|
|
143
180
|
e.check("ghostty_render_state_row_get", this.iterator, this.keys.row["CELLS"], out);
|
|
144
181
|
});
|
|
145
182
|
const styleSize = e.sizeOf("GhosttyStyle");
|
|
146
|
-
|
|
147
|
-
// Scratch: raw cell (8), colour (3, padded to 8), the 8-aligned style,
|
|
148
|
-
// a UTF-8 buffer struct and its bytes.
|
|
183
|
+
let count = 0;
|
|
149
184
|
const utf8Cap = 64;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const color = scratch +
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
const utf8 = buffer + e.sizeOf("GhosttyBuffer");
|
|
156
|
-
while (e.call("ghostty_render_state_row_cells_next", this.cells) && cells.length < cols) {
|
|
185
|
+
const layout = scratchLayout(e, ["GhosttyCell", "GhosttyColorRgb", "GhosttyStyle", "GhosttyBuffer"]);
|
|
186
|
+
e.scratch(layout.size + utf8Cap, (scratch) => {
|
|
187
|
+
const [raw, color, style, buffer] = layout.offsets.map((offset) => scratch + offset);
|
|
188
|
+
const utf8 = scratch + layout.size;
|
|
189
|
+
while (e.call("ghostty_render_state_row_cells_next", this.cells) && count < cols) {
|
|
157
190
|
e.check("ghostty_render_state_row_cells_get", this.cells, this.keys.cell["RAW"], raw);
|
|
158
191
|
const tag = e.readBits(raw, this.cell.tag);
|
|
159
192
|
const wide = e.readBits(raw, this.cell.wide);
|
|
193
|
+
let codepoint = 0;
|
|
160
194
|
let text = "";
|
|
161
195
|
if (tag === this.tags.codepoint) {
|
|
162
|
-
|
|
163
|
-
if (cp !== 0)
|
|
164
|
-
text = String.fromCodePoint(cp);
|
|
196
|
+
codepoint = e.readBits(raw, this.cell.codepoint);
|
|
165
197
|
}
|
|
166
198
|
else if (tag === this.tags.grapheme) {
|
|
167
199
|
text = this.graphemes(buffer, utf8, utf8Cap);
|
|
@@ -197,10 +229,10 @@ export class RenderState {
|
|
|
197
229
|
flags |= FLAG.OVERLINE;
|
|
198
230
|
underline = e.field("GhosttyStyle", style, "underline");
|
|
199
231
|
}
|
|
200
|
-
|
|
232
|
+
write(codepoint, text, fg, bg, flags, underline);
|
|
233
|
+
count++;
|
|
201
234
|
}
|
|
202
235
|
});
|
|
203
|
-
return cells;
|
|
204
236
|
}
|
|
205
237
|
color(key, out) {
|
|
206
238
|
const e = this.engine;
|
|
@@ -208,7 +240,7 @@ export class RenderState {
|
|
|
208
240
|
if (code === e.result.INVALID_VALUE)
|
|
209
241
|
return NO_COLOR;
|
|
210
242
|
if (code !== e.result.SUCCESS)
|
|
211
|
-
throw new
|
|
243
|
+
throw new EngineError("ghostty_render_state_row_cells_get", code);
|
|
212
244
|
return e.readRgb(out);
|
|
213
245
|
}
|
|
214
246
|
graphemes(buffer, utf8, cap) {
|
|
@@ -222,8 +254,7 @@ export class RenderState {
|
|
|
222
254
|
return new TextDecoder().decode(e.memory.slice(utf8, utf8 + len));
|
|
223
255
|
}
|
|
224
256
|
if (code !== e.result.OUT_OF_SPACE)
|
|
225
|
-
throw new
|
|
226
|
-
// The buffer struct reports the needed length; retry through it.
|
|
257
|
+
throw new EngineError("ghostty_render_state_row_cells_get", code);
|
|
227
258
|
const needed = e.field("GhosttyBuffer", buffer, "len");
|
|
228
259
|
return new TextDecoder().decode(e.growing("ghostty_render_state_row_cells_get", needed, (big, bigCap, len) => {
|
|
229
260
|
e.view.setUint32(buffer + e.offsetOf("GhosttyBuffer", "ptr"), big, true);
|
|
@@ -233,7 +264,6 @@ export class RenderState {
|
|
|
233
264
|
return again;
|
|
234
265
|
}));
|
|
235
266
|
}
|
|
236
|
-
/** Marks the frame as drawn. */
|
|
237
267
|
clean() {
|
|
238
268
|
this.engine.check("ghostty_render_state_clean", this.state);
|
|
239
269
|
}
|
|
@@ -5,33 +5,16 @@ export interface CellPoint {
|
|
|
5
5
|
x: number;
|
|
6
6
|
y: number;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Mouse selection through the engine's gesture: a press, then drags, then
|
|
10
|
-
* a release. A single press selects nothing; a drag selects from it by
|
|
11
|
-
* cells, a double press a word and a triple press a line, dragging by
|
|
12
|
-
* words or lines. The gesture tracks its anchor in the terminal, so
|
|
13
|
-
* output between press and drag does not move it.
|
|
14
|
-
*/
|
|
15
8
|
export declare class SelectionGesture {
|
|
16
9
|
readonly engine: Engine;
|
|
17
10
|
private gesture;
|
|
18
11
|
private readonly events;
|
|
19
|
-
/** The terminal the gesture tracks its anchor in. */
|
|
20
12
|
private term;
|
|
21
13
|
constructor(engine: Engine);
|
|
22
|
-
/** Presses at `at` (`time` in ms); the selection to install, or
|
|
23
|
-
* undefined for none (a single press). */
|
|
24
14
|
press(term: Terminal, at: CellPoint, time: number): Uint8Array | undefined;
|
|
25
|
-
/** Drags to `at`; the selection from the press, or undefined when the
|
|
26
|
-
* pointer has not left the pressed cell. */
|
|
27
15
|
drag(term: Terminal, at: CellPoint): Uint8Array | undefined;
|
|
28
16
|
release(term: Terminal, at: CellPoint): void;
|
|
29
|
-
/** Starts afresh, for a terminal freed or about to be: `term` when it
|
|
30
|
-
* is still alive, to release the tracked anchor in it, else none. The
|
|
31
|
-
* caller says so, since a new terminal may have the handle of a freed
|
|
32
|
-
* one. */
|
|
33
17
|
forget(term?: Terminal): void;
|
|
34
|
-
/** A gesture is in one terminal. */
|
|
35
18
|
private follow;
|
|
36
19
|
private set;
|
|
37
20
|
private apply;
|
package/dist/engine/selection.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const SCALE = 1000;
|
|
4
|
-
/** Clicks closer together than this, and within a cell of each other,
|
|
5
|
-
* count up to a word (two) and a line (three). */
|
|
6
|
-
const REPEAT_MS = 500;
|
|
7
|
-
/**
|
|
8
|
-
* Mouse selection through the engine's gesture: a press, then drags, then
|
|
9
|
-
* a release. A single press selects nothing; a drag selects from it by
|
|
10
|
-
* cells, a double press a word and a triple press a line, dragging by
|
|
11
|
-
* words or lines. The gesture tracks its anchor in the terminal, so
|
|
12
|
-
* output between press and drag does not move it.
|
|
13
|
-
*/
|
|
1
|
+
const PIXELS_PER_CELL = 1000;
|
|
2
|
+
const MULTI_CLICK_INTERVAL_MS = 500;
|
|
14
3
|
export class SelectionGesture {
|
|
15
4
|
engine;
|
|
16
5
|
gesture;
|
|
17
6
|
events;
|
|
18
|
-
/** The terminal the gesture tracks its anchor in. */
|
|
19
7
|
term;
|
|
20
8
|
constructor(engine) {
|
|
21
9
|
this.engine = engine;
|
|
@@ -23,12 +11,10 @@ export class SelectionGesture {
|
|
|
23
11
|
const event = (type) => engine.construct("ghostty_selection_gesture_event_new", engine.enumValue("GhosttySelectionGestureEventType", type));
|
|
24
12
|
this.events = { press: event("PRESS"), drag: event("DRAG"), release: event("RELEASE") };
|
|
25
13
|
const f64 = new Uint8Array(8);
|
|
26
|
-
new DataView(f64.buffer).setFloat64(0,
|
|
14
|
+
new DataView(f64.buffer).setFloat64(0, PIXELS_PER_CELL, true);
|
|
27
15
|
this.set(this.events.press, "REPEAT_DISTANCE", f64);
|
|
28
|
-
this.set(this.events.press, "REPEAT_INTERVAL_NS", u64(
|
|
16
|
+
this.set(this.events.press, "REPEAT_INTERVAL_NS", u64(MULTI_CLICK_INTERVAL_MS * 1e6));
|
|
29
17
|
}
|
|
30
|
-
/** Presses at `at` (`time` in ms); the selection to install, or
|
|
31
|
-
* undefined for none (a single press). */
|
|
32
18
|
press(term, at, time) {
|
|
33
19
|
this.follow(term);
|
|
34
20
|
this.set(this.events.press, "REF", term.gridRef(at));
|
|
@@ -36,17 +22,15 @@ export class SelectionGesture {
|
|
|
36
22
|
this.set(this.events.press, "TIME_NS", u64(time * 1e6));
|
|
37
23
|
return this.apply(term, this.events.press);
|
|
38
24
|
}
|
|
39
|
-
/** Drags to `at`; the selection from the press, or undefined when the
|
|
40
|
-
* pointer has not left the pressed cell. */
|
|
41
25
|
drag(term, at) {
|
|
42
26
|
if (this.term !== term.handle)
|
|
43
27
|
return undefined;
|
|
44
28
|
const geometry = new Uint8Array(16);
|
|
45
29
|
const view = new DataView(geometry.buffer);
|
|
46
30
|
view.setUint32(0, term.cols, true);
|
|
47
|
-
view.setUint32(4,
|
|
31
|
+
view.setUint32(4, PIXELS_PER_CELL, true);
|
|
48
32
|
view.setUint32(8, 0, true);
|
|
49
|
-
view.setUint32(12, term.rows *
|
|
33
|
+
view.setUint32(12, term.rows * PIXELS_PER_CELL, true);
|
|
50
34
|
this.set(this.events.drag, "REF", term.gridRef(at));
|
|
51
35
|
this.set(this.events.drag, "POSITION", position(at));
|
|
52
36
|
this.set(this.events.drag, "GEOMETRY", geometry);
|
|
@@ -58,10 +42,6 @@ export class SelectionGesture {
|
|
|
58
42
|
this.set(this.events.release, "REF", term.gridRef(at));
|
|
59
43
|
this.apply(term, this.events.release);
|
|
60
44
|
}
|
|
61
|
-
/** Starts afresh, for a terminal freed or about to be: `term` when it
|
|
62
|
-
* is still alive, to release the tracked anchor in it, else none. The
|
|
63
|
-
* caller says so, since a new terminal may have the handle of a freed
|
|
64
|
-
* one. */
|
|
65
45
|
forget(term) {
|
|
66
46
|
if (this.term === undefined)
|
|
67
47
|
return;
|
|
@@ -69,7 +49,6 @@ export class SelectionGesture {
|
|
|
69
49
|
this.gesture = this.engine.construct("ghostty_selection_gesture_new");
|
|
70
50
|
this.term = undefined;
|
|
71
51
|
}
|
|
72
|
-
/** A gesture is in one terminal. */
|
|
73
52
|
follow(term) {
|
|
74
53
|
if (this.term !== term.handle)
|
|
75
54
|
this.forget();
|
|
@@ -85,11 +64,8 @@ export class SelectionGesture {
|
|
|
85
64
|
return e.scratch(size, (out) => {
|
|
86
65
|
e.memory.fill(0, out, out + size);
|
|
87
66
|
e.view.setUint32(out, size, true);
|
|
88
|
-
|
|
89
|
-
if (code === e.result.NO_VALUE)
|
|
67
|
+
if (!e.present("ghostty_selection_gesture_event", this.gesture, term.handle, event, out))
|
|
90
68
|
return undefined;
|
|
91
|
-
if (code !== e.result.SUCCESS)
|
|
92
|
-
throw new Error(`selection gesture: ${code}`);
|
|
93
69
|
return e.memory.slice(out, out + size);
|
|
94
70
|
});
|
|
95
71
|
}
|
|
@@ -104,11 +80,10 @@ function u64(value) {
|
|
|
104
80
|
new DataView(bytes.buffer).setBigUint64(0, BigInt(Math.round(value)), true);
|
|
105
81
|
return bytes;
|
|
106
82
|
}
|
|
107
|
-
/** A `GhosttySurfacePosition` for `at`, in the gesture's scaled pixels. */
|
|
108
83
|
function position(at) {
|
|
109
84
|
const bytes = new Uint8Array(16);
|
|
110
85
|
const view = new DataView(bytes.buffer);
|
|
111
|
-
view.setFloat64(0, at.x *
|
|
112
|
-
view.setFloat64(8, at.y *
|
|
86
|
+
view.setFloat64(0, at.x * PIXELS_PER_CELL, true);
|
|
87
|
+
view.setFloat64(8, at.y * PIXELS_PER_CELL, true);
|
|
113
88
|
return bytes;
|
|
114
89
|
}
|