@gjermundgaraba/clankermux 0.2.0 → 0.4.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.
@@ -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,48 +46,67 @@ 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
106
  * included; `time` in ms, for double and triple clicks. */
87
107
  | {
88
108
  type: "select";
109
+ mount: number;
89
110
  action: "press" | "drag" | "release";
90
111
  at: CellPoint;
91
112
  time: number;
@@ -93,53 +114,101 @@ export type ToWorker =
93
114
  /** Text as typed, which no key sent: a composition's, the emoji picker's. */
94
115
  | {
95
116
  type: "text";
117
+ mount: number;
96
118
  text: string;
97
119
  }
98
120
  /** The wheel: `rows` through the history, up when negative. */
99
121
  | {
100
- type: "scroll";
122
+ type: "wheel";
123
+ mount: number;
101
124
  rows: number;
102
125
  }
126
+ /** The view through the history: `rows` from where it is, up when
127
+ * negative, or back to the live screen. */
128
+ | {
129
+ type: "view";
130
+ mount: number;
131
+ rows: number | "live";
132
+ }
103
133
  /** 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. */
134
+ * looking at, reports them to the session: under the `latest` policy
135
+ * the server applies the latest report, so the session takes the size
136
+ * of the page in use. */
106
137
  | {
107
138
  type: "viewport";
139
+ mount: number;
108
140
  size: Size;
109
141
  profile: Profile;
110
142
  active: boolean;
111
143
  }
144
+ /** The terminal has the keyboard, and its window the focus, or not. */
145
+ | {
146
+ type: "focus";
147
+ mount: number;
148
+ focused: boolean;
149
+ }
112
150
  /** The page lost its drawing: send the whole screen again. */
113
151
  | {
114
152
  type: "repaint";
153
+ mount: number;
115
154
  };
116
155
  /** Messages from the worker to the page. */
117
- export type ToPage = {
156
+ export type ToPage =
157
+ /** The engine loaded: the client is usable. */
158
+ {
159
+ type: "ready";
160
+ }
161
+ /** The engine did not load; nothing else follows. */
162
+ | {
163
+ type: "failed";
164
+ message: string;
165
+ } | {
166
+ type: "reply";
167
+ id: number;
168
+ result?: unknown;
169
+ error?: Failure;
170
+ }
171
+ /** Every session on the server, at each change. */
172
+ | {
173
+ type: "sessions";
174
+ sessions: Session[];
175
+ } | {
176
+ type: "event";
177
+ event: Event;
178
+ }
179
+ /** Events were lost: the server restarted, or more happened while the
180
+ * connection was down than it retains. `sessions` was paged again. */
181
+ | {
182
+ type: "gap";
183
+ incarnation: string;
184
+ }
185
+ /** The connection's own link: `connecting`, `connected` with no
186
+ * session, or `ended`. */
187
+ | {
188
+ type: "connection";
189
+ link: Link;
190
+ } | {
118
191
  type: "status";
192
+ mount: number;
119
193
  text: string;
120
194
  } | {
121
195
  type: "link";
196
+ mount: number;
122
197
  link: Link;
123
- } | {
124
- type: "done";
125
- id: number;
126
- session?: Session;
127
- error?: Failure;
128
198
  } | {
129
199
  type: "frame";
200
+ mount: number;
130
201
  frame: Frame;
131
- } | {
132
- type: "sessions";
133
- sessions: Session[];
134
- current: string | undefined;
135
202
  } | {
136
203
  type: "clipboard";
204
+ mount: number;
137
205
  text: string;
138
206
  }
139
207
  /** The selection's text, or undefined once there is none; `copy`: the
140
208
  * answer to a release, so the text (if any) goes to the clipboard. */
141
209
  | {
142
210
  type: "selection";
211
+ mount: number;
143
212
  text: string | undefined;
144
213
  copy: boolean;
145
214
  };
@@ -148,6 +217,6 @@ export interface WorkerPort {
148
217
  postMessage(message: ToPage): void;
149
218
  onmessage: ((e: MessageEvent<ToWorker>) => void) | null;
150
219
  }
151
- /** Serves a page's `mountTerminal` on `port`: the worker module the page
152
- * starts calls `runWorker(self)`. */
220
+ /** Serves a page's `connect` on `port`: the worker module the page starts
221
+ * calls `runWorker(self)`. */
153
222
  export declare function runWorker(port: WorkerPort): void;