@mrciphersmith/roomyx 0.6.2 → 0.6.3
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/CHANGELOG.md +37 -0
- package/README.md +28 -1
- package/package.json +1 -1
- package/src/cli/specs.ts +2 -0
- package/src/cli.ts +40 -1
- package/src/client/clip.ts +26 -0
- package/src/client/components/footer.ts +6 -2
- package/src/client/components/roster-sidebar.ts +1 -28
- package/src/client/components/status-bar.ts +17 -6
- package/src/client/index.ts +200 -226
- package/src/client/keymap.ts +7 -2
- package/src/client/screens/archive-list.ts +152 -0
- package/src/client/screens/chat-view.ts +14 -4
- package/src/client/viewer.ts +231 -0
- package/src/installer/history.ts +154 -0
- package/src/installer/registry.ts +14 -2
package/src/client/index.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
3
|
-
import { join } from "node:path";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
4
3
|
import { createCliRenderer } from "@opentui/core";
|
|
4
|
+
import type { CliRenderer } from "@opentui/core";
|
|
5
5
|
import { RoomClient } from "./mcp-client";
|
|
6
|
-
import { ChatView } from "./screens/chat-view";
|
|
7
|
-
import type { RosterEntry } from "../log/types";
|
|
8
6
|
import { resolveConnectionUrl } from "../installer/resolve-connection";
|
|
9
7
|
import { IDLE, OPENED, ownerPromptLine, stepOwnerPrompt } from "./owner-prompt";
|
|
10
8
|
import type { OwnerPromptState } from "./owner-prompt";
|
|
11
|
-
import { resolveAction } from "./keymap";
|
|
12
|
-
import type { Action } from "./keymap";
|
|
13
9
|
import { livenessLine } from "./liveness";
|
|
14
|
-
import { exportBaseName, nextFreeExportPath } from "./export-name";
|
|
15
10
|
import { createShutdown } from "./shutdown";
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
11
|
+
import { Viewer } from "./viewer";
|
|
12
|
+
import { resolveAction } from "./keymap";
|
|
13
|
+
import { ArchiveList } from "./screens/archive-list";
|
|
14
|
+
import { defaultHistoryPath, readHistory } from "../installer/history";
|
|
15
|
+
import type { RoomHistoryRow } from "../installer/history";
|
|
16
|
+
import { loadRoomLog } from "../log/store";
|
|
18
17
|
import type { ConnectionStatus } from "./mcp-client";
|
|
19
18
|
import { ArgError, parseArgs, renderFlags } from "../cli/args";
|
|
20
19
|
import type { FlagValues } from "../cli/args";
|
|
@@ -26,11 +25,25 @@ import { CLIENT_FLAGS } from "../cli/specs";
|
|
|
26
25
|
* means. They previously had one scanner each, which is how a bare
|
|
27
26
|
* `--registry` became `""` here (and `""` is not nullish, so it beat the
|
|
28
27
|
* default) while becoming `true` in the other.
|
|
28
|
+
*
|
|
29
|
+
* Three modes, and only the first one needs a server: attach to a live room,
|
|
30
|
+
* reread one closed room by path (`--open`), or pick a closed room from the
|
|
31
|
+
* history index (`--archive`). Everything the reader does once a transcript is
|
|
32
|
+
* on screen is the same in all three and lives in `./viewer`.
|
|
29
33
|
*/
|
|
30
34
|
export async function runClient(flags: FlagValues): Promise<void> {
|
|
31
35
|
const registryPath =
|
|
32
36
|
typeof flags.registry === "string" ? flags.registry : join(process.cwd(), ".roomyx", "rooms", "registry.json");
|
|
33
37
|
|
|
38
|
+
if (typeof flags.open === "string") {
|
|
39
|
+
await runArchived(resolve(flags.open), null);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (flags.archive === true) {
|
|
43
|
+
await runArchivePicker(defaultHistoryPath(registryPath));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
const resolved = await resolveConnectionUrl({
|
|
35
48
|
connect: typeof flags.connect === "string" ? flags.connect : undefined,
|
|
36
49
|
room: typeof flags.room === "string" ? flags.room : undefined,
|
|
@@ -40,6 +53,12 @@ export async function runClient(flags: FlagValues): Promise<void> {
|
|
|
40
53
|
if (!resolved.ok) {
|
|
41
54
|
if (resolved.reason === "no-rooms") {
|
|
42
55
|
console.error("No live roomyx rooms found. Start one with `roomyx serve <logPath>` first.");
|
|
56
|
+
// The rooms that have ended are the other half of the answer, and the
|
|
57
|
+
// person who just got "no live rooms" is usually looking for one of them.
|
|
58
|
+
const { rooms } = readHistory(defaultHistoryPath(registryPath));
|
|
59
|
+
if (rooms.length > 0) {
|
|
60
|
+
console.error(`${rooms.length} closed room(s) recorded — reread them with \`roomyx-client --archive\`.`);
|
|
61
|
+
}
|
|
43
62
|
} else if (resolved.reason === "room-not-found") {
|
|
44
63
|
console.error(`No live room with id "${flags.room}". Run \`roomyx rooms list\` to see what's running.`);
|
|
45
64
|
} else {
|
|
@@ -48,59 +67,58 @@ export async function runClient(flags: FlagValues): Promise<void> {
|
|
|
48
67
|
}
|
|
49
68
|
process.exit(1);
|
|
50
69
|
}
|
|
51
|
-
const url = resolved.url;
|
|
52
|
-
|
|
53
|
-
const renderer = await createCliRenderer({ targetFps: 30 });
|
|
54
70
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// compose with search, cost a keypress to leave, and was pinned at hardcoded
|
|
58
|
-
// coordinates across the roster it had been opened from.
|
|
59
|
-
const chatView = new ChatView(renderer, {
|
|
60
|
-
width: renderer.terminalWidth,
|
|
61
|
-
height: renderer.terminalHeight,
|
|
62
|
-
onSelectAgent: (agent: RosterEntry) => applyFilter(agent),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
renderer.root.add(chatView.node);
|
|
66
|
-
|
|
67
|
-
let filtered: RosterEntry | null = null;
|
|
68
|
-
let matchCursor = -1;
|
|
71
|
+
await runLive(resolved.url);
|
|
72
|
+
}
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
matchCursor = -1;
|
|
74
|
-
chatView.scrollToBottom();
|
|
75
|
-
refreshFooter();
|
|
76
|
-
}
|
|
74
|
+
/** Attached to a room that is still running: polling, owner commands, liveness. */
|
|
75
|
+
async function runLive(url: string): Promise<void> {
|
|
76
|
+
const renderer = await createCliRenderer({ targetFps: 30 });
|
|
77
77
|
|
|
78
78
|
let messageCount = 0;
|
|
79
79
|
let lastMessageAt: number | null = null;
|
|
80
80
|
let connection: ConnectionStatus = "connecting";
|
|
81
|
-
let
|
|
81
|
+
let prompt: OwnerPromptState = IDLE;
|
|
82
|
+
|
|
83
|
+
const viewer = new Viewer({
|
|
84
|
+
renderer,
|
|
85
|
+
quit: () => shutdown(0),
|
|
86
|
+
status: () => livenessLine({ status: connection, messageCount, lastMessageAt, now: Date.now() }),
|
|
87
|
+
onOwnerPrompt: () => {
|
|
88
|
+
prompt = OPENED;
|
|
89
|
+
showPrompt();
|
|
90
|
+
},
|
|
91
|
+
// The prompt owns the keyboard while it is open — otherwise typing "q"
|
|
92
|
+
// into a veto would quit the client.
|
|
93
|
+
beforeKey: (event) => {
|
|
94
|
+
if (prompt.stage === "idle") return false;
|
|
95
|
+
const stepped = stepOwnerPrompt(prompt, event);
|
|
96
|
+
prompt = stepped.state;
|
|
97
|
+
showPrompt();
|
|
98
|
+
if (stepped.action.type === "send") {
|
|
99
|
+
const { kind, body } = stepped.action;
|
|
100
|
+
viewer.chatView.statusBar.setNotice(`${kind}: sending…`);
|
|
101
|
+
void roomClient
|
|
102
|
+
.postOwnerCommand(kind, body)
|
|
103
|
+
.then((result) => {
|
|
104
|
+
viewer.chatView.statusBar.setNotice(
|
|
105
|
+
result.accepted
|
|
106
|
+
? `${kind} accepted${result.reason ? ` — ${result.reason}` : ""}`
|
|
107
|
+
: `${kind} not accepted — ${result.reason ?? "no reason given"}`,
|
|
108
|
+
);
|
|
109
|
+
})
|
|
110
|
+
.catch((error: unknown) => {
|
|
111
|
+
viewer.chatView.statusBar.setNotice(
|
|
112
|
+
`${kind} failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
82
119
|
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
// On a terminal too narrow for the roster, the footer is the only place
|
|
86
|
-
// that still says how many people are in the room.
|
|
87
|
-
const here = chatView.isRosterVisible() || participants === 0 ? "" : `${participants} here · `;
|
|
88
|
-
// A filter or a search that is on but invisible is the worst of both: the
|
|
89
|
-
// pane looks like a quiet room. `less` prints a single `&` for the same
|
|
90
|
-
// reason, and k9s puts the live filter in the view title.
|
|
91
|
-
const filterNote = filtered === null ? "" : `filter: ${filtered.name} · `;
|
|
92
|
-
const query = chatView.transcript.currentQuery();
|
|
93
|
-
const total = chatView.transcript.matches().length;
|
|
94
|
-
// `matchCursor` is -1 until a match has been jumped to, and `applyFilter`
|
|
95
|
-
// resets it — so this printed "0/2", a match number that does not exist.
|
|
96
|
-
// Before a position is known, say how many there are.
|
|
97
|
-
const position = matchCursor >= 0 ? `${matchCursor + 1}/${total}` : `${total} matches`;
|
|
98
|
-
const searchNote = query === "" ? "" : `/${query} ${total === 0 ? "no matches" : position} · `;
|
|
99
|
-
chatView.footer.setLiveness(`${filterNote}${searchNote}${here}${liveness}`);
|
|
100
|
-
// Only say something when the reader is *not* where new messages land —
|
|
101
|
-
// a permanent "at bottom" would be another word that always says the same
|
|
102
|
-
// thing, which is the habit this footer exists to break.
|
|
103
|
-
chatView.footer.setScrollNote(chatView.isAtBottom() ? null : "scrolled up · G to follow");
|
|
120
|
+
function showPrompt(): void {
|
|
121
|
+
viewer.chatView.statusBar.setNotice(ownerPromptLine(prompt));
|
|
104
122
|
}
|
|
105
123
|
|
|
106
124
|
const roomClient = new RoomClient(
|
|
@@ -109,34 +127,34 @@ export async function runClient(flags: FlagValues): Promise<void> {
|
|
|
109
127
|
onConnectionChange: (status) => {
|
|
110
128
|
const previous = connection;
|
|
111
129
|
connection = status;
|
|
112
|
-
chatView.setConnectionStatus(status);
|
|
130
|
+
viewer.chatView.setConnectionStatus(status);
|
|
113
131
|
// Also into the transcript, not only the footer: a repainted footer
|
|
114
132
|
// row is never spoken by a screen reader and never survives a `tee`.
|
|
115
133
|
if (previous !== status && previous !== "connecting") {
|
|
116
|
-
chatView.appendSystemLine(status === "connected" ? "reconnected" : "disconnected, retrying");
|
|
134
|
+
viewer.chatView.appendSystemLine(status === "connected" ? "reconnected" : "disconnected, retrying");
|
|
117
135
|
}
|
|
118
|
-
refreshFooter();
|
|
136
|
+
viewer.refreshFooter();
|
|
119
137
|
},
|
|
120
138
|
// The room answered and the answer was an error — usually a malformed
|
|
121
139
|
// line in the log. It reaches the transcript, where it is readable and
|
|
122
140
|
// survives a scroll, rather than being thrown away.
|
|
123
141
|
onToolError: (message) => {
|
|
124
|
-
chatView.appendSystemLine(message);
|
|
125
|
-
refreshFooter();
|
|
142
|
+
viewer.chatView.appendSystemLine(message);
|
|
143
|
+
viewer.refreshFooter();
|
|
126
144
|
},
|
|
127
145
|
onStateUpdate: (state) => {
|
|
128
|
-
chatView.setGoalContract(state.goal_contract);
|
|
129
|
-
chatView.setRoster(state.roster);
|
|
130
|
-
|
|
131
|
-
refreshFooter();
|
|
146
|
+
viewer.chatView.setGoalContract(state.goal_contract);
|
|
147
|
+
viewer.chatView.setRoster(state.roster);
|
|
148
|
+
viewer.setParticipants(state.roster.length);
|
|
149
|
+
viewer.refreshFooter();
|
|
132
150
|
},
|
|
133
151
|
onNewMessages: (messages) => {
|
|
134
|
-
chatView.appendMessages(messages);
|
|
152
|
+
viewer.chatView.appendMessages(messages);
|
|
135
153
|
if (messages.length > 0) {
|
|
136
154
|
messageCount += messages.length;
|
|
137
155
|
lastMessageAt = Date.now();
|
|
138
156
|
}
|
|
139
|
-
refreshFooter();
|
|
157
|
+
viewer.refreshFooter();
|
|
140
158
|
},
|
|
141
159
|
},
|
|
142
160
|
);
|
|
@@ -145,19 +163,8 @@ export async function runClient(flags: FlagValues): Promise<void> {
|
|
|
145
163
|
// The footer carries an age, so it has to repaint on its own — otherwise
|
|
146
164
|
// "last 4s ago" would sit there unchanged through a silence, which is the
|
|
147
165
|
// exact failure it was added to prevent.
|
|
148
|
-
const footerTimer = setInterval(refreshFooter, 1000);
|
|
149
|
-
refreshFooter();
|
|
150
|
-
|
|
151
|
-
let prompt: OwnerPromptState = IDLE;
|
|
152
|
-
|
|
153
|
-
function showPrompt(): void {
|
|
154
|
-
chatView.statusBar.setNotice(ownerPromptLine(prompt));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function openOwnerPrompt(): void {
|
|
158
|
-
prompt = OPENED;
|
|
159
|
-
showPrompt();
|
|
160
|
-
}
|
|
166
|
+
const footerTimer = setInterval(() => viewer.refreshFooter(), 1000);
|
|
167
|
+
viewer.refreshFooter();
|
|
161
168
|
|
|
162
169
|
// The ordering and the re-entry guard live in `./shutdown` so they can be
|
|
163
170
|
// tested; see that file for why the order is the fix. `q`, Ctrl-C and all
|
|
@@ -175,168 +182,135 @@ export async function runClient(flags: FlagValues): Promise<void> {
|
|
|
175
182
|
process.on(signal, () => shutdown(0));
|
|
176
183
|
}
|
|
177
184
|
|
|
178
|
-
|
|
185
|
+
renderer.keyInput.on("keypress", (event) => viewer.handleKey(event));
|
|
186
|
+
}
|
|
179
187
|
|
|
180
|
-
|
|
181
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Rereads a room that has ended. No server, no polling, no reconnect — the log
|
|
190
|
+
* is a finished file, so it is read once and that is the whole of it.
|
|
191
|
+
*
|
|
192
|
+
* The log is loaded *before* the renderer starts. A room log that has been
|
|
193
|
+
* moved, or that has a damaged line, must fail as a printed sentence — entering
|
|
194
|
+
* the alternate screen first and then throwing leaves the terminal in a state
|
|
195
|
+
* the person has to `reset` out of, with the error scrolled away behind it.
|
|
196
|
+
*/
|
|
197
|
+
async function runArchived(logPath: string, closed: RoomHistoryRow | null, renderer?: CliRenderer): Promise<void> {
|
|
198
|
+
let loaded: ReturnType<typeof loadRoomLog>;
|
|
199
|
+
try {
|
|
200
|
+
loaded = loadRoomLog(logPath);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (renderer) renderer.destroy();
|
|
203
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
204
|
+
process.exit(1);
|
|
182
205
|
}
|
|
183
206
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
207
|
+
const active = renderer ?? (await createCliRenderer({ targetFps: 30 }));
|
|
208
|
+
|
|
209
|
+
// Static: nothing here changes after the file is read, so unlike the live
|
|
210
|
+
// client this needs no repaint timer. What it says instead of a liveness age
|
|
211
|
+
// is when the room closed, because "read-only" without a date is the same
|
|
212
|
+
// word forever — the habit this footer exists to break.
|
|
213
|
+
const status =
|
|
214
|
+
`read-only · ${loaded.messages.length} messages` + (closed ? ` · closed ${closed.closedAt.slice(0, 10)}` : "");
|
|
215
|
+
|
|
216
|
+
const shutdown = createShutdown({
|
|
217
|
+
stopClient: async () => undefined,
|
|
218
|
+
destroyRenderer: () => active.destroy(),
|
|
219
|
+
exit: (code) => process.exit(code),
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const viewer = new Viewer({ renderer: active, quit: () => shutdown(0), status: () => status });
|
|
223
|
+
viewer.chatView.setGoalContract(loaded.state.goal_contract);
|
|
224
|
+
viewer.chatView.setRoster(loaded.state.roster);
|
|
225
|
+
viewer.setParticipants(loaded.state.roster.length);
|
|
226
|
+
viewer.chatView.appendMessages(loaded.messages);
|
|
227
|
+
// "closed" rather than a connection state: the status bar's other values all
|
|
228
|
+
// describe a socket, and this room does not have one.
|
|
229
|
+
viewer.chatView.setConnectionStatus("closed");
|
|
230
|
+
viewer.chatView.scrollToTop();
|
|
231
|
+
viewer.refreshFooter();
|
|
195
232
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
* already underway, otherwise the end of the transcript, so the first `n`
|
|
199
|
-
* after a fresh `/` wraps to the earliest match rather than jumping from
|
|
200
|
-
* wherever the last search happened to leave off.
|
|
201
|
-
*/
|
|
202
|
-
function currentEntryIndex(): number {
|
|
203
|
-
const matches = chatView.transcript.matches();
|
|
204
|
-
const at = matches[matchCursor];
|
|
205
|
-
return at ?? -1;
|
|
233
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) {
|
|
234
|
+
process.on(signal, () => shutdown(0));
|
|
206
235
|
}
|
|
207
236
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
function exportTranscript(): void {
|
|
222
|
-
const base = exportBaseName(filtered?.id ?? null);
|
|
223
|
-
const target = nextFreeExportPath(process.cwd(), base, existsSync);
|
|
224
|
-
if (!target.ok) {
|
|
225
|
-
chatView.statusBar.setNotice(
|
|
226
|
-
target.reason === "exhausted"
|
|
227
|
-
? `${base}.txt and 99 numbered siblings all exist — nothing written`
|
|
228
|
-
: "refusing to write outside the working directory",
|
|
229
|
-
);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
// `wx` creates or fails; it never truncates.
|
|
234
|
-
writeFileSync(target.path, `${chatView.transcript.toText()}\n`, { encoding: "utf8", flag: "wx" });
|
|
235
|
-
// The name, not the absolute path: the status bar is one line and
|
|
236
|
-
// truncates, and an absolute path under a deep working directory gets cut
|
|
237
|
-
// exactly where the filename would have been. The file is in the
|
|
238
|
-
// directory the client was started from, which the containment check
|
|
239
|
-
// above now guarantees rather than assumes.
|
|
240
|
-
chatView.statusBar.setNotice(`written to ./${target.name}`);
|
|
241
|
-
} catch (error) {
|
|
242
|
-
chatView.statusBar.setNotice(
|
|
243
|
-
`could not write ./${target.name} — ${error instanceof Error ? error.message : String(error)}`,
|
|
244
|
-
);
|
|
245
|
-
}
|
|
237
|
+
active.keyInput.on("keypress", (event) => viewer.handleKey(event));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The list of closed rooms; Enter opens the highlighted one read-only. */
|
|
241
|
+
async function runArchivePicker(historyPath: string): Promise<void> {
|
|
242
|
+
const { rooms, unreadable } = readHistory(historyPath);
|
|
243
|
+
if (rooms.length === 0) {
|
|
244
|
+
// Printed rather than shown: a full-screen list you have to press q to
|
|
245
|
+
// leave, in order to be told it is empty, is worse than a sentence.
|
|
246
|
+
console.log("No closed rooms recorded yet.");
|
|
247
|
+
console.log("A room is recorded when `roomyx serve` shuts down, or when `roomyx rooms list` finds it gone.");
|
|
248
|
+
if (unreadable > 0) console.log(`${unreadable} history line(s) could not be read and were skipped.`);
|
|
249
|
+
return;
|
|
246
250
|
}
|
|
247
251
|
|
|
248
|
-
renderer
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
const renderer = await createCliRenderer({ targetFps: 30 });
|
|
253
|
+
const list = new ArchiveList(renderer, rooms, {
|
|
254
|
+
width: renderer.terminalWidth,
|
|
255
|
+
height: renderer.terminalHeight,
|
|
256
|
+
unreadable,
|
|
257
|
+
});
|
|
258
|
+
renderer.root.add(list.node);
|
|
255
259
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
else refreshFooter();
|
|
265
|
-
} else if (stepped.action.type === "cancel") {
|
|
266
|
-
chatView.statusBar.setNotice(null);
|
|
267
|
-
}
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
260
|
+
const quit = createShutdown({
|
|
261
|
+
stopClient: async () => undefined,
|
|
262
|
+
destroyRenderer: () => renderer.destroy(),
|
|
263
|
+
exit: (code) => process.exit(code),
|
|
264
|
+
});
|
|
265
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) {
|
|
266
|
+
process.on(signal, () => quit(0));
|
|
267
|
+
}
|
|
270
268
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
269
|
+
// Through the shared keymap rather than its own key comparisons: this is a
|
|
270
|
+
// list of rows navigated with j/k and opened with Enter, which is what the
|
|
271
|
+
// roster already is, and two lists in one client that disagree about which
|
|
272
|
+
// key moves down is exactly the kind of drift a printed keymap is supposed to
|
|
273
|
+
// rule out.
|
|
274
|
+
renderer.keyInput.on("keypress", (event) => {
|
|
275
|
+
switch (resolveAction(event)) {
|
|
276
|
+
// ↑/↓ scroll the transcript in the chat view, but a list has nothing else
|
|
277
|
+
// to scroll — a key that moves in every other list and does nothing here
|
|
278
|
+
// reads as the screen being frozen.
|
|
279
|
+
case "roster.next":
|
|
280
|
+
case "scroll.lineDown":
|
|
281
|
+
list.moveSelection(1);
|
|
282
|
+
break;
|
|
283
|
+
case "roster.prev":
|
|
284
|
+
case "scroll.lineUp":
|
|
285
|
+
list.moveSelection(-1);
|
|
286
|
+
break;
|
|
287
|
+
case "app.quit":
|
|
288
|
+
quit(0);
|
|
289
|
+
break;
|
|
290
|
+
case "roster.open": {
|
|
291
|
+
const room = list.selected();
|
|
292
|
+
if (room === null) return;
|
|
293
|
+
// Freed, not merely unlinked: `remove()` leaves the native yoga nodes
|
|
294
|
+
// and TextBuffers allocated, and the pool is finite. The chat view
|
|
295
|
+
// built next wants those rows back.
|
|
296
|
+
renderer.root.remove(list.node);
|
|
297
|
+
list.destroy();
|
|
298
|
+
void runArchived(room.logPath, room, renderer);
|
|
299
|
+
break;
|
|
294
300
|
}
|
|
295
|
-
|
|
301
|
+
default:
|
|
302
|
+
break;
|
|
296
303
|
}
|
|
297
|
-
|
|
298
|
-
// Any other key clears a leftover result line and falls through.
|
|
299
|
-
chatView.statusBar.setNotice(null);
|
|
300
|
-
|
|
301
|
-
const action = resolveAction(event);
|
|
302
|
-
if (action === null) return;
|
|
303
|
-
|
|
304
|
-
// One row per action rather than a chain of conditions, so the set of
|
|
305
|
-
// things a key can do is a list you can read, and adding one cannot
|
|
306
|
-
// accidentally shadow an earlier branch.
|
|
307
|
-
const half = Math.max(1, Math.floor(chatView.pageSize() / 2));
|
|
308
|
-
const handlers: Record<Action, () => void> = {
|
|
309
|
-
"scroll.lineUp": () => chatView.scrollByLines(-1),
|
|
310
|
-
"scroll.lineDown": () => chatView.scrollByLines(1),
|
|
311
|
-
"scroll.pageUp": () => chatView.scrollByLines(-chatView.pageSize()),
|
|
312
|
-
"scroll.pageDown": () => chatView.scrollByLines(chatView.pageSize()),
|
|
313
|
-
"scroll.halfUp": () => chatView.scrollByLines(-half),
|
|
314
|
-
"scroll.halfDown": () => chatView.scrollByLines(half),
|
|
315
|
-
"scroll.top": () => chatView.scrollToTop(),
|
|
316
|
-
"scroll.bottom": () => chatView.scrollToBottom(),
|
|
317
|
-
"roster.prev": () => chatView.roster.moveSelection(-1),
|
|
318
|
-
"roster.next": () => chatView.roster.moveSelection(1),
|
|
319
|
-
"roster.open": () => chatView.roster.confirmSelection(),
|
|
320
|
-
"filter.clear": () => applyFilter(null),
|
|
321
|
-
"search.open": () => {
|
|
322
|
-
search = opened();
|
|
323
|
-
showSearch();
|
|
324
|
-
},
|
|
325
|
-
"search.next": () => jumpTo(chatView.transcript.nextMatch(currentEntryIndex())),
|
|
326
|
-
"search.previous": () => jumpTo(chatView.transcript.previousMatch(currentEntryIndex())),
|
|
327
|
-
"owner.prompt": () => openOwnerPrompt(),
|
|
328
|
-
"transcript.export": () => exportTranscript(),
|
|
329
|
-
"help.toggle": () => chatView.help.toggle(),
|
|
330
|
-
"app.quit": () => shutdown(0),
|
|
331
|
-
};
|
|
332
|
-
handlers[action]();
|
|
333
|
-
refreshFooter();
|
|
334
304
|
});
|
|
335
305
|
}
|
|
336
306
|
|
|
337
|
-
const CLIENT_USAGE = [
|
|
338
|
-
"
|
|
339
|
-
|
|
307
|
+
const CLIENT_USAGE = [
|
|
308
|
+
"roomyx-client [flags]",
|
|
309
|
+
"",
|
|
310
|
+
" attach the terminal UI to a live room, or reread a closed one",
|
|
311
|
+
"",
|
|
312
|
+
renderFlags(CLIENT_FLAGS),
|
|
313
|
+
].join("\n");
|
|
340
314
|
|
|
341
315
|
if (import.meta.main) {
|
|
342
316
|
void (async () => {
|
package/src/client/keymap.ts
CHANGED
|
@@ -128,9 +128,14 @@ export function resolveAction(event: ParsedKey): Action | null {
|
|
|
128
128
|
* The footer's key hints, in binding order, trimmed to fit `width` by dropping
|
|
129
129
|
* the least useful ones first rather than dropping all of them at once.
|
|
130
130
|
* Returns "" when not even one hint fits.
|
|
131
|
+
*
|
|
132
|
+
* `exclude` drops bindings that do not apply to the surface asking. A closed
|
|
133
|
+
* room has nobody to send an owner command to, and a footer that advertises one
|
|
134
|
+
* anyway is the same failure as the permanent `[connected]` chip this footer
|
|
135
|
+
* was rebuilt to remove: a printed word that is not true of what is on screen.
|
|
131
136
|
*/
|
|
132
|
-
export function footerHints(width = Number.POSITIVE_INFINITY): string {
|
|
133
|
-
const entries = BINDINGS.filter((binding) => binding.footer).map((binding, order) => ({
|
|
137
|
+
export function footerHints(width = Number.POSITIVE_INFINITY, exclude: readonly Action[] = []): string {
|
|
138
|
+
const entries = BINDINGS.filter((binding) => binding.footer && !exclude.includes(binding.action)).map((binding, order) => ({
|
|
134
139
|
order,
|
|
135
140
|
rank: binding.footerRank ?? 0,
|
|
136
141
|
text: `${binding.keys} ${binding.hint}`,
|