@gjermundgaraba/clankermux 0.3.0 → 0.4.1

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.
@@ -1,21 +1,23 @@
1
1
  /**
2
- * The engine side of a mounted terminal: the connection, the attachment
3
- * and the render state live in a worker; the page draws frames and
4
- * reports input. Imported as `@gjermundgaraba/clankermux/worker`, so a worker
5
- * typechecked without the DOM library does not see the page's types.
2
+ * The engine side of a client: the connection, the attachments and their
3
+ * render state live in a worker; the page draws frames and reports input.
4
+ * One worker serves one `Client` and every terminal mounted from it.
5
+ * Imported as `@gjermundgaraba/clankermux/worker`, so a worker typechecked
6
+ * without the DOM library does not see the page's types.
6
7
  */
7
8
  import { type CellPoint, type Frame, type KeyInput } from "../engine/index.ts";
8
- import { type ErrorCode, type ErrorMessage, type Exit, type OnExit, type Profile, type Session, type Size } from "../proto/index.ts";
9
+ import { type ErrorCode, type ErrorMessage, type Event, type Exit, type Peer, type Profile, type Session, type Size } from "../proto/index.ts";
9
10
  import { type ErrorKind } from "./connection.ts";
10
11
  /** Why the link to the session ended. `closed`: the connection closed
11
12
  * (not a `CLOSED` frame, which the worker does not wait for when it
12
- * detaches); `removed` and `stopping`: the server's `CLOSED`; `exited`:
13
+ * detaches); `removed`, `stopping` and `detached` (another client's
14
+ * `detach`): the server's `CLOSED`; `exited`:
13
15
  * the session's program exited; `no_such_session` and `engine_mismatch`:
14
16
  * an `OPEN` refused; `error`: any other error, the server's or the
15
17
  * client's own. */
16
- export type LinkEnd = "closed" | "removed" | "stopping" | "exited" | "no_such_session" | "engine_mismatch" | "error";
17
- /** The page's link to its session, through the connection and the
18
- * attachment. */
18
+ export type LinkEnd = "closed" | "removed" | "stopping" | "detached" | "exited" | "no_such_session" | "engine_mismatch" | "error";
19
+ /** A terminal's link to its session, through the client's connection and
20
+ * the terminal's attachment. */
19
21
  export type Link =
20
22
  /** Opening a connection; `attempt` counts from 1 and starts again once
21
23
  * a server answers. */
@@ -30,10 +32,10 @@ export type Link =
30
32
  session: Session | undefined;
31
33
  }
32
34
  /** The link ended. `code` and `message` are the error's, when there is
33
- * one; `exit` is the program's, for `exited`. `retry`: the worker
35
+ * one, and `message` the reason a `detach` gave; `exit` is the
36
+ * program's, for `exited`. `retry`: the worker
34
37
  * reconnects or attaches again by itself, so `connecting` or
35
- * `connected` follows; otherwise nothing does until the page attaches
36
- * or creates. */
38
+ * `connected` follows; otherwise nothing does until the page attaches. */
37
39
  | {
38
40
  state: "ended";
39
41
  reason: LinkEnd;
@@ -44,110 +46,186 @@ export type Link =
44
46
  };
45
47
  /** A failed request, as it crosses to the page. */
46
48
  export interface Failure {
47
- /** Absent for a request that needs a session when none is attached. */
48
- kind?: ErrorKind;
49
+ kind: ErrorKind;
49
50
  message: string;
50
51
  server?: ErrorMessage;
51
52
  }
53
+ /** What a mounted terminal starts with. `active`: the user is looking at
54
+ * the page (below). */
55
+ export interface MountInit {
56
+ session: string | undefined;
57
+ viewport: Size;
58
+ profile: Profile;
59
+ active: boolean;
60
+ readOnly: boolean;
61
+ ackOnFocus: boolean;
62
+ }
52
63
  /** Messages from the page to the worker. */
53
- export type ToWorker =
54
- /** `active`: the user is looking at the page (below). */
55
- {
64
+ export type ToWorker = {
56
65
  type: "init";
57
66
  wasm: string;
58
67
  url: string;
59
- viewport: Size;
60
- profile: Profile;
61
- active: boolean;
62
- session: string | undefined;
63
- } | {
64
- type: "attach";
65
- session: string;
68
+ client: Peer | undefined;
66
69
  }
67
- /** Each request is answered by a `done` with its `id`. */
70
+ /** A protocol request, answered by a `reply` with its `id`. */
68
71
  | {
69
- type: "create";
72
+ type: "request";
70
73
  id: number;
71
- onExit?: OnExit;
72
- } | {
73
- type: "end";
74
+ method: string;
75
+ params: unknown;
76
+ }
77
+ /** Cancels the pending `wait` (or `send` with `wait`) of request `id`. */
78
+ | {
79
+ type: "cancel";
74
80
  id: number;
81
+ }
82
+ /** The terminals, each by the page's number for it. */
83
+ | ({
84
+ type: "mount";
85
+ mount: number;
86
+ } & MountInit) | {
87
+ type: "unmount";
88
+ mount: number;
75
89
  } | {
76
- type: "remove";
77
- id: number;
90
+ type: "attach";
91
+ mount: number;
92
+ session: string;
93
+ } | {
94
+ type: "detach";
95
+ mount: number;
78
96
  } | {
79
97
  type: "key";
98
+ mount: number;
80
99
  input: KeyInput;
81
100
  } | {
82
101
  type: "paste";
102
+ mount: number;
83
103
  text: string;
84
104
  }
85
105
  /** The mouse on the canvas, `at` in cells of the viewport, fractions
86
- * included; `time` in ms, for double and triple clicks. */
106
+ * included; `time` in ms, for double and triple clicks. A release has
107
+ * the page's number for its copy, which the answer carries. */
87
108
  | {
88
109
  type: "select";
89
- action: "press" | "drag" | "release";
110
+ mount: number;
111
+ action: "press" | "drag";
90
112
  at: CellPoint;
91
113
  time: number;
114
+ } | {
115
+ type: "select";
116
+ mount: number;
117
+ action: "release";
118
+ at: CellPoint;
119
+ time: number;
120
+ copy: number;
92
121
  }
93
122
  /** Text as typed, which no key sent: a composition's, the emoji picker's. */
94
123
  | {
95
124
  type: "text";
125
+ mount: number;
96
126
  text: string;
97
127
  }
98
128
  /** The wheel: `rows` through the history, up when negative. */
99
129
  | {
100
- type: "scroll";
130
+ type: "wheel";
131
+ mount: number;
101
132
  rows: number;
102
133
  }
134
+ /** The view through the history: `rows` from where it is, up when
135
+ * negative, or back to the live screen. */
136
+ | {
137
+ type: "view";
138
+ mount: number;
139
+ rows: number | "live";
140
+ }
103
141
  /** The page's size and profile. Only an `active` page, one the user is
104
- * looking at, reports them to the session: the server applies the
105
- * latest report, so the session takes the size of the page in use. */
142
+ * looking at, reports them to the session: under the `latest` policy
143
+ * the server applies the latest report, so the session takes the size
144
+ * of the page in use. */
106
145
  | {
107
146
  type: "viewport";
147
+ mount: number;
108
148
  size: Size;
109
149
  profile: Profile;
110
150
  active: boolean;
111
151
  }
152
+ /** The terminal has the keyboard, and its window the focus, or not. */
153
+ | {
154
+ type: "focus";
155
+ mount: number;
156
+ focused: boolean;
157
+ }
112
158
  /** The page lost its drawing: send the whole screen again. */
113
159
  | {
114
160
  type: "repaint";
161
+ mount: number;
115
162
  };
116
163
  /** Messages from the worker to the page. */
117
- export type ToPage = {
164
+ export type ToPage =
165
+ /** The engine loaded: the client is usable. */
166
+ {
167
+ type: "ready";
168
+ }
169
+ /** The engine did not load; nothing else follows. */
170
+ | {
171
+ type: "failed";
172
+ message: string;
173
+ } | {
174
+ type: "reply";
175
+ id: number;
176
+ result?: unknown;
177
+ error?: Failure;
178
+ }
179
+ /** Every session on the server, at each change. */
180
+ | {
181
+ type: "sessions";
182
+ sessions: Session[];
183
+ } | {
184
+ type: "event";
185
+ event: Event;
186
+ }
187
+ /** Events were lost: the server restarted, or more happened while the
188
+ * connection was down than it retains. `sessions` was paged again. */
189
+ | {
190
+ type: "gap";
191
+ incarnation: string;
192
+ }
193
+ /** The connection's own link: `connecting`, `connected` with no
194
+ * session, or `ended`. */
195
+ | {
196
+ type: "connection";
197
+ link: Link;
198
+ } | {
118
199
  type: "status";
200
+ mount: number;
119
201
  text: string;
120
202
  } | {
121
203
  type: "link";
204
+ mount: number;
122
205
  link: Link;
123
- } | {
124
- type: "done";
125
- id: number;
126
- session?: Session;
127
- error?: Failure;
128
206
  } | {
129
207
  type: "frame";
208
+ mount: number;
130
209
  frame: Frame;
131
- } | {
132
- type: "sessions";
133
- sessions: Session[];
134
- current: string | undefined;
135
210
  } | {
136
211
  type: "clipboard";
212
+ mount: number;
137
213
  text: string;
138
214
  }
139
- /** The selection's text, or undefined once there is none; `copy`: the
140
- * answer to a release, so the text (if any) goes to the clipboard. */
215
+ /** The selection's text, or undefined once there is none; with `copy`,
216
+ * the answer to the release of that number, so the text (if any) goes
217
+ * to the clipboard. Every release is answered. */
141
218
  | {
142
219
  type: "selection";
220
+ mount: number;
143
221
  text: string | undefined;
144
- copy: boolean;
222
+ copy?: number;
145
223
  };
146
224
  /** The worker's end of the page's messages: `self` in a dedicated worker. */
147
225
  export interface WorkerPort {
148
226
  postMessage(message: ToPage): void;
149
227
  onmessage: ((e: MessageEvent<ToWorker>) => void) | null;
150
228
  }
151
- /** Serves a page's `mountTerminal` on `port`: the worker module the page
152
- * starts calls `runWorker(self)`. */
229
+ /** Serves a page's `connect` on `port`: the worker module the page starts
230
+ * calls `runWorker(self)`. */
153
231
  export declare function runWorker(port: WorkerPort): void;