@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.
@@ -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
- if (this.connectionLink.state === "ended")
282
- this.reattach(mount);
283
- else if (this.live())
284
- mount.connected();
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
- reattach(mount) {
293
- if (this.connectionLink.state === "ended") {
294
- this.attempt = 0;
295
- void this.connect();
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
- attachment;
306
- channel = 0;
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 (!this.disposed)
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
- if (this.session !== undefined) {
355
- this.open();
356
- }
357
- else {
358
- this.status("no session");
359
- this.link({ state: "connected", session: undefined });
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
- open() {
358
+ offerIfLive() {
363
359
  const conn = this.hub.live();
364
- if (!conn || this.session === undefined || this.disposed || this.openOn === conn)
365
- return;
366
- if (!this.attachment)
367
- this.attachment = new Attachment(this.hub.engine);
368
- const attachment = this.attachment;
369
- attachment.openOn(conn.welcome);
370
- const channel = this.hub.nextChannel();
371
- this.channel = channel;
372
- this.openOn = conn;
373
- const resume = attachment.resume();
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: this.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
- const desync = err instanceof ClientError && err.kind === "desync";
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
- attached(session) {
402
- this.link({ state: "connected", session });
403
- if (session?.status === "exited") {
404
- this.link({ state: "ended", reason: "exited", ...(session.exit && { exit: session.exit }), retry: false });
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.attached(session);
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.link({ state: "connected", session: this.attachment?.session });
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.link({ state: "ended", reason: "exited", exit: action.exit, retry: false });
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.link({
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
- if (!this.attachment?.closed())
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 || this.disposed || !this.visible || this.frameInFlight)
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.close();
589
+ this.step({ type: "page.attach", session, open: this.offerIfLive() });
617
590
  this.inputQueue.stopWaitingOnSendsUnderWay();
618
- this.session = session;
619
- this.hub.reattach(this);
591
+ this.hub.reconnectIfEnded();
620
592
  }
621
593
  detach() {
622
- const had = this.session !== undefined;
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.close();
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.queueInput(bytes, async ({ conn, channel }) => {
642
- conn.send(FrameType.Input, channel, bytes);
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.queueInput(bytes, async ({ conn, session }) => {
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
- queueInput(bytes, deliver) {
654
- const conn = this.hub.conn;
655
- const attachment = this.attachment;
656
- const session = this.session;
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 deliver({ conn, session, channel });
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.attachment;
744
- if (!this.hub.conn || !attachment || attachment.ended())
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
- this.hub.conn?.sendJson(FrameType.Viewport, this.channel, { ...this.viewport, profile: this.profile });
728
+ line.conn.sendJson(FrameType.Viewport, line.channel, { ...this.viewport, profile: this.profile });
754
729
  }
755
730
  claim() {
756
- if (this.sizeTakenByOtherClient && this.active && this.attachment && !this.attachment.ended())
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
  }
@@ -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;
@@ -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
- return endOfStep(buf, len, pos, (tag) => tag === TAG_PAGE || tag === TAG_FINISH);
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;
@@ -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
  }
@@ -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
- const options = e.pack("GhosttyTerminalSelectionFormatOptions", {
380
- emit: e.enumValue("GhosttyFormatterFormat", "PLAIN"),
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
- finally {
396
- e.call("ghostty_free", 0, ptr, len);
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
- const options = this.engine.pack("GhosttyFormatterTerminalOptions", {
428
- emit: this.engine.enumValue("GhosttyFormatterFormat", "PLAIN"),
429
- extra: { screen: {} },
430
- });
431
- return this.engine.withBytes(options, (optionsPtr) => {
432
- const formatter = this.engine.construct("ghostty_formatter_terminal_new", this.handle, optionsPtr);
433
- try {
434
- return new TextDecoder().decode(this.engine.allocated((ptr, len) => this.engine.check("ghostty_formatter_format_alloc", formatter, 0, ptr, len)));
435
- }
436
- finally {
437
- this.engine.call("ghostty_formatter_free", formatter);
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);
@@ -37,7 +37,7 @@ export class KeyEncoder {
37
37
  }
38
38
  encode(term, input) {
39
39
  const e = this.engine;
40
- e.call("ghostty_key_encoder_setopt_from_terminal", this.encoder, term.handle);
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.call("ghostty_key_event_set_utf8", this.event, textPtr, utf8.length);
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));
@@ -1,2 +1 @@
1
- /** Engine id of the vendored libghostty-vt build, matched by the server. */
2
- export declare const ENGINE = "ghostty-vt@1.3.2-main+d2865b8";
1
+ export declare const ENGINE = "ghostty-vt@1.0.1";
@@ -1,3 +1 @@
1
- // Written by scripts/pin.sh from vendor/pin.json.
2
- /** Engine id of the vendored libghostty-vt build, matched by the server. */
3
- export const ENGINE = "ghostty-vt@1.3.2-main+d2865b8";
1
+ export const ENGINE = "ghostty-vt@1.0.1";
@@ -74,6 +74,7 @@ export declare class RenderState {
74
74
  private readonly tags;
75
75
  private readonly wide;
76
76
  private readonly cell;
77
+ private readonly style;
77
78
  private readonly cursorStyles;
78
79
  constructor(engine: Engine);
79
80
  update(term: Terminal): Frame;