@gjermundgaraba/clankermux 0.6.0 → 0.8.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 +1 -2
- package/dist/client/attachment.js +8 -16
- package/dist/client/connection.d.ts +1 -1
- package/dist/client/link.d.ts +143 -0
- package/dist/client/link.js +205 -0
- package/dist/client/osc52.js +0 -11
- package/dist/client/worker.d.ts +3 -37
- package/dist/client/worker.js +114 -141
- package/dist/engine/decoder.d.ts +4 -0
- package/dist/engine/decoder.js +32 -1
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.js +27 -36
- package/dist/engine/keys.js +4 -2
- package/dist/engine/pin.d.ts +1 -2
- package/dist/engine/pin.js +1 -3
- package/dist/engine/render.d.ts +1 -0
- package/dist/engine/render.js +11 -22
- package/dist/proto/frame.d.ts +2 -23
- package/dist/proto/frame.js +1 -21
- package/dist/proto/messages.d.ts +49 -9
- package/dist/proto/messages.js +42 -2
- package/ghostty-vt.wasm +0 -0
- package/package.json +5 -2
package/dist/client/worker.js
CHANGED
|
@@ -2,6 +2,7 @@ import { ENGINE, Engine, KeyEncoder, RenderState, SelectionGesture, } from "../e
|
|
|
2
2
|
import { FrameType, } from "../proto/index.js";
|
|
3
3
|
import { Attachment } from "./attachment.js";
|
|
4
4
|
import { ClientError, Connection, hello } from "./connection.js";
|
|
5
|
+
import { endedWith, lineOf, linkOf, mountMachine, } from "./link.js";
|
|
5
6
|
import { Osc52Scanner } from "./osc52.js";
|
|
6
7
|
const SCROLL_KEYS = {
|
|
7
8
|
PageUp: -1,
|
|
@@ -12,7 +13,6 @@ const SCROLL_KEYS = {
|
|
|
12
13
|
const PAINT_COALESCE_MS = 16;
|
|
13
14
|
const BACKOFF_MIN_MS = 250;
|
|
14
15
|
const BACKOFF_MAX_MS = 5000;
|
|
15
|
-
const UNRETRYABLE_OPEN_ERRORS = new Set(["no_such_session", "engine_mismatch", "invalid_request"]);
|
|
16
16
|
const ACKABLE_ATTENTION_STATES = new Set(["done", "error"]);
|
|
17
17
|
const ALTERNATE_SCROLL_MODE = 1007;
|
|
18
18
|
const SEND_REQUEST_OVERHEAD_BYTES = 1024;
|
|
@@ -76,12 +76,6 @@ function failureOf(err) {
|
|
|
76
76
|
? { kind: err.kind, message: err.message, ...(err.server && { server: err.server }) }
|
|
77
77
|
: { kind: "protocol", message: err instanceof Error ? err.message : String(err) };
|
|
78
78
|
}
|
|
79
|
-
function endedWith(err, retry) {
|
|
80
|
-
const server = err instanceof ClientError ? err.server : undefined;
|
|
81
|
-
return server
|
|
82
|
-
? { state: "ended", reason: linkEnd(server.code), code: server.code, message: server.message, retry }
|
|
83
|
-
: { state: "ended", reason: "error", message: err instanceof Error ? err.message : String(err), retry };
|
|
84
|
-
}
|
|
85
79
|
class Hub {
|
|
86
80
|
post;
|
|
87
81
|
constructor(post) {
|
|
@@ -158,6 +152,8 @@ class Hub {
|
|
|
158
152
|
if (this.conn !== conn)
|
|
159
153
|
return;
|
|
160
154
|
this.conn = undefined;
|
|
155
|
+
for (const mount of this.mounts.values())
|
|
156
|
+
mount.disconnected();
|
|
161
157
|
if (err.kind === "server") {
|
|
162
158
|
this.refuse(err);
|
|
163
159
|
}
|
|
@@ -182,7 +178,7 @@ class Hub {
|
|
|
182
178
|
this.statusText = "connected";
|
|
183
179
|
this.post({ type: "connection", link: this.connectionLink });
|
|
184
180
|
for (const mount of this.mounts.values())
|
|
185
|
-
mount.connected();
|
|
181
|
+
mount.connected(conn);
|
|
186
182
|
}
|
|
187
183
|
async subscribe(conn) {
|
|
188
184
|
const incarnation = conn.welcome.incarnation;
|
|
@@ -278,35 +274,30 @@ class Hub {
|
|
|
278
274
|
const mount = new Mount(this, id, init);
|
|
279
275
|
this.mounts.set(id, mount);
|
|
280
276
|
mount.status(this.statusText);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
else
|
|
277
|
+
const conn = this.live();
|
|
278
|
+
if (conn)
|
|
279
|
+
mount.connected(conn);
|
|
280
|
+
else if (this.connectionLink.state !== "ended")
|
|
286
281
|
mount.link(this.connectionLink);
|
|
282
|
+
this.reconnectIfEnded();
|
|
287
283
|
}
|
|
288
284
|
unmount(id) {
|
|
289
285
|
this.mounts.get(id)?.dispose();
|
|
290
286
|
this.mounts.delete(id);
|
|
291
287
|
}
|
|
292
|
-
|
|
293
|
-
if (this.connectionLink.state
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
else {
|
|
298
|
-
mount.open();
|
|
299
|
-
}
|
|
288
|
+
reconnectIfEnded() {
|
|
289
|
+
if (this.connectionLink.state !== "ended")
|
|
290
|
+
return;
|
|
291
|
+
this.attempt = 0;
|
|
292
|
+
void this.connect();
|
|
300
293
|
}
|
|
301
294
|
}
|
|
302
295
|
class Mount {
|
|
303
296
|
hub;
|
|
304
297
|
id;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
openOn;
|
|
298
|
+
snapshot = mountMachine.initialState;
|
|
299
|
+
reopenTimer;
|
|
308
300
|
acking = false;
|
|
309
|
-
session;
|
|
310
301
|
viewport;
|
|
311
302
|
profile;
|
|
312
303
|
active;
|
|
@@ -325,12 +316,9 @@ class Mount {
|
|
|
325
316
|
frameInFlight = false;
|
|
326
317
|
fullNext = false;
|
|
327
318
|
backoff = new Backoff();
|
|
328
|
-
reopenTimer;
|
|
329
|
-
disposed = false;
|
|
330
319
|
constructor(hub, id, init) {
|
|
331
320
|
this.hub = hub;
|
|
332
321
|
this.id = id;
|
|
333
|
-
this.session = init.session;
|
|
334
322
|
this.viewport = init.viewport;
|
|
335
323
|
this.profile = init.profile;
|
|
336
324
|
this.active = init.active;
|
|
@@ -339,9 +327,17 @@ class Mount {
|
|
|
339
327
|
this.ackOnFocus = init.ackOnFocus;
|
|
340
328
|
this.render = new RenderState(hub.engine);
|
|
341
329
|
this.gesture = new SelectionGesture(hub.engine);
|
|
330
|
+
if (init.session !== undefined)
|
|
331
|
+
this.step({ type: "page.attach", session: init.session, open: undefined });
|
|
332
|
+
}
|
|
333
|
+
get attachment() {
|
|
334
|
+
return this.snapshot.context.attachment;
|
|
335
|
+
}
|
|
336
|
+
get session() {
|
|
337
|
+
return this.snapshot.context.session;
|
|
342
338
|
}
|
|
343
339
|
post(message, options) {
|
|
344
|
-
if (
|
|
340
|
+
if (this.snapshot.value !== "disposed")
|
|
345
341
|
this.hub.post(message, options);
|
|
346
342
|
}
|
|
347
343
|
link(link) {
|
|
@@ -350,33 +346,52 @@ class Mount {
|
|
|
350
346
|
status(text) {
|
|
351
347
|
this.post({ type: "status", mount: this.id, text });
|
|
352
348
|
}
|
|
353
|
-
connected() {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
349
|
+
connected(conn) {
|
|
350
|
+
this.step({ type: "hub.live", open: this.offer(conn) });
|
|
351
|
+
}
|
|
352
|
+
disconnected() {
|
|
353
|
+
this.step({ type: "hub.down" });
|
|
354
|
+
}
|
|
355
|
+
offer(conn) {
|
|
356
|
+
return { conn, channel: this.hub.nextChannel(), fresh: new Attachment(this.hub.engine) };
|
|
361
357
|
}
|
|
362
|
-
|
|
358
|
+
offerIfLive() {
|
|
363
359
|
const conn = this.hub.live();
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
360
|
+
return conn && this.offer(conn);
|
|
361
|
+
}
|
|
362
|
+
step(event) {
|
|
363
|
+
const prev = this.snapshot;
|
|
364
|
+
const [next] = mountMachine.transition(prev, event);
|
|
365
|
+
if (next === prev)
|
|
366
|
+
return;
|
|
367
|
+
const { attachment } = prev.context;
|
|
368
|
+
if (attachment && attachment !== next.context.attachment)
|
|
369
|
+
this.close(attachment, lineOf(prev));
|
|
370
|
+
if (prev.value === "backoff")
|
|
371
|
+
clearTimeout(this.reopenTimer);
|
|
372
|
+
this.snapshot = next;
|
|
373
|
+
if (next.value === "opening")
|
|
374
|
+
this.open(next.context);
|
|
375
|
+
if (next.value === "backoff") {
|
|
376
|
+
this.reopenTimer = setTimeout(() => this.step({ type: "reopen.due", open: this.offerIfLive() }), this.backoff.next());
|
|
377
|
+
}
|
|
378
|
+
const link = linkOf(next);
|
|
379
|
+
if (!link)
|
|
380
|
+
return;
|
|
381
|
+
if (link.state === "connected" && link.session === undefined)
|
|
382
|
+
this.status("no session");
|
|
383
|
+
this.link(link);
|
|
384
|
+
}
|
|
385
|
+
open({ session, attachment, channel, conn }) {
|
|
386
|
+
const resume = attachment.open(conn.welcome);
|
|
374
387
|
const open = {
|
|
375
|
-
session
|
|
388
|
+
session,
|
|
376
389
|
...(this.readOnly && { read_only: true }),
|
|
377
390
|
...(this.active && { viewport: this.viewport, profile: this.profile }),
|
|
378
391
|
...(resume && { resume }),
|
|
379
392
|
};
|
|
393
|
+
if (this.active)
|
|
394
|
+
this.sizeTakenByOtherClient = false;
|
|
380
395
|
conn.open(channel, open, (frame) => {
|
|
381
396
|
if (this.attachment !== attachment)
|
|
382
397
|
return;
|
|
@@ -386,35 +401,21 @@ class Mount {
|
|
|
386
401
|
}
|
|
387
402
|
catch (err) {
|
|
388
403
|
this.status(String(err));
|
|
389
|
-
|
|
390
|
-
this.link(endedWith(err, desync));
|
|
391
|
-
if (desync)
|
|
392
|
-
this.reopen();
|
|
393
|
-
else
|
|
394
|
-
this.giveUp();
|
|
404
|
+
this.step({ type: "attachment.threw", error: err });
|
|
395
405
|
return;
|
|
396
406
|
}
|
|
397
407
|
for (const action of actions)
|
|
398
408
|
this.apply(action);
|
|
399
409
|
});
|
|
400
410
|
}
|
|
401
|
-
|
|
402
|
-
this.
|
|
403
|
-
if (
|
|
404
|
-
|
|
411
|
+
close(attachment, line) {
|
|
412
|
+
this.forgetSelection(attachment.term());
|
|
413
|
+
if (line) {
|
|
414
|
+
line.conn.release(line.channel);
|
|
415
|
+
if (!attachment.closed())
|
|
416
|
+
line.conn.send(FrameType.Close, line.channel, new Uint8Array());
|
|
405
417
|
}
|
|
406
|
-
|
|
407
|
-
giveUp() {
|
|
408
|
-
this.close();
|
|
409
|
-
this.session = undefined;
|
|
410
|
-
}
|
|
411
|
-
reopen() {
|
|
412
|
-
this.close();
|
|
413
|
-
this.reopenTimer ??= setTimeout(() => {
|
|
414
|
-
this.reopenTimer = undefined;
|
|
415
|
-
if (this.session !== undefined && !this.attachment)
|
|
416
|
-
this.open();
|
|
417
|
-
}, this.backoff.next());
|
|
418
|
+
attachment.free();
|
|
418
419
|
}
|
|
419
420
|
apply(action) {
|
|
420
421
|
switch (action.type) {
|
|
@@ -431,14 +432,16 @@ class Mount {
|
|
|
431
432
|
? `exited: ${describe(session.exit)}`
|
|
432
433
|
: "attached";
|
|
433
434
|
this.status(text);
|
|
434
|
-
this.
|
|
435
|
+
this.step({ type: "frame.screen", session });
|
|
436
|
+
if (session?.status === "exited")
|
|
437
|
+
this.step({ type: "frame.exited", exit: session.exit });
|
|
435
438
|
if (session)
|
|
436
439
|
this.changed(session);
|
|
437
440
|
break;
|
|
438
441
|
}
|
|
439
442
|
case "resumed":
|
|
440
443
|
this.status("resumed");
|
|
441
|
-
this.
|
|
444
|
+
this.step({ type: "frame.resumed", session: this.attachment?.session });
|
|
442
445
|
break;
|
|
443
446
|
case "output":
|
|
444
447
|
if (this.selected && !this.attachment?.term()?.selected)
|
|
@@ -460,7 +463,7 @@ class Mount {
|
|
|
460
463
|
case "exited":
|
|
461
464
|
this.paint();
|
|
462
465
|
this.status(`exited: ${describe(action.exit)}`);
|
|
463
|
-
this.
|
|
466
|
+
this.step({ type: "frame.exited", exit: action.exit });
|
|
464
467
|
break;
|
|
465
468
|
case "gap":
|
|
466
469
|
this.clipboard.reset();
|
|
@@ -469,28 +472,12 @@ class Mount {
|
|
|
469
472
|
break;
|
|
470
473
|
case "closed":
|
|
471
474
|
this.status(`closed: ${action.reason}`);
|
|
472
|
-
this.
|
|
473
|
-
state: "ended",
|
|
474
|
-
reason: action.reason,
|
|
475
|
-
...(action.message !== undefined && { message: action.message }),
|
|
476
|
-
retry: action.reason === "stopping",
|
|
477
|
-
});
|
|
478
|
-
if (action.reason === "removed" || action.reason === "detached")
|
|
479
|
-
this.giveUp();
|
|
475
|
+
this.step({ type: "frame.closed", reason: action.reason, message: action.message });
|
|
480
476
|
break;
|
|
481
|
-
case "error":
|
|
477
|
+
case "error":
|
|
482
478
|
this.status(`${action.error.code}: ${action.error.message}`);
|
|
483
|
-
|
|
484
|
-
break;
|
|
485
|
-
const { code, message } = action.error;
|
|
486
|
-
const retry = !UNRETRYABLE_OPEN_ERRORS.has(code);
|
|
487
|
-
this.link({ state: "ended", reason: linkEnd(code), code, message, retry });
|
|
488
|
-
if (retry)
|
|
489
|
-
this.reopen();
|
|
490
|
-
else
|
|
491
|
-
this.giveUp();
|
|
479
|
+
this.step({ type: "frame.error", error: action.error, endsAttachment: this.attachment?.closed() === true });
|
|
492
480
|
break;
|
|
493
|
-
}
|
|
494
481
|
}
|
|
495
482
|
}
|
|
496
483
|
applyProfile(term) {
|
|
@@ -534,7 +521,7 @@ class Mount {
|
|
|
534
521
|
}
|
|
535
522
|
this.paintPending = true;
|
|
536
523
|
const term = this.attachment?.term();
|
|
537
|
-
if (!term ||
|
|
524
|
+
if (!term || !this.visible || this.frameInFlight)
|
|
538
525
|
return;
|
|
539
526
|
if (this.fullNext) {
|
|
540
527
|
this.render.free();
|
|
@@ -598,72 +585,57 @@ class Mount {
|
|
|
598
585
|
if (this.selected)
|
|
599
586
|
this.unselected();
|
|
600
587
|
}
|
|
601
|
-
close() {
|
|
602
|
-
if (!this.attachment)
|
|
603
|
-
return;
|
|
604
|
-
this.forgetSelection(this.attachment.term());
|
|
605
|
-
const conn = this.hub.conn;
|
|
606
|
-
if (conn) {
|
|
607
|
-
conn.release(this.channel);
|
|
608
|
-
if (!this.attachment.closed())
|
|
609
|
-
conn.send(FrameType.Close, this.channel, new Uint8Array());
|
|
610
|
-
}
|
|
611
|
-
this.attachment.free();
|
|
612
|
-
this.attachment = undefined;
|
|
613
|
-
this.openOn = undefined;
|
|
614
|
-
}
|
|
615
588
|
attach(session) {
|
|
616
|
-
this.
|
|
589
|
+
this.step({ type: "page.attach", session, open: this.offerIfLive() });
|
|
617
590
|
this.inputQueue.stopWaitingOnSendsUnderWay();
|
|
618
|
-
this.
|
|
619
|
-
this.hub.reattach(this);
|
|
591
|
+
this.hub.reconnectIfEnded();
|
|
620
592
|
}
|
|
621
593
|
detach() {
|
|
622
|
-
|
|
623
|
-
this.giveUp();
|
|
594
|
+
this.step({ type: "page.detach", live: this.hub.live() !== undefined });
|
|
624
595
|
this.inputQueue.stopWaitingOnSendsUnderWay();
|
|
625
|
-
if (had && this.hub.conn) {
|
|
626
|
-
this.status("no session");
|
|
627
|
-
this.link({ state: "connected", session: undefined });
|
|
628
|
-
}
|
|
629
596
|
}
|
|
630
597
|
dispose() {
|
|
631
|
-
this.
|
|
632
|
-
this.disposed = true;
|
|
598
|
+
this.step({ type: "page.unmount" });
|
|
633
599
|
if (this.paintTimer !== undefined)
|
|
634
600
|
clearTimeout(this.paintTimer);
|
|
635
|
-
if (this.reopenTimer !== undefined)
|
|
636
|
-
clearTimeout(this.reopenTimer);
|
|
637
601
|
this.render.free();
|
|
638
602
|
this.gesture.forget(undefined);
|
|
639
603
|
}
|
|
640
604
|
sendInput(bytes) {
|
|
641
|
-
this.
|
|
642
|
-
|
|
643
|
-
|
|
605
|
+
if (!this.typed(bytes))
|
|
606
|
+
return;
|
|
607
|
+
const line = lineOf(this.snapshot);
|
|
608
|
+
if (line)
|
|
609
|
+
this.deliver(line.conn, async () => line.conn.send(FrameType.Input, line.channel, bytes));
|
|
644
610
|
}
|
|
645
611
|
sendPaste(bytes) {
|
|
646
|
-
this.
|
|
612
|
+
if (!this.typed(bytes))
|
|
613
|
+
return;
|
|
614
|
+
const { conn } = this.hub;
|
|
615
|
+
const { session } = this;
|
|
616
|
+
if (!conn || session === undefined)
|
|
617
|
+
return;
|
|
618
|
+
this.deliver(conn, async () => {
|
|
647
619
|
const chunk = pasteChunkSize(conn.welcome.limits);
|
|
648
620
|
for (let at = 0; at < bytes.length; at += chunk) {
|
|
649
621
|
await conn.call("send", { session, data: base64(bytes.subarray(at, at + chunk)) });
|
|
650
622
|
}
|
|
651
623
|
});
|
|
652
624
|
}
|
|
653
|
-
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const channel = this.channel;
|
|
658
|
-
if (bytes.length === 0 || this.readOnly || !conn || !attachment || attachment.ended() || session === undefined) {
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
625
|
+
typed(bytes) {
|
|
626
|
+
const { attachment } = this;
|
|
627
|
+
if (bytes.length === 0 || this.readOnly || !attachment || attachment.ended())
|
|
628
|
+
return false;
|
|
661
629
|
this.claim();
|
|
662
630
|
this.backToLive();
|
|
663
631
|
this.unselect();
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
deliver(conn, send) {
|
|
635
|
+
const { attachment } = this;
|
|
664
636
|
this.inputQueue.enqueueUnlessDetached(() => this.attachment === attachment, async () => {
|
|
665
637
|
try {
|
|
666
|
-
await
|
|
638
|
+
await send();
|
|
667
639
|
}
|
|
668
640
|
catch (err) {
|
|
669
641
|
if (conn === this.hub.conn)
|
|
@@ -740,8 +712,8 @@ class Mount {
|
|
|
740
712
|
this.viewport = size;
|
|
741
713
|
this.profile = profile;
|
|
742
714
|
this.active = active;
|
|
743
|
-
const attachment = this
|
|
744
|
-
if (!
|
|
715
|
+
const { attachment } = this;
|
|
716
|
+
if (!attachment || attachment.ended())
|
|
745
717
|
return;
|
|
746
718
|
this.applyProfile(attachment.term());
|
|
747
719
|
this.paint();
|
|
@@ -749,11 +721,15 @@ class Mount {
|
|
|
749
721
|
this.report();
|
|
750
722
|
}
|
|
751
723
|
report() {
|
|
724
|
+
const line = lineOf(this.snapshot);
|
|
725
|
+
if (!line)
|
|
726
|
+
return;
|
|
752
727
|
this.sizeTakenByOtherClient = false;
|
|
753
|
-
|
|
728
|
+
line.conn.sendJson(FrameType.Viewport, line.channel, { ...this.viewport, profile: this.profile });
|
|
754
729
|
}
|
|
755
730
|
claim() {
|
|
756
|
-
|
|
731
|
+
const { attachment } = this;
|
|
732
|
+
if (this.sizeTakenByOtherClient && this.active && attachment && !attachment.ended())
|
|
757
733
|
this.report();
|
|
758
734
|
}
|
|
759
735
|
focus(focused) {
|
|
@@ -780,9 +756,6 @@ class Mount {
|
|
|
780
756
|
}, () => (this.acking = false));
|
|
781
757
|
}
|
|
782
758
|
}
|
|
783
|
-
function linkEnd(code) {
|
|
784
|
-
return code === "no_such_session" || code === "engine_mismatch" ? code : "error";
|
|
785
|
-
}
|
|
786
759
|
function describe(exit) {
|
|
787
760
|
return "code" in exit ? `code ${exit.code}` : `signal ${exit.signal}`;
|
|
788
761
|
}
|
package/dist/engine/decoder.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type Engine, Terminal } from "./index.ts";
|
|
2
2
|
export declare function readyEnd(buf: Uint8Array, len?: number): number | undefined;
|
|
3
|
+
/** Where the step one decoder `next` call takes ends, from the first record
|
|
4
|
+
* it has not returned: just past the next PAGE or FINISH. After a PAGE the
|
|
5
|
+
* decoder also reads the next known record header, which must be buffered
|
|
6
|
+
* too and starts the next step. */
|
|
3
7
|
export declare function stepEnd(buf: Uint8Array, pos: number, len?: number): number | undefined;
|
|
4
8
|
export declare class Decoder {
|
|
5
9
|
readonly engine: Engine;
|
package/dist/engine/decoder.js
CHANGED
|
@@ -9,6 +9,9 @@ const RECORD_HEADER_LEN = TAG_LEN + PAYLOAD_LENGTH_LEN + CRC32C_LEN;
|
|
|
9
9
|
const TAG_PAGE = 3;
|
|
10
10
|
const TAG_READY = 5;
|
|
11
11
|
const TAG_FINISH = 6;
|
|
12
|
+
/** The record tags the wasm build decodes. It has no Kitty graphics, so it
|
|
13
|
+
* skips Kitty records (tags 8 to 10) whole, as it does any unknown record. */
|
|
14
|
+
const LAST_KNOWN_TAG = 7;
|
|
12
15
|
function recordAt(buf, len, pos) {
|
|
13
16
|
if (pos + RECORD_HEADER_LEN > len)
|
|
14
17
|
return undefined;
|
|
@@ -31,8 +34,36 @@ function endOfStep(buf, len, pos, last) {
|
|
|
31
34
|
export function readyEnd(buf, len = buf.length) {
|
|
32
35
|
return endOfStep(buf, len, ENVELOPE_LEN, (tag) => tag === TAG_READY);
|
|
33
36
|
}
|
|
37
|
+
/** Where the step one decoder `next` call takes ends, from the first record
|
|
38
|
+
* it has not returned: just past the next PAGE or FINISH. After a PAGE the
|
|
39
|
+
* decoder also reads the next known record header, which must be buffered
|
|
40
|
+
* too and starts the next step. */
|
|
34
41
|
export function stepEnd(buf, pos, len = buf.length) {
|
|
35
|
-
|
|
42
|
+
for (;;) {
|
|
43
|
+
const record = recordAt(buf, len, pos);
|
|
44
|
+
if (!record)
|
|
45
|
+
return undefined;
|
|
46
|
+
const [tag, end] = record;
|
|
47
|
+
if (tag === TAG_FINISH)
|
|
48
|
+
return end;
|
|
49
|
+
if (tag === TAG_PAGE)
|
|
50
|
+
return afterPage(buf, len, end);
|
|
51
|
+
pos = end;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function afterPage(buf, len, pos) {
|
|
55
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
56
|
+
for (;;) {
|
|
57
|
+
if (pos + RECORD_HEADER_LEN > len)
|
|
58
|
+
return undefined;
|
|
59
|
+
const tag = view.getUint16(pos, true);
|
|
60
|
+
if (tag >= 1 && tag <= LAST_KNOWN_TAG)
|
|
61
|
+
return pos;
|
|
62
|
+
const record = recordAt(buf, len, pos);
|
|
63
|
+
if (!record)
|
|
64
|
+
return undefined;
|
|
65
|
+
pos = record[1];
|
|
66
|
+
}
|
|
36
67
|
}
|
|
37
68
|
export class Decoder {
|
|
38
69
|
engine;
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -98,5 +98,7 @@ export declare class Terminal {
|
|
|
98
98
|
setColor(kind: "foreground" | "background" | "cursor", color: number): void;
|
|
99
99
|
snapshot(): Uint8Array;
|
|
100
100
|
formatPlain(): string;
|
|
101
|
+
/** Plain text from a formatter, after `configure` sets its options. */
|
|
102
|
+
private format;
|
|
101
103
|
free(): void;
|
|
102
104
|
}
|
package/dist/engine/index.js
CHANGED
|
@@ -361,7 +361,6 @@ export class Terminal {
|
|
|
361
361
|
const coordinate = ptr + e.offsetOf("GhosttyPoint", "value");
|
|
362
362
|
e.view.setUint16(coordinate + e.offsetOf("GhosttyPointCoordinate", "x"), x, true);
|
|
363
363
|
e.view.setUint32(coordinate + e.offsetOf("GhosttyPointCoordinate", "y"), y, true);
|
|
364
|
-
e.view.setUint32(ptr + point, ref, true);
|
|
365
364
|
// The point is passed by value, which the wasm ABI passes by address.
|
|
366
365
|
e.check("ghostty_terminal_grid_ref", this.handle, ptr, ptr + point);
|
|
367
366
|
return e.memory.slice(ptr + point, ptr + point + ref);
|
|
@@ -376,34 +375,20 @@ export class Terminal {
|
|
|
376
375
|
}
|
|
377
376
|
selectionText() {
|
|
378
377
|
const e = this.engine;
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
unwrap: 1,
|
|
382
|
-
trim: 1,
|
|
383
|
-
});
|
|
384
|
-
return e.withBytes(options, (optionsPtr) => e.scratch(8, (out) => {
|
|
385
|
-
e.view.setUint32(out, 0, true);
|
|
386
|
-
e.view.setUint32(out + 4, 0, true);
|
|
387
|
-
// The options are passed by value, which the wasm ABI passes by address.
|
|
388
|
-
if (!e.present("ghostty_terminal_selection_format_alloc", this.handle, 0, optionsPtr, out, out + 4))
|
|
378
|
+
return e.scratch(e.sizeOf("GhosttySelection"), (selection) => {
|
|
379
|
+
if (!e.present("ghostty_terminal_get", this.handle, e.enumValue("GhosttyTerminalData", "SELECTION"), selection)) {
|
|
389
380
|
return undefined;
|
|
390
|
-
const ptr = e.view.getUint32(out, true);
|
|
391
|
-
const len = e.view.getUint32(out + 4, true);
|
|
392
|
-
try {
|
|
393
|
-
return new TextDecoder().decode(e.memory.slice(ptr, ptr + len));
|
|
394
381
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
382
|
+
return this.format((set) => {
|
|
383
|
+
set("SELECTION", selection);
|
|
384
|
+
set("UNWRAP", new Uint8Array([1]));
|
|
385
|
+
});
|
|
386
|
+
});
|
|
399
387
|
}
|
|
400
388
|
get selected() {
|
|
401
389
|
const e = this.engine;
|
|
402
390
|
const size = e.sizeOf("GhosttySelection");
|
|
403
|
-
return e.scratch(size, (out) =>
|
|
404
|
-
e.view.setUint32(out, size, true);
|
|
405
|
-
return e.present("ghostty_terminal_get", this.handle, e.enumValue("GhosttyTerminalData", "SELECTION"), out);
|
|
406
|
-
});
|
|
391
|
+
return e.scratch(size, (out) => e.present("ghostty_terminal_get", this.handle, e.enumValue("GhosttyTerminalData", "SELECTION"), out));
|
|
407
392
|
}
|
|
408
393
|
mode(number) {
|
|
409
394
|
const config = this.engine.pack("GhosttyTerminalModeConfig", { mode: number });
|
|
@@ -424,19 +409,25 @@ export class Terminal {
|
|
|
424
409
|
return this.engine.allocated((ptr, len) => this.engine.check("ghostty_snapshot_encode_alloc", this.handle, 0, ptr, len));
|
|
425
410
|
}
|
|
426
411
|
formatPlain() {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
412
|
+
return this.format((set) => set("TRIM", new Uint8Array([0])));
|
|
413
|
+
}
|
|
414
|
+
/** Plain text from a formatter, after `configure` sets its options. */
|
|
415
|
+
format(configure) {
|
|
416
|
+
const e = this.engine;
|
|
417
|
+
const formatter = e.construct("ghostty_formatter_terminal_new", this.handle);
|
|
418
|
+
try {
|
|
419
|
+
configure((option, value) => {
|
|
420
|
+
const key = e.enumValue("GhosttyFormatterOption", option);
|
|
421
|
+
if (typeof value === "number")
|
|
422
|
+
e.check("ghostty_formatter_set", formatter, key, value);
|
|
423
|
+
else
|
|
424
|
+
e.withBytes(value, (ptr) => e.check("ghostty_formatter_set", formatter, key, ptr));
|
|
425
|
+
});
|
|
426
|
+
return new TextDecoder().decode(e.allocated((ptr, len) => e.check("ghostty_formatter_format_alloc", formatter, 0, ptr, len)));
|
|
427
|
+
}
|
|
428
|
+
finally {
|
|
429
|
+
e.call("ghostty_formatter_free", formatter);
|
|
430
|
+
}
|
|
440
431
|
}
|
|
441
432
|
free() {
|
|
442
433
|
this.engine.call("ghostty_terminal_free", this.handle);
|
package/dist/engine/keys.js
CHANGED
|
@@ -37,7 +37,7 @@ export class KeyEncoder {
|
|
|
37
37
|
}
|
|
38
38
|
encode(term, input) {
|
|
39
39
|
const e = this.engine;
|
|
40
|
-
e.
|
|
40
|
+
e.check("ghostty_key_encoder_set_from_terminal", this.encoder, term.handle);
|
|
41
41
|
const name = keyName(input.code);
|
|
42
42
|
const key = e.hasEnumValue("GhosttyKey", name) ? e.enumValue("GhosttyKey", name) : this.unidentified;
|
|
43
43
|
const composed = input.altComposed === true;
|
|
@@ -53,7 +53,9 @@ export class KeyEncoder {
|
|
|
53
53
|
e.call("ghostty_key_event_set_composing", this.event, input.composing ? 1 : 0);
|
|
54
54
|
const utf8 = new TextEncoder().encode(text);
|
|
55
55
|
return e.withBytes(utf8, (textPtr) => {
|
|
56
|
-
e.
|
|
56
|
+
const string = e.pack("GhosttyString", { ptr: textPtr, len: utf8.length });
|
|
57
|
+
// The string is passed by value, which the wasm ABI passes by address.
|
|
58
|
+
e.withBytes(string, (stringPtr) => e.check("ghostty_key_event_set_utf8", this.event, stringPtr));
|
|
57
59
|
const base = input.unshifted ?? (text ? text.toLowerCase() : "");
|
|
58
60
|
e.call("ghostty_key_event_set_unshifted_codepoint", this.event, base ? base.codePointAt(0) : 0);
|
|
59
61
|
return e.growing("ghostty_key_encoder_encode", 64, (buf, cap, len) => e.call("ghostty_key_encoder_encode", this.encoder, this.event, buf, cap, len));
|
package/dist/engine/pin.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const ENGINE = "ghostty-vt@1.3.2-main+d2865b8";
|
|
1
|
+
export declare const ENGINE = "ghostty-vt@1.0.1";
|
package/dist/engine/pin.js
CHANGED
package/dist/engine/render.d.ts
CHANGED