@gjermundgaraba/clankermux 0.5.0 → 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 +7 -28
- package/dist/client/attachment.js +24 -31
- package/dist/client/client.d.ts +0 -2
- package/dist/client/client.js +6 -11
- package/dist/client/connection.d.ts +0 -18
- package/dist/client/connection.js +0 -17
- package/dist/client/copy.d.ts +0 -14
- package/dist/client/copy.js +4 -25
- package/dist/client/keyboard.d.ts +1 -27
- package/dist/client/keyboard.js +18 -34
- package/dist/client/listeners.d.ts +3 -1
- package/dist/client/listeners.js +20 -4
- package/dist/client/mount.d.ts +0 -5
- package/dist/client/mount.js +20 -72
- package/dist/client/osc52.d.ts +1 -4
- package/dist/client/osc52.js +20 -17
- package/dist/client/profile.d.ts +0 -6
- package/dist/client/profile.js +0 -6
- package/dist/client/worker.d.ts +0 -7
- package/dist/client/worker.js +84 -204
- package/dist/engine/decoder.d.ts +0 -20
- package/dist/engine/decoder.js +8 -27
- package/dist/engine/index.d.ts +2 -49
- package/dist/engine/index.js +7 -48
- package/dist/engine/keys.d.ts +0 -7
- package/dist/engine/keys.js +9 -15
- package/dist/engine/render.d.ts +7 -18
- package/dist/engine/render.js +32 -32
- package/dist/engine/selection.d.ts +0 -17
- package/dist/engine/selection.js +8 -30
- package/dist/renderer/index.d.ts +3 -4
- package/dist/renderer/index.js +38 -42
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ The browser client of [clankermux](https://github.com/gjermundgaraba/clankermux)
|
|
|
7
7
|
| `.` | `connect`, `Client`, the `Terminal` it mounts, their types, `ClientError` |
|
|
8
8
|
| `./worker` | `runWorker`, for the worker module; no DOM types |
|
|
9
9
|
| `./ghostty-vt.wasm` | the engine build the server's engine id names |
|
|
10
|
-
| `./proto`, `./
|
|
10
|
+
| `./proto`, `./renderer` | the protocol messages and the canvas renderer; `Methods` maps each method to its params and result types, and `Catalog` is what `describe()` answers: the server's methods, events, frames and error codes with their JSON Schemas |
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
13
|
// worker.ts, started as a module worker
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { type Engine, type Terminal } from "../engine/index.ts";
|
|
2
2
|
import { type Closed, type ErrorMessage, type Exit, type Frame, type Resume, type Session, type Welcome } from "../proto/index.ts";
|
|
3
|
-
|
|
4
|
-
export type Action =
|
|
5
|
-
/** The screen is renderable from the local engine. The session may
|
|
6
|
-
* already have exited: see `Attachment.session`. */
|
|
7
|
-
{
|
|
3
|
+
export type Action = {
|
|
8
4
|
type: "screen";
|
|
5
|
+
} | {
|
|
6
|
+
type: "resumed";
|
|
9
7
|
} | {
|
|
10
8
|
type: "output";
|
|
11
9
|
bytes: Uint8Array;
|
|
@@ -16,56 +14,37 @@ export type Action =
|
|
|
16
14
|
} | {
|
|
17
15
|
type: "exited";
|
|
18
16
|
exit: Exit;
|
|
19
|
-
}
|
|
20
|
-
/** Bytes were lost; the terminal was discarded and a new bootstrap follows. */
|
|
21
|
-
| {
|
|
17
|
+
} | {
|
|
22
18
|
type: "gap";
|
|
23
19
|
} | {
|
|
24
20
|
type: "closed";
|
|
25
21
|
reason: Closed["reason"];
|
|
26
22
|
message?: string;
|
|
27
|
-
}
|
|
28
|
-
/** `read_only`, `not_running` and `input_overflow` keep the attachment;
|
|
29
|
-
* any other code ended it. */
|
|
30
|
-
| {
|
|
23
|
+
} | {
|
|
31
24
|
type: "error";
|
|
32
25
|
error: ErrorMessage;
|
|
33
26
|
};
|
|
34
|
-
/**
|
|
35
|
-
* The attachment state machine: frames in, actions out. It keeps the
|
|
36
|
-
* local engine current and tracks the cursor for resuming.
|
|
37
|
-
*/
|
|
38
27
|
export declare class Attachment {
|
|
39
28
|
readonly engine: Engine;
|
|
40
29
|
private state;
|
|
41
30
|
private cursor;
|
|
42
|
-
/** The server the cursor was obtained from, and its limit. */
|
|
43
31
|
private incarnation;
|
|
44
32
|
private continuation;
|
|
45
|
-
|
|
46
|
-
private next;
|
|
33
|
+
private pendingServer;
|
|
47
34
|
session: Session | undefined;
|
|
48
35
|
constructor(engine: Engine);
|
|
49
|
-
/** Records the server an `OPEN` is about to go to; its incarnation
|
|
50
|
-
* becomes the cursor's once that `ATTACHED` arrives. */
|
|
51
36
|
openOn(welcome: Welcome): void;
|
|
52
|
-
/** The cursor to resume from, once the terminal reflects the stream. */
|
|
53
37
|
resume(): Resume | undefined;
|
|
54
38
|
ended(): boolean;
|
|
55
|
-
/** The server ended the attachment (`CLOSED` or a fatal `ERROR`). */
|
|
56
39
|
closed(): boolean;
|
|
57
|
-
/** The local engine, once `READY` has been decoded. */
|
|
58
40
|
term(): Terminal | undefined;
|
|
59
41
|
handle(frame: Frame): Action[];
|
|
60
|
-
/** Releases the engine objects. */
|
|
61
42
|
free(): void;
|
|
62
43
|
private json;
|
|
44
|
+
private assertWellFormed;
|
|
63
45
|
private step;
|
|
64
|
-
/** A stream frame at the cursor. */
|
|
65
46
|
private stream;
|
|
66
47
|
private checkMarker;
|
|
67
|
-
/** Keeps the terminal for display, if there is one. */
|
|
68
48
|
private end;
|
|
69
|
-
/** Frees whatever engine objects the state holds. */
|
|
70
49
|
private discard;
|
|
71
50
|
}
|
|
@@ -2,31 +2,25 @@ import { Decoder } from "../engine/index.js";
|
|
|
2
2
|
import { FrameType, parseOutput, } from "../proto/index.js";
|
|
3
3
|
import { ClientError } from "./connection.js";
|
|
4
4
|
const KEEPS_ATTACHMENT = new Set(["read_only", "not_running", "input_overflow"]);
|
|
5
|
-
/** Payload bytes plus a per-frame charge to bound tiny held frames too. */
|
|
6
5
|
const MAX_HELD_BYTES = 4 * 1024 * 1024;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const HELD_FRAME_OVERHEAD_BYTES = 64;
|
|
7
|
+
function mustHoldUntilSnapshotEnd(held, type) {
|
|
8
|
+
return held.length > 0 || type !== FrameType.Output;
|
|
9
|
+
}
|
|
11
10
|
export class Attachment {
|
|
12
11
|
engine;
|
|
13
12
|
state = { kind: "opening" };
|
|
14
13
|
cursor = { offset: 0, marker: 0 };
|
|
15
|
-
/** The server the cursor was obtained from, and its limit. */
|
|
16
14
|
incarnation = "";
|
|
17
15
|
continuation = 0;
|
|
18
|
-
|
|
19
|
-
next;
|
|
16
|
+
pendingServer;
|
|
20
17
|
session;
|
|
21
18
|
constructor(engine) {
|
|
22
19
|
this.engine = engine;
|
|
23
20
|
}
|
|
24
|
-
/** Records the server an `OPEN` is about to go to; its incarnation
|
|
25
|
-
* becomes the cursor's once that `ATTACHED` arrives. */
|
|
26
21
|
openOn(welcome) {
|
|
27
|
-
this.
|
|
22
|
+
this.pendingServer = { incarnation: welcome.incarnation, continuation: welcome.limits.continuation };
|
|
28
23
|
}
|
|
29
|
-
/** The cursor to resume from, once the terminal reflects the stream. */
|
|
30
24
|
resume() {
|
|
31
25
|
return this.state.kind === "streaming"
|
|
32
26
|
? { incarnation: this.incarnation, offset: this.cursor.offset, marker: this.cursor.marker }
|
|
@@ -35,11 +29,9 @@ export class Attachment {
|
|
|
35
29
|
ended() {
|
|
36
30
|
return this.state.kind === "ended";
|
|
37
31
|
}
|
|
38
|
-
/** The server ended the attachment (`CLOSED` or a fatal `ERROR`). */
|
|
39
32
|
closed() {
|
|
40
|
-
return this.state.kind === "ended" && this.state.
|
|
33
|
+
return this.state.kind === "ended" && this.state.serverClosed;
|
|
41
34
|
}
|
|
42
|
-
/** The local engine, once `READY` has been decoded. */
|
|
43
35
|
term() {
|
|
44
36
|
switch (this.state.kind) {
|
|
45
37
|
case "bootstrapping":
|
|
@@ -56,10 +48,9 @@ export class Attachment {
|
|
|
56
48
|
this.step(frame, actions);
|
|
57
49
|
return actions;
|
|
58
50
|
}
|
|
59
|
-
/** Releases the engine objects. */
|
|
60
51
|
free() {
|
|
61
52
|
this.discard();
|
|
62
|
-
this.state = { kind: "ended", term: undefined,
|
|
53
|
+
this.state = { kind: "ended", term: undefined, serverClosed: true };
|
|
63
54
|
}
|
|
64
55
|
json(frame) {
|
|
65
56
|
try {
|
|
@@ -69,15 +60,18 @@ export class Attachment {
|
|
|
69
60
|
throw ClientError.protocol(`malformed ${frame.header.type}: ${err}`);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
63
|
+
assertWellFormed(frame) {
|
|
64
|
+
this.json(frame);
|
|
65
|
+
}
|
|
72
66
|
step(frame, actions) {
|
|
73
67
|
const type = frame.header.type;
|
|
74
68
|
switch (type) {
|
|
75
69
|
case FrameType.Attached: {
|
|
76
70
|
const attached = this.json(frame);
|
|
77
|
-
if (this.
|
|
78
|
-
this.incarnation = this.
|
|
79
|
-
this.continuation = this.
|
|
80
|
-
this.
|
|
71
|
+
if (this.pendingServer) {
|
|
72
|
+
this.incarnation = this.pendingServer.incarnation;
|
|
73
|
+
this.continuation = this.pendingServer.continuation;
|
|
74
|
+
this.pendingServer = undefined;
|
|
81
75
|
}
|
|
82
76
|
this.cursor = { offset: attached.offset, marker: attached.marker };
|
|
83
77
|
this.session = attached.session;
|
|
@@ -95,7 +89,10 @@ export class Attachment {
|
|
|
95
89
|
}
|
|
96
90
|
this.state = { kind: "bootstrapping", decoder, held: [], heldBytes: 0 };
|
|
97
91
|
}
|
|
98
|
-
else if (this.state.kind
|
|
92
|
+
else if (this.state.kind === "streaming") {
|
|
93
|
+
actions.push({ type: "resumed" });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
99
96
|
throw ClientError.protocol("resume without a terminal");
|
|
100
97
|
}
|
|
101
98
|
break;
|
|
@@ -140,8 +137,8 @@ export class Attachment {
|
|
|
140
137
|
case FrameType.Output:
|
|
141
138
|
case FrameType.Resized:
|
|
142
139
|
case FrameType.Exited:
|
|
143
|
-
if (this.state.kind === "bootstrapping" && (this.state.held
|
|
144
|
-
const bytes = frame.payload.byteLength +
|
|
140
|
+
if (this.state.kind === "bootstrapping" && mustHoldUntilSnapshotEnd(this.state.held, type)) {
|
|
141
|
+
const bytes = frame.payload.byteLength + HELD_FRAME_OVERHEAD_BYTES;
|
|
145
142
|
if (bytes > MAX_HELD_BYTES - this.state.heldBytes) {
|
|
146
143
|
this.end(false);
|
|
147
144
|
throw ClientError.desync("bootstrap stream buffer full; fresh OPEN required");
|
|
@@ -156,8 +153,7 @@ export class Attachment {
|
|
|
156
153
|
this.stream(frame, actions);
|
|
157
154
|
break;
|
|
158
155
|
case FrameType.Gap:
|
|
159
|
-
|
|
160
|
-
this.json(frame);
|
|
156
|
+
this.assertWellFormed(frame);
|
|
161
157
|
this.discard();
|
|
162
158
|
actions.push({ type: "gap" });
|
|
163
159
|
break;
|
|
@@ -178,7 +174,6 @@ export class Attachment {
|
|
|
178
174
|
throw ClientError.protocol(`${type} on an attachment`);
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
|
-
/** A stream frame at the cursor. */
|
|
182
177
|
stream(frame, actions) {
|
|
183
178
|
switch (frame.header.type) {
|
|
184
179
|
case FrameType.Output: {
|
|
@@ -218,8 +213,7 @@ export class Attachment {
|
|
|
218
213
|
}
|
|
219
214
|
this.cursor.marker = seq;
|
|
220
215
|
}
|
|
221
|
-
|
|
222
|
-
end(closed) {
|
|
216
|
+
end(serverClosed) {
|
|
223
217
|
let term;
|
|
224
218
|
switch (this.state.kind) {
|
|
225
219
|
case "bootstrapping":
|
|
@@ -230,9 +224,8 @@ export class Attachment {
|
|
|
230
224
|
term = this.state.term;
|
|
231
225
|
break;
|
|
232
226
|
}
|
|
233
|
-
this.state = { kind: "ended", term,
|
|
227
|
+
this.state = { kind: "ended", term, serverClosed };
|
|
234
228
|
}
|
|
235
|
-
/** Frees whatever engine objects the state holds. */
|
|
236
229
|
discard() {
|
|
237
230
|
switch (this.state.kind) {
|
|
238
231
|
case "bootstrapping":
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** The page side of a client: one worker, one connection, the control
|
|
2
|
-
* surface, and the terminals mounted from it. */
|
|
3
1
|
import type { Acked, Catalog, CreateParams, Description, Event, Page, Peer, Read, ReadParams, ResizeParams, SendParams, Sent, Session, StreamCursor, Tail, Until, Waited } from "../proto/index.ts";
|
|
4
2
|
import { type MountOptions, type Terminal } from "./mount.ts";
|
|
5
3
|
import type { Link, ToWorker } from "./worker.ts";
|
package/dist/client/client.js
CHANGED
|
@@ -43,17 +43,14 @@ export class Client {
|
|
|
43
43
|
/** @internal Use `connect`. */
|
|
44
44
|
constructor(worker, started) {
|
|
45
45
|
this.worker = worker;
|
|
46
|
-
|
|
47
|
-
// would never settle. Once it runs, an error event is an exception in
|
|
48
|
-
// one of its handlers, which costs that message only: the browser
|
|
49
|
-
// reports it, and the client goes on.
|
|
50
|
-
worker.onerror = (e) => {
|
|
46
|
+
const failStartIfWorkerDidNotLoad = (e) => {
|
|
51
47
|
if (this.started)
|
|
52
48
|
return;
|
|
53
49
|
e.preventDefault();
|
|
54
50
|
started(new Error(`the worker failed: ${e.message || "it did not load"}`));
|
|
55
51
|
this.close();
|
|
56
52
|
};
|
|
53
|
+
worker.onerror = failStartIfWorkerDidNotLoad;
|
|
57
54
|
worker.onmessage = (e) => {
|
|
58
55
|
const message = e.data;
|
|
59
56
|
switch (message.type) {
|
|
@@ -104,16 +101,14 @@ export class Client {
|
|
|
104
101
|
return Promise.reject(new ClientError("closed", "closed"));
|
|
105
102
|
const id = this.nextId++;
|
|
106
103
|
return new Promise((resolve, reject) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const cancel = () => this.post({ type: "cancel", id });
|
|
110
|
-
const done = () => signal?.removeEventListener("abort", cancel);
|
|
104
|
+
const cancelOnServer = () => this.post({ type: "cancel", id });
|
|
105
|
+
const done = () => signal?.removeEventListener("abort", cancelOnServer);
|
|
111
106
|
this.pending.set(id, { resolve: resolve, reject, done });
|
|
112
107
|
this.post({ type: "request", id, method, params });
|
|
113
108
|
if (signal?.aborted)
|
|
114
|
-
|
|
109
|
+
cancelOnServer();
|
|
115
110
|
else
|
|
116
|
-
signal?.addEventListener("abort",
|
|
111
|
+
signal?.addEventListener("abort", cancelOnServer, { once: true });
|
|
117
112
|
});
|
|
118
113
|
}
|
|
119
114
|
describe(method) {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { type Catalog, type Description, type ErrorCode, type ErrorMessage, type Event, type Frame, FrameType, type Hello, type Peer, type Welcome } from "../proto/index.ts";
|
|
2
|
-
/** A message-oriented byte transport: one frame per message, as over WebSocket. */
|
|
3
2
|
export interface Transport {
|
|
4
3
|
send(bytes: Uint8Array): void;
|
|
5
4
|
close(): void;
|
|
6
5
|
onMessage: ((bytes: Uint8Array) => void) | undefined;
|
|
7
6
|
onClose: (() => void) | undefined;
|
|
8
7
|
}
|
|
9
|
-
/** `desync`: a stream frame did not continue from the cursor; a fresh
|
|
10
|
-
* OPEN recovers it, where any other fault would only repeat. */
|
|
11
8
|
export type ErrorKind = "protocol" | "desync" | "server" | "closed";
|
|
12
9
|
/** A failed request or connection. `kind: "server"` carries the server's
|
|
13
10
|
* `ERROR` as `server`, and its code as `code`: a refused request, or a
|
|
@@ -22,13 +19,7 @@ export declare class ClientError extends Error {
|
|
|
22
19
|
static desync(message: string): ClientError;
|
|
23
20
|
static fromServer(error: ErrorMessage): ClientError;
|
|
24
21
|
}
|
|
25
|
-
/** `HELLO` for `client`: a name and version, or a name with this
|
|
26
|
-
* package's version. */
|
|
27
22
|
export declare function hello(client: string | Peer, engine?: string): Hello;
|
|
28
|
-
/**
|
|
29
|
-
* One protocol connection: the handshake, requests answered by id, events,
|
|
30
|
-
* and attachment channels routed to their receivers.
|
|
31
|
-
*/
|
|
32
23
|
export declare class Connection {
|
|
33
24
|
private readonly transport;
|
|
34
25
|
readonly welcome: Welcome;
|
|
@@ -36,29 +27,20 @@ export declare class Connection {
|
|
|
36
27
|
private readonly pending;
|
|
37
28
|
private readonly channels;
|
|
38
29
|
private ended;
|
|
39
|
-
/** Session events, once subscribed. */
|
|
40
30
|
onEvent: ((event: Event) => void) | undefined;
|
|
41
|
-
/** The connection ended: the transport closed, or an error without id. */
|
|
42
31
|
onEnd: ((error: ClientError) => void) | undefined;
|
|
43
32
|
private constructor();
|
|
44
|
-
/** Sends `HELLO` and resolves at `WELCOME`; rejects on an `ERROR` or close. */
|
|
45
33
|
static connect(transport: Transport, hello: Hello): Promise<Connection>;
|
|
46
34
|
send(type: FrameType, channel: number, payload: Uint8Array): void;
|
|
47
35
|
sendJson(type: FrameType, channel: number, body: unknown): void;
|
|
48
|
-
/** A request; the reply's `result`, or a rejection with the server's error. */
|
|
49
36
|
call<R>(method: string, params: unknown): Promise<R>;
|
|
50
|
-
/** A request and its id on this connection, which `cancel` takes. */
|
|
51
37
|
request<R>(method: string, params: unknown): {
|
|
52
38
|
id: number;
|
|
53
39
|
reply: Promise<R>;
|
|
54
40
|
};
|
|
55
|
-
/** The server's catalog (`describe {}`), or one method of it. */
|
|
56
41
|
describe(): Promise<Catalog>;
|
|
57
42
|
describe(method: string): Promise<Description>;
|
|
58
|
-
/** Opens `channel`; its frames go to `receive` until `release` or the
|
|
59
|
-
* connection's end. */
|
|
60
43
|
open(channel: number, open: unknown, receive: (frame: Frame) => void): void;
|
|
61
|
-
/** Stops routing `channel`; later frames on it are dropped. */
|
|
62
44
|
release(channel: number): void;
|
|
63
45
|
close(): void;
|
|
64
46
|
private route;
|
|
@@ -25,11 +25,7 @@ export class ClientError extends Error {
|
|
|
25
25
|
return new ClientError("server", `${error.code}: ${error.message}`, error);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
/** Frames before `WELCOME` tells us the real limit: the protocol's
|
|
29
|
-
* default `max_frame`, as the Rust client. */
|
|
30
28
|
const HELLO_MAX_FRAME = 1024 * 1024;
|
|
31
|
-
/** `HELLO` for `client`: a name and version, or a name with this
|
|
32
|
-
* package's version. */
|
|
33
29
|
export function hello(client, engine) {
|
|
34
30
|
const peer = typeof client === "string" ? { name: client, version: pkg.version } : client;
|
|
35
31
|
const h = { version: VERSION, client: peer, capabilities: [] };
|
|
@@ -37,10 +33,6 @@ export function hello(client, engine) {
|
|
|
37
33
|
h.engine = engine;
|
|
38
34
|
return h;
|
|
39
35
|
}
|
|
40
|
-
/**
|
|
41
|
-
* One protocol connection: the handshake, requests answered by id, events,
|
|
42
|
-
* and attachment channels routed to their receivers.
|
|
43
|
-
*/
|
|
44
36
|
export class Connection {
|
|
45
37
|
transport;
|
|
46
38
|
welcome;
|
|
@@ -48,9 +40,7 @@ export class Connection {
|
|
|
48
40
|
pending = new Map();
|
|
49
41
|
channels = new Map();
|
|
50
42
|
ended;
|
|
51
|
-
/** Session events, once subscribed. */
|
|
52
43
|
onEvent;
|
|
53
|
-
/** The connection ended: the transport closed, or an error without id. */
|
|
54
44
|
onEnd;
|
|
55
45
|
constructor(transport, welcome) {
|
|
56
46
|
this.transport = transport;
|
|
@@ -58,7 +48,6 @@ export class Connection {
|
|
|
58
48
|
transport.onMessage = (bytes) => this.route(bytes);
|
|
59
49
|
transport.onClose = () => this.end(new ClientError("closed", "connection closed"));
|
|
60
50
|
}
|
|
61
|
-
/** Sends `HELLO` and resolves at `WELCOME`; rejects on an `ERROR` or close. */
|
|
62
51
|
static connect(transport, hello) {
|
|
63
52
|
return new Promise((resolve, reject) => {
|
|
64
53
|
transport.onMessage = (bytes) => {
|
|
@@ -91,11 +80,9 @@ export class Connection {
|
|
|
91
80
|
sendJson(type, channel, body) {
|
|
92
81
|
this.send(type, channel, new TextEncoder().encode(JSON.stringify(body)));
|
|
93
82
|
}
|
|
94
|
-
/** A request; the reply's `result`, or a rejection with the server's error. */
|
|
95
83
|
call(method, params) {
|
|
96
84
|
return this.request(method, params).reply;
|
|
97
85
|
}
|
|
98
|
-
/** A request and its id on this connection, which `cancel` takes. */
|
|
99
86
|
request(method, params) {
|
|
100
87
|
const id = this.nextId++;
|
|
101
88
|
const reply = new Promise((resolve, reject) => {
|
|
@@ -113,15 +100,12 @@ export class Connection {
|
|
|
113
100
|
describe(method) {
|
|
114
101
|
return this.call("describe", method === undefined ? {} : { method });
|
|
115
102
|
}
|
|
116
|
-
/** Opens `channel`; its frames go to `receive` until `release` or the
|
|
117
|
-
* connection's end. */
|
|
118
103
|
open(channel, open, receive) {
|
|
119
104
|
if (this.ended)
|
|
120
105
|
throw this.ended;
|
|
121
106
|
this.channels.set(channel, receive);
|
|
122
107
|
this.sendJson(FrameType.Open, channel, open);
|
|
123
108
|
}
|
|
124
|
-
/** Stops routing `channel`; later frames on it are dropped. */
|
|
125
109
|
release(channel) {
|
|
126
110
|
this.channels.delete(channel);
|
|
127
111
|
}
|
|
@@ -151,7 +135,6 @@ export class Connection {
|
|
|
151
135
|
}
|
|
152
136
|
switch (frame.header.type) {
|
|
153
137
|
case FrameType.Reply: {
|
|
154
|
-
// A reply or error for a request no longer waited for is dropped.
|
|
155
138
|
const reply = body;
|
|
156
139
|
this.pending.get(reply.id)?.resolve(reply.result);
|
|
157
140
|
this.pending.delete(reply.id);
|
package/dist/client/copy.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** The page's copies to the clipboard, and what each came to. */
|
|
2
1
|
/** What started a copy: the release of a selection, Ctrl+Shift+C, the
|
|
3
2
|
* browser's copy (Cmd+C, the Copy menu), or the program (OSC 52). */
|
|
4
3
|
export type CopySource = "release" | "keys" | "browser" | "program";
|
|
@@ -19,26 +18,19 @@ export type Copy = {
|
|
|
19
18
|
chars?: number;
|
|
20
19
|
message?: string;
|
|
21
20
|
};
|
|
22
|
-
/** The parts of `navigator.clipboard` a copy uses. */
|
|
23
21
|
export interface ClipboardLike {
|
|
24
22
|
write?(items: ClipboardItem[]): Promise<void>;
|
|
25
23
|
writeText?(text: string): Promise<void>;
|
|
26
24
|
}
|
|
27
25
|
export interface CopyHost {
|
|
28
|
-
/** The clipboard, read at each copy; undefined where there is none. */
|
|
29
26
|
clipboard(): ClipboardLike | undefined;
|
|
30
|
-
/** A `ClipboardItem` of text to come; undefined where the browser has
|
|
31
|
-
* no `ClipboardItem`. */
|
|
32
27
|
item: ((text: Promise<Blob>) => ClipboardItem) | undefined;
|
|
33
28
|
report(copy: Copy): void;
|
|
34
29
|
}
|
|
35
|
-
/** A mounted terminal's copies. */
|
|
36
30
|
export declare class Copier {
|
|
37
31
|
private readonly host;
|
|
38
|
-
/** The latest release's copy, while it waits for the worker's answer. */
|
|
39
32
|
private pending;
|
|
40
33
|
private next;
|
|
41
|
-
/** Every copy not yet reported or dropped, for `dispose`. */
|
|
42
34
|
private readonly live;
|
|
43
35
|
constructor(host: CopyHost);
|
|
44
36
|
/** Starts the copy of what a release selected, and returns its number
|
|
@@ -50,15 +42,9 @@ export declare class Copier {
|
|
|
50
42
|
* release's copy still waiting is dropped, so the clipboard gets the
|
|
51
43
|
* latest. */
|
|
52
44
|
start(): number;
|
|
53
|
-
/** The worker's answer to release `id`: the selected text, or undefined
|
|
54
|
-
* when nothing was selected, which is no copy. An answer to a copy that
|
|
55
|
-
* was dropped or timed out is ignored. */
|
|
56
45
|
answer(id: number, text: string | undefined): void;
|
|
57
|
-
/** Copies `text` known now. */
|
|
58
46
|
write(text: string, source: CopySource): void;
|
|
59
|
-
/** A copy the browser made itself (the `copy` event's data). */
|
|
60
47
|
copied(text: string): void;
|
|
61
|
-
/** Drops every copy under way, unreported. */
|
|
62
48
|
dispose(): void;
|
|
63
49
|
private attempt;
|
|
64
50
|
private dropOne;
|
package/dist/client/copy.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/** The page's copies to the clipboard, and what each came to. */
|
|
2
|
-
/** How long a copy may take: the worker's answer and the write. */
|
|
3
1
|
const COPY_TIMEOUT_MS = 2000;
|
|
4
|
-
|
|
5
|
-
const length = (text) => [...text].length;
|
|
6
|
-
/** One copy under way, reported once: when both its text's length and
|
|
7
|
-
* the write's result are known, or at the timeout. */
|
|
2
|
+
const codePointLength = (text) => [...text].length;
|
|
8
3
|
class Attempt {
|
|
9
4
|
source;
|
|
10
5
|
report;
|
|
@@ -13,11 +8,7 @@ class Attempt {
|
|
|
13
8
|
chars;
|
|
14
9
|
result;
|
|
15
10
|
timer;
|
|
16
|
-
constructor(source, report,
|
|
17
|
-
/** Once, when it is reported or dropped. */
|
|
18
|
-
ended,
|
|
19
|
-
/** At the timeout, after the report. */
|
|
20
|
-
timedOut) {
|
|
11
|
+
constructor(source, report, ended, timedOut) {
|
|
21
12
|
this.source = source;
|
|
22
13
|
this.report = report;
|
|
23
14
|
this.ended = ended;
|
|
@@ -27,14 +18,13 @@ class Attempt {
|
|
|
27
18
|
}, COPY_TIMEOUT_MS);
|
|
28
19
|
}
|
|
29
20
|
text(text) {
|
|
30
|
-
this.chars =
|
|
21
|
+
this.chars = codePointLength(text);
|
|
31
22
|
this.settle();
|
|
32
23
|
}
|
|
33
24
|
wrote(result) {
|
|
34
25
|
this.result ??= result;
|
|
35
26
|
this.settle();
|
|
36
27
|
}
|
|
37
|
-
/** Not a copy: nothing was selected, or a newer copy took its place. */
|
|
38
28
|
drop() {
|
|
39
29
|
if (this.done)
|
|
40
30
|
return;
|
|
@@ -56,18 +46,14 @@ class Attempt {
|
|
|
56
46
|
else
|
|
57
47
|
this.report({ source: this.source, ...result, ...(chars !== undefined ? { chars } : {}) });
|
|
58
48
|
}
|
|
59
|
-
/** Follows a write's promise. */
|
|
60
49
|
follow(write) {
|
|
61
50
|
write.then(() => this.wrote({ ok: true }), (err) => this.wrote({ ok: false, reason: "refused", message: String(err) }));
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
|
-
/** A mounted terminal's copies. */
|
|
65
53
|
export class Copier {
|
|
66
54
|
host;
|
|
67
|
-
/** The latest release's copy, while it waits for the worker's answer. */
|
|
68
55
|
pending;
|
|
69
56
|
next = 1;
|
|
70
|
-
/** Every copy not yet reported or dropped, for `dispose`. */
|
|
71
57
|
live = new Set();
|
|
72
58
|
constructor(host) {
|
|
73
59
|
this.host = host;
|
|
@@ -86,7 +72,6 @@ export class Copier {
|
|
|
86
72
|
const id = this.next++;
|
|
87
73
|
const pending = {
|
|
88
74
|
id,
|
|
89
|
-
// At the timeout the write is left without its text.
|
|
90
75
|
attempt: this.attempt("release", () => {
|
|
91
76
|
if (this.pending === pending)
|
|
92
77
|
this.pending = undefined;
|
|
@@ -119,9 +104,6 @@ export class Copier {
|
|
|
119
104
|
pending.attempt.follow(clipboard.write([item]));
|
|
120
105
|
return id;
|
|
121
106
|
}
|
|
122
|
-
/** The worker's answer to release `id`: the selected text, or undefined
|
|
123
|
-
* when nothing was selected, which is no copy. An answer to a copy that
|
|
124
|
-
* was dropped or timed out is ignored. */
|
|
125
107
|
answer(id, text) {
|
|
126
108
|
const pending = this.pending;
|
|
127
109
|
if (pending?.id !== id)
|
|
@@ -135,17 +117,14 @@ export class Copier {
|
|
|
135
117
|
else
|
|
136
118
|
this.writeText(pending.attempt, text);
|
|
137
119
|
}
|
|
138
|
-
/** Copies `text` known now. */
|
|
139
120
|
write(text, source) {
|
|
140
121
|
const attempt = this.attempt(source);
|
|
141
122
|
attempt.text(text);
|
|
142
123
|
this.writeText(attempt, text);
|
|
143
124
|
}
|
|
144
|
-
/** A copy the browser made itself (the `copy` event's data). */
|
|
145
125
|
copied(text) {
|
|
146
|
-
this.host.report({ ok: true, source: "browser", chars:
|
|
126
|
+
this.host.report({ ok: true, source: "browser", chars: codePointLength(text) });
|
|
147
127
|
}
|
|
148
|
-
/** Drops every copy under way, unreported. */
|
|
149
128
|
dispose() {
|
|
150
129
|
if (this.pending)
|
|
151
130
|
this.dropOne(this.pending);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type KeyInput } from "../engine/index.ts";
|
|
2
|
-
/** The parts of a `KeyboardEvent` the mapping reads. */
|
|
3
2
|
export interface KeyEventLike {
|
|
4
3
|
type: string;
|
|
5
4
|
code: string;
|
|
@@ -10,56 +9,31 @@ export interface KeyEventLike {
|
|
|
10
9
|
altKey: boolean;
|
|
11
10
|
metaKey: boolean;
|
|
12
11
|
isComposing: boolean;
|
|
13
|
-
/** 229 while an input method processes the key. */
|
|
14
12
|
keyCode: number;
|
|
15
13
|
}
|
|
16
|
-
/** The parts of an `InputEvent` the input element reads. */
|
|
17
14
|
export interface InputEventLike {
|
|
18
15
|
inputType: string;
|
|
19
16
|
data: string | null;
|
|
20
17
|
isComposing: boolean;
|
|
21
18
|
}
|
|
22
|
-
/** What typing comes to: a key for the key encoder, or text as typed. */
|
|
23
19
|
export type Typed = {
|
|
24
20
|
key: KeyInput;
|
|
25
21
|
} | {
|
|
26
22
|
text: string;
|
|
27
23
|
};
|
|
28
|
-
/** What the page knows about the keyboard: the layout's unmodified
|
|
29
|
-
* character per `code` when the browser exposes it, and the platform. */
|
|
30
24
|
export interface Keyboard {
|
|
31
25
|
layout: ReadonlyMap<string, string> | undefined;
|
|
32
26
|
mac: boolean;
|
|
33
27
|
}
|
|
34
|
-
/** Whether the browser keeps the key: its own shortcuts with the platform's
|
|
35
|
-
* command modifier, and Ctrl+Shift+V, the paste shortcut where Ctrl+V is
|
|
36
|
-
* the terminal's. */
|
|
37
28
|
export declare function browserKeeps(e: KeyEventLike): boolean;
|
|
38
|
-
/** Whether the key belongs to an input method: it is composing, or
|
|
39
|
-
* processing the key (`Process`, key code 229), or the key is a dead key
|
|
40
|
-
* that starts a composition. Its text arrives at `compositionend`. */
|
|
41
29
|
export declare function composing(e: KeyEventLike): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Typing on the terminal's input element, a textarea: keys go to the key
|
|
44
|
-
* encoder, and text that no key sent goes as text. Keys the browser keeps
|
|
45
|
-
* and keys of a composition are left to the browser; a composition's text
|
|
46
|
-
* is sent when it ends, and text inserted without a key (a dead key's
|
|
47
|
-
* character, the emoji picker, dictation) as it is inserted.
|
|
48
|
-
*/
|
|
49
30
|
export declare class Typing {
|
|
50
31
|
private readonly keyboard;
|
|
51
|
-
|
|
52
|
-
* ended a composition sends no release of a press it never sent. */
|
|
53
|
-
private readonly down;
|
|
32
|
+
private readonly pressesSent;
|
|
54
33
|
constructor(keyboard: Keyboard);
|
|
55
|
-
/** A key to send, or undefined to leave the event to the browser. */
|
|
56
34
|
keydown(e: KeyEventLike): KeyInput | undefined;
|
|
57
35
|
keyup(e: KeyEventLike): KeyInput | undefined;
|
|
58
|
-
/** `beforeinput`: what the element would insert or delete, when no key
|
|
59
|
-
* sent it. A composition's own steps wait for `compositionend`; a paste
|
|
60
|
-
* is the `paste` event's. */
|
|
61
36
|
beforeinput(e: InputEventLike): Typed | undefined;
|
|
62
|
-
/** `compositionend`: the composed text. */
|
|
63
37
|
compositionend(data: string | null): Typed | undefined;
|
|
64
38
|
}
|
|
65
39
|
export declare function keyInput(e: KeyEventLike, keyboard: Keyboard): KeyInput;
|