@alexsun-top/opencode-chat-room 0.8.4 → 0.8.5
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 +5 -1
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +14 -11
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin.js +4 -1
- package/server/assets/chat/announcements.js +3 -0
- package/server/assets/chat/attachments.js +3 -3
- package/server/assets/chat/clipboard.js +1 -1
- package/server/assets/chat/copy-action.js +1 -1
- package/server/assets/chat/doc-preview.js +1 -1
- package/server/assets/chat/editor.js +11 -7
- package/server/assets/chat/events.js +7 -5
- package/server/assets/chat/files.js +5 -1
- package/server/assets/chat/integration-editor.js +2 -0
- package/server/assets/chat/integrations.js +1 -1
- package/server/assets/chat/join-requests.js +1 -1
- package/server/assets/chat/markdown-footnotes.js +8 -7
- package/server/assets/chat/markdown.js +6 -5
- package/server/assets/chat/members.js +3 -3
- package/server/assets/chat/mentions.js +8 -5
- package/server/assets/chat/message-cache.js +1 -1
- package/server/assets/chat/message-polling.js +2 -2
- package/server/assets/chat/message-window.js +1 -1
- package/server/assets/chat/messages.js +17 -3
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +5 -3
- package/server/assets/chat/panels.js +19 -0
- package/server/assets/chat/questions.js +3 -2
- package/server/assets/chat/reminders.js +3 -0
- package/server/assets/chat/replies.js +6 -3
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/rooms.js +7 -4
- package/server/assets/chat/settings.js +4 -3
- package/server/assets/chat/shortcuts.js +3 -1
- package/server/assets/chat/side-pane.js +1 -1
- package/server/assets/chat/state.js +30 -11
- package/server/assets/chat/system-events.js +3 -2
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/tasks.js +4 -3
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +257 -242
- package/src/tui/room-settings-app.mts +301 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
// State-to-renderable syncing for the OpenTUI view. These functions rebuild
|
|
2
|
+
// message and room rows only when their signature changes.
|
|
3
|
+
import { BoxRenderable, StyledText, TextRenderable, bold, fg } from "@opentui/core";
|
|
4
|
+
import type { CliRenderer, SyntaxStyle, TextChunk, ThemeMode } from "@opentui/core";
|
|
5
|
+
import { formatMessage, messageStamp, sanitizeText } from "./messages.mjs";
|
|
6
|
+
import type { ChatMessage, Participant } from "./messages.mjs";
|
|
7
|
+
import { addNotice, buildMessageBlock, hashText, markdownStyle } from "./message-view.mjs";
|
|
8
|
+
import { syncMentionHighlights } from "./ui-mentions.mjs";
|
|
9
|
+
import { connectionStyle } from "./ui-theme.mjs";
|
|
10
|
+
import type { TuiTheme } from "./ui-theme.mjs";
|
|
11
|
+
import { t } from "./i18n.mjs";
|
|
12
|
+
import type { Command, PaletteRoom, SearchResult } from "./palette.mjs";
|
|
13
|
+
import type { createView } from "./ui-view.mjs";
|
|
14
|
+
|
|
15
|
+
type View = ReturnType<typeof createView>;
|
|
16
|
+
type ContentRoom = PaletteRoom & { participants: readonly Participant[] };
|
|
17
|
+
type ContentPalette = {
|
|
18
|
+
mode: string; kind?: string; scope?: string; title?: string; subtitle?: string;
|
|
19
|
+
query?: string; prompt?: { label?: string; value?: string };
|
|
20
|
+
results: readonly SearchResult[]; items: readonly { name: string; value: string }[];
|
|
21
|
+
selected?: number; loading?: boolean; error?: string; hint?: string; searching?: boolean;
|
|
22
|
+
detail?: { title?: string; markdown?: string } | null;
|
|
23
|
+
confirm?: { text?: string } | null;
|
|
24
|
+
};
|
|
25
|
+
type ContentState = {
|
|
26
|
+
connection: string; language: string; selected: number;
|
|
27
|
+
rooms: readonly ContentRoom[]; messages: readonly ChatMessage[];
|
|
28
|
+
current?: ContentRoom | null; joined?: boolean; focus?: string;
|
|
29
|
+
pending?: { roomId?: string; message?: string } | null; palette?: ContentPalette | null;
|
|
30
|
+
host?: unknown; participant?: string; draft?: unknown; status?: unknown; statusKind?: string;
|
|
31
|
+
help?: unknown; highlight?: string | null;
|
|
32
|
+
};
|
|
33
|
+
type ContentApp = {
|
|
34
|
+
state: ContentState; paletteCommands(): Command[];
|
|
35
|
+
selectRoom(index: number): void; openRoom(index: number): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
type MessageBlock = { key: string; block: BoxRenderable };
|
|
38
|
+
type RoomRow = { row: BoxRenderable; label: TextRenderable; count: TextRenderable };
|
|
39
|
+
type ContentUi = View & {
|
|
40
|
+
renderer: CliRenderer; theme: TuiTheme; app: ContentApp;
|
|
41
|
+
syntaxStyles: Map<ThemeMode, SyntaxStyle>; mentionStyles: Map<ThemeMode, SyntaxStyle>;
|
|
42
|
+
mentionSignature: string; mentionTypeId: number | null;
|
|
43
|
+
messageBlocks: MessageBlock[]; roomRows: Map<string, RoomRow>;
|
|
44
|
+
selectedRoomID: string | null; hoverRoomId: string | null;
|
|
45
|
+
pendingRoomScroll: string | null; pendingScrollTo: string | null; pendingBottom: boolean;
|
|
46
|
+
roomSignature: string; messageSignature: string; detailSignature: string;
|
|
47
|
+
syncingComposer: boolean; syncingPalette: boolean; focusKey: string | null; paletteInputMode: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const clear = (container: BoxRenderable): void => {
|
|
51
|
+
for (const child of container.getChildren()) {
|
|
52
|
+
container.remove(child);
|
|
53
|
+
child.destroyRecursively();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export function syncLayout(ui: ContentUi): void {
|
|
58
|
+
const { renderer, theme } = ui;
|
|
59
|
+
const narrow = renderer.width < 70;
|
|
60
|
+
const showRooms = !narrow;
|
|
61
|
+
const railWidth = renderer.width >= 120 ? 32 : renderer.width >= 100 ? 28 : 24;
|
|
62
|
+
ui.roomsPane.visible = showRooms;
|
|
63
|
+
ui.roomsPane.width = showRooms ? railWidth : 0;
|
|
64
|
+
ui.roomsFooter.visible = showRooms;
|
|
65
|
+
ui.roomsPane.borderColor = theme.border;
|
|
66
|
+
ui.headerBox.borderColor = theme.border;
|
|
67
|
+
ui.headerBox.paddingX = narrow ? 1 : 2;
|
|
68
|
+
ui.statusBox.paddingX = narrow ? 1 : 2;
|
|
69
|
+
ui.statusBox.borderColor = theme.border;
|
|
70
|
+
ui.chatPane.paddingX = narrow ? 1 : 2;
|
|
71
|
+
ui.composer.marginX = narrow ? 0 : 1;
|
|
72
|
+
ui.composer.height = renderer.height < 18 ? 4 : 5;
|
|
73
|
+
ui.textarea.height = ui.composer.height - 2;
|
|
74
|
+
ui.prompt.height = ui.textarea.height;
|
|
75
|
+
ui.statusHints.visible = !narrow;
|
|
76
|
+
// Dialogs keep the OpenCode v2 habit: inset, readable measure and a top-third seat.
|
|
77
|
+
const paletteMargin = narrow ? 0 : Math.max(1, Math.floor((renderer.width - 80) / 2));
|
|
78
|
+
ui.paletteBox.left = paletteMargin;
|
|
79
|
+
ui.paletteBox.right = paletteMargin;
|
|
80
|
+
ui.paletteBox.bottom = narrow ? 1 : Math.max(1, Math.floor(renderer.height / 4));
|
|
81
|
+
ui.paletteBox.height = Math.min(16, Math.max(9, Math.floor(renderer.height / 2) + 1));
|
|
82
|
+
ui.helpBox.left = narrow ? 0 : 1;
|
|
83
|
+
ui.helpBox.right = narrow ? 0 : 1;
|
|
84
|
+
ui.helpBox.bottom = narrow ? 0 : 1;
|
|
85
|
+
ui.helpBox.height = Math.min(16, Math.max(8, renderer.height - 4));
|
|
86
|
+
ui.helpBody.gap = narrow ? 1 : 4;
|
|
87
|
+
ui.helpBody.paddingX = narrow ? 1 : 2;
|
|
88
|
+
ui.helpBody.paddingY = renderer.height < 22 ? 0 : 1;
|
|
89
|
+
ui.roomsTitle.fg = theme.muted;
|
|
90
|
+
ui.roomsTitle.content = t("rooms.title");
|
|
91
|
+
ui.roomsCount.fg = theme.muted;
|
|
92
|
+
ui.roomsFooter.fg = theme.faint;
|
|
93
|
+
ui.roomsFooter.content = ` ${t("rooms.refreshHint")}`;
|
|
94
|
+
ui.chatMeta.fg = theme.muted;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function syncHeader(ui: ContentUi, state: ContentState): void {
|
|
98
|
+
const { theme } = ui;
|
|
99
|
+
const narrow = ui.renderer.width < 70;
|
|
100
|
+
const left: TextChunk[] = [bold(fg(theme.accent)("opencode-chat-room"))];
|
|
101
|
+
if (!narrow) {
|
|
102
|
+
left.push(fg(theme.muted)(" · "));
|
|
103
|
+
left.push(fg(theme.muted)(sanitizeText(state.host || t("common.server"))));
|
|
104
|
+
}
|
|
105
|
+
ui.headerLeft.content = new StyledText(left);
|
|
106
|
+
|
|
107
|
+
const status = connectionStyle(theme, state.connection);
|
|
108
|
+
const right: TextChunk[] = [];
|
|
109
|
+
right.push(fg(theme.text)(sanitizeText(state.participant || "?")), fg(theme.muted)(" "));
|
|
110
|
+
right.push(fg(status.color)(`${status.dot} ${status.label}`));
|
|
111
|
+
ui.headerRight.content = new StyledText(right);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function roomLabel(room: ContentRoom, pendingID: string | undefined, theme: TuiTheme, active: boolean): StyledText {
|
|
115
|
+
const pending = pendingID === room.id;
|
|
116
|
+
const marker = pending ? "?" : room.joined ? "●" : "○";
|
|
117
|
+
const markerColor = active ? theme.selectedFg : pending ? theme.warning : room.joined ? theme.success : theme.muted;
|
|
118
|
+
const nameColor = active ? theme.selectedFg : theme.text;
|
|
119
|
+
return new StyledText([
|
|
120
|
+
fg(markerColor)(`${marker} `),
|
|
121
|
+
fg(nameColor)(bold(sanitizeText(room.name))),
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function updateRoomStyles(ui: ContentUi, state: ContentState): void {
|
|
126
|
+
const selectedID = state.rooms[state.selected]?.id;
|
|
127
|
+
for (const [id, entry] of ui.roomRows) {
|
|
128
|
+
const room = state.rooms.find((item) => item.id === id);
|
|
129
|
+
if (!room) continue;
|
|
130
|
+
const active = id === selectedID;
|
|
131
|
+
const hovered = id === ui.hoverRoomId;
|
|
132
|
+
entry.row.backgroundColor = active ? ui.theme.selectedBg : hovered ? ui.theme.raised : "transparent";
|
|
133
|
+
entry.label.content = roomLabel(room, state.pending?.roomId, ui.theme, active);
|
|
134
|
+
entry.count.fg = active ? ui.theme.selectedFg : ui.theme.muted;
|
|
135
|
+
}
|
|
136
|
+
if (selectedID && selectedID !== ui.selectedRoomID) {
|
|
137
|
+
ui.selectedRoomID = selectedID;
|
|
138
|
+
ui.pendingRoomScroll = `room-${selectedID}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function syncRooms(ui: ContentUi, state: ContentState): void {
|
|
143
|
+
const pendingID = state.pending?.roomId;
|
|
144
|
+
const signature = `${ui.theme.mode}|${state.language}|${state.connection}|${pendingID ?? ""}|${state.rooms
|
|
145
|
+
.map((room) => `${room.id}:${room.name}:${room.joined}:${room.participants.length}`)
|
|
146
|
+
.join("|")}`;
|
|
147
|
+
ui.roomsCount.content = state.rooms.length ? String(state.rooms.length) : "";
|
|
148
|
+
if (signature !== ui.roomSignature) {
|
|
149
|
+
ui.roomSignature = signature;
|
|
150
|
+
clear(ui.roomContent);
|
|
151
|
+
ui.roomRows.clear();
|
|
152
|
+
if (!state.rooms.length) {
|
|
153
|
+
const emptyLabel = state.connection === "connecting"
|
|
154
|
+
? t("connection.connecting")
|
|
155
|
+
: state.connection === "offline"
|
|
156
|
+
? t("connection.offline")
|
|
157
|
+
: t("rooms.empty");
|
|
158
|
+
ui.roomContent.add(new TextRenderable(ui.renderer, {
|
|
159
|
+
id: "room-empty",
|
|
160
|
+
height: 1,
|
|
161
|
+
wrapMode: "none",
|
|
162
|
+
fg: ui.theme.muted,
|
|
163
|
+
paddingX: 1,
|
|
164
|
+
content: emptyLabel,
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
for (const [index, room] of state.rooms.entries()) {
|
|
168
|
+
const row = new BoxRenderable(ui.renderer, {
|
|
169
|
+
id: `room-${room.id}`,
|
|
170
|
+
height: 1,
|
|
171
|
+
flexDirection: "row",
|
|
172
|
+
gap: 1,
|
|
173
|
+
paddingX: 1,
|
|
174
|
+
});
|
|
175
|
+
const label = new TextRenderable(ui.renderer, {
|
|
176
|
+
id: `room-label-${room.id}`,
|
|
177
|
+
flexGrow: 1,
|
|
178
|
+
height: 1,
|
|
179
|
+
wrapMode: "none",
|
|
180
|
+
truncate: true,
|
|
181
|
+
content: roomLabel(room, pendingID, ui.theme, false),
|
|
182
|
+
});
|
|
183
|
+
const count = new TextRenderable(ui.renderer, {
|
|
184
|
+
id: `room-count-${room.id}`,
|
|
185
|
+
flexShrink: 0,
|
|
186
|
+
height: 1,
|
|
187
|
+
wrapMode: "none",
|
|
188
|
+
fg: ui.theme.muted,
|
|
189
|
+
content: String(room.participants.length),
|
|
190
|
+
});
|
|
191
|
+
row.add(label);
|
|
192
|
+
row.add(count);
|
|
193
|
+
row.onMouseOver = () => {
|
|
194
|
+
ui.hoverRoomId = room.id;
|
|
195
|
+
updateRoomStyles(ui, state);
|
|
196
|
+
ui.renderer.requestRender();
|
|
197
|
+
};
|
|
198
|
+
row.onMouseOut = () => {
|
|
199
|
+
if (ui.hoverRoomId === room.id) ui.hoverRoomId = null;
|
|
200
|
+
updateRoomStyles(ui, state);
|
|
201
|
+
ui.renderer.requestRender();
|
|
202
|
+
};
|
|
203
|
+
row.onMouseUp = (event) => {
|
|
204
|
+
if (event.button !== 0) return;
|
|
205
|
+
ui.app.selectRoom(index);
|
|
206
|
+
void ui.app.openRoom(index);
|
|
207
|
+
};
|
|
208
|
+
ui.roomContent.add(row);
|
|
209
|
+
ui.roomRows.set(room.id, { row, label, count });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
updateRoomStyles(ui, state);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function syncMessages(ui: ContentUi, state: ContentState): void {
|
|
216
|
+
const { current, pending, joined, messages, highlight } = state;
|
|
217
|
+
const messageKey = messages
|
|
218
|
+
.map((message) => `${message.id}:${message.recalledAt ? 1 : 0}:${message.isQuestion ? 1 : 0}:${message.text?.length ?? 0}`)
|
|
219
|
+
.join("|");
|
|
220
|
+
const signature = `${ui.theme.mode}:${state.language}:${current?.id ?? ""}:${joined}:${pending?.roomId ?? ""}:${pending?.message ?? ""}:${highlight ?? ""}:${messageKey}`;
|
|
221
|
+
|
|
222
|
+
if (current) {
|
|
223
|
+
ui.chatTitle.content = new StyledText([bold(fg(ui.theme.accent)(`# ${sanitizeText(current.name)}`))]);
|
|
224
|
+
const count = current.participants.length;
|
|
225
|
+
ui.chatMeta.content = t(count === 1 ? "common.member" : "common.members", { count });
|
|
226
|
+
ui.chatMeta.fg = ui.theme.muted;
|
|
227
|
+
} else {
|
|
228
|
+
ui.chatTitle.content = new StyledText([fg(ui.theme.muted)(t("chat.noRoom"))]);
|
|
229
|
+
ui.chatMeta.content = "";
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (signature === ui.messageSignature) return;
|
|
233
|
+
const previousTop = ui.scrollBox.scrollTop;
|
|
234
|
+
const wasAtBottom = ui.scrollBox.scrollHeight - ui.scrollBox.scrollTop - ui.scrollBox.viewport.height < 2;
|
|
235
|
+
ui.messageSignature = signature;
|
|
236
|
+
|
|
237
|
+
ui.pendingScrollTo = null;
|
|
238
|
+
ui.pendingBottom = false;
|
|
239
|
+
|
|
240
|
+
if (pending && pending.roomId === current?.id) {
|
|
241
|
+
clear(ui.messageContent);
|
|
242
|
+
ui.messageBlocks = [];
|
|
243
|
+
addNotice(ui, "pending", sanitizeText(pending.message), ui.theme.warning);
|
|
244
|
+
addNotice(ui, "pending-wait", t("chat.waitingApproval"), ui.theme.muted);
|
|
245
|
+
} else if (!current) {
|
|
246
|
+
clear(ui.messageContent);
|
|
247
|
+
ui.messageBlocks = [];
|
|
248
|
+
addNotice(ui, "empty", t("chat.selectRoom"), ui.theme.muted);
|
|
249
|
+
} else if (!joined) {
|
|
250
|
+
clear(ui.messageContent);
|
|
251
|
+
ui.messageBlocks = [];
|
|
252
|
+
addNotice(ui, "empty", t("chat.notJoined"), ui.theme.muted);
|
|
253
|
+
} else if (!messages.length) {
|
|
254
|
+
clear(ui.messageContent);
|
|
255
|
+
ui.messageBlocks = [];
|
|
256
|
+
addNotice(ui, "empty", t("chat.noMessages"), ui.theme.muted);
|
|
257
|
+
} else {
|
|
258
|
+
if (!ui.messageBlocks.length && ui.messageContent.getChildren().length) clear(ui.messageContent);
|
|
259
|
+
const nextBlocks: MessageBlock[] = [];
|
|
260
|
+
messages.forEach((message, index) => {
|
|
261
|
+
const info = formatMessage(message, current);
|
|
262
|
+
const previous = messages[index - 1];
|
|
263
|
+
const gap = previous
|
|
264
|
+
? previous.senderId !== message.senderId || messageStamp(message) - messageStamp(previous) > 300000
|
|
265
|
+
: false;
|
|
266
|
+
const highlighted = message.id === highlight;
|
|
267
|
+
const key = [
|
|
268
|
+
ui.theme.mode,
|
|
269
|
+
current.id,
|
|
270
|
+
message.id,
|
|
271
|
+
message.recalledAt ? 1 : 0,
|
|
272
|
+
message.isQuestion ? 1 : 0,
|
|
273
|
+
message.senderId,
|
|
274
|
+
message.createdAt,
|
|
275
|
+
highlighted ? 1 : 0,
|
|
276
|
+
hashText(info.body),
|
|
277
|
+
].join("|");
|
|
278
|
+
const existing = ui.messageBlocks[index];
|
|
279
|
+
let block: BoxRenderable;
|
|
280
|
+
if (existing?.key === key) {
|
|
281
|
+
block = existing.block;
|
|
282
|
+
block.marginTop = index === 0 || gap ? 1 : 0;
|
|
283
|
+
} else {
|
|
284
|
+
if (existing) {
|
|
285
|
+
ui.messageContent.remove(existing.block);
|
|
286
|
+
existing.block.destroyRecursively();
|
|
287
|
+
}
|
|
288
|
+
block = buildMessageBlock(ui, message, info, highlighted, index === 0 || gap ? 1 : 0);
|
|
289
|
+
ui.messageContent.add(block, index);
|
|
290
|
+
}
|
|
291
|
+
nextBlocks.push({ key, block });
|
|
292
|
+
});
|
|
293
|
+
for (const stale of ui.messageBlocks.slice(messages.length)) {
|
|
294
|
+
ui.messageContent.remove(stale.block);
|
|
295
|
+
stale.block.destroyRecursively();
|
|
296
|
+
}
|
|
297
|
+
ui.messageBlocks = nextBlocks;
|
|
298
|
+
if (highlight) ui.pendingScrollTo = `message-${highlight}`;
|
|
299
|
+
else if (wasAtBottom) ui.pendingBottom = true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (!ui.pendingScrollTo && !ui.pendingBottom && previousTop > 0) {
|
|
303
|
+
ui.scrollBox.scrollTop = previousTop;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function syncComposer(ui: ContentUi, state: ContentState): void {
|
|
308
|
+
const draft = String(state.draft ?? "");
|
|
309
|
+
ui.textarea.placeholder = t("chat.composerPlaceholder");
|
|
310
|
+
ui.textarea.placeholderColor = ui.theme.faint;
|
|
311
|
+
ui.textarea.textColor = ui.theme.text;
|
|
312
|
+
ui.textarea.focusedTextColor = ui.theme.text;
|
|
313
|
+
ui.prompt.fg = ui.theme.accent;
|
|
314
|
+
if (ui.textarea.plainText === draft) {
|
|
315
|
+
syncMentionHighlights(ui, state);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
ui.syncingComposer = true;
|
|
319
|
+
try {
|
|
320
|
+
ui.textarea.setText(draft);
|
|
321
|
+
// setText can leave the caret at the start. A character typed while the
|
|
322
|
+
// room list was focused would then be followed by the rest before it.
|
|
323
|
+
ui.textarea.cursorOffset = draft.length;
|
|
324
|
+
} finally {
|
|
325
|
+
ui.syncingComposer = false;
|
|
326
|
+
}
|
|
327
|
+
ui.mentionSignature = "";
|
|
328
|
+
syncMentionHighlights(ui, state);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function syncStatus(ui: ContentUi, state: ContentState): void {
|
|
332
|
+
const { theme } = ui;
|
|
333
|
+
const connection = connectionStyle(theme, state.connection);
|
|
334
|
+
const text = state.status
|
|
335
|
+
|| (state.connection === "online" ? t("status.ready") : `${connection.dot} ${connection.label}`);
|
|
336
|
+
ui.statusLine.content = sanitizeText(text);
|
|
337
|
+
ui.statusLine.fg = state.statusKind === "error"
|
|
338
|
+
? theme.error
|
|
339
|
+
: state.statusKind === "success"
|
|
340
|
+
? theme.success
|
|
341
|
+
: theme.muted;
|
|
342
|
+
const hints = state.focus === "composer"
|
|
343
|
+
? t("status.composerHints")
|
|
344
|
+
: t("status.roomHints");
|
|
345
|
+
ui.statusHints.content = ui.renderer.width < 70 ? t("status.hintsShort") : hints;
|
|
346
|
+
ui.statusHints.fg = theme.faint;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export function syncFocus(ui: ContentUi, state: ContentState): void {
|
|
350
|
+
const palette = state.palette;
|
|
351
|
+
const paletteMode = palette?.mode ?? "";
|
|
352
|
+
const target = palette ? "palette" : state.help ? "help" : state.focus === "composer" ? "composer" : "rooms";
|
|
353
|
+
const paletteInput = Boolean(palette) && ["commands", "search", "prompt"].includes(paletteMode);
|
|
354
|
+
if (target !== ui.focusKey) {
|
|
355
|
+
if (ui.focusKey === "composer") ui.textarea.blur();
|
|
356
|
+
if (ui.focusKey === "palette") ui.paletteInput.blur();
|
|
357
|
+
if (target === "composer") ui.textarea.focus();
|
|
358
|
+
if (target === "palette" && paletteInput) ui.paletteInput.focus();
|
|
359
|
+
ui.focusKey = target;
|
|
360
|
+
}
|
|
361
|
+
if (ui.paletteInputMode !== paletteInput) {
|
|
362
|
+
if (paletteInput) ui.paletteInput.focus();
|
|
363
|
+
else ui.paletteInput.blur();
|
|
364
|
+
ui.paletteInputMode = paletteInput;
|
|
365
|
+
}
|
|
366
|
+
const accent = target === "composer";
|
|
367
|
+
ui.composer.borderColor = accent ? ui.theme.accent : ui.theme.border;
|
|
368
|
+
ui.prompt.fg = accent ? ui.theme.accent : ui.theme.muted;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function syncPalette(ui: ContentUi, state: ContentState): void {
|
|
372
|
+
const { theme, paletteBox } = ui;
|
|
373
|
+
const palette = state.palette;
|
|
374
|
+
paletteBox.visible = Boolean(palette);
|
|
375
|
+
if (!palette) {
|
|
376
|
+
ui.detailSignature = "";
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const mode = palette.mode;
|
|
381
|
+
const isInput = mode === "commands" || mode === "search" || mode === "prompt";
|
|
382
|
+
const isList = mode === "commands" || mode === "search" || mode === "info";
|
|
383
|
+
const isDetail = mode === "detail";
|
|
384
|
+
const isConfirm = mode === "confirm";
|
|
385
|
+
|
|
386
|
+
paletteBox.backgroundColor = theme.surface;
|
|
387
|
+
paletteBox.borderColor = theme.accent;
|
|
388
|
+
ui.paletteBar.backgroundColor = theme.raised;
|
|
389
|
+
ui.paletteTitle.fg = theme.text;
|
|
390
|
+
ui.paletteScope.fg = theme.muted;
|
|
391
|
+
ui.palettePrompt.fg = theme.accent;
|
|
392
|
+
ui.paletteInputRow.visible = isInput;
|
|
393
|
+
ui.paletteList.visible = isList;
|
|
394
|
+
ui.paletteDetailScroll.visible = isDetail;
|
|
395
|
+
ui.paletteConfirm.visible = isConfirm;
|
|
396
|
+
ui.paletteInput.placeholderColor = theme.faint;
|
|
397
|
+
ui.paletteInput.textColor = theme.text;
|
|
398
|
+
ui.paletteInput.focusedTextColor = theme.text;
|
|
399
|
+
ui.paletteList.textColor = theme.text;
|
|
400
|
+
ui.paletteList.focusedTextColor = theme.text;
|
|
401
|
+
ui.paletteList.selectedBackgroundColor = theme.selectedBg;
|
|
402
|
+
ui.paletteList.selectedTextColor = theme.selectedFg;
|
|
403
|
+
|
|
404
|
+
const scope = palette.scope === "all" ? t("palette.scopeAll") : t("palette.scopeRoom");
|
|
405
|
+
const defaultTitle = mode === "prompt"
|
|
406
|
+
? t("palette.newRoom")
|
|
407
|
+
: mode === "search"
|
|
408
|
+
? t("palette.searchMessages")
|
|
409
|
+
: t("palette.title");
|
|
410
|
+
ui.paletteTitle.content = new StyledText([bold(fg(theme.text)(palette.title || defaultTitle))]);
|
|
411
|
+
ui.paletteScope.content = palette.subtitle
|
|
412
|
+
|| (mode === "prompt" ? t("palette.create") : mode === "search" ? scope : t("palette.commands"));
|
|
413
|
+
ui.paletteInput.placeholder = mode === "prompt"
|
|
414
|
+
? palette.prompt?.label || t("palette.valuePlaceholder")
|
|
415
|
+
: mode === "search"
|
|
416
|
+
? t("palette.searchPlaceholder")
|
|
417
|
+
: t("palette.commandPlaceholder");
|
|
418
|
+
|
|
419
|
+
const value = mode === "prompt" ? palette.prompt?.value ?? "" : palette.query ?? "";
|
|
420
|
+
if (ui.paletteInput.value !== value) {
|
|
421
|
+
ui.syncingPalette = true;
|
|
422
|
+
try {
|
|
423
|
+
ui.paletteInput.value = value;
|
|
424
|
+
} finally {
|
|
425
|
+
ui.syncingPalette = false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
let options: { name: string; description: string; value: string }[] = [];
|
|
430
|
+
if (mode === "commands") {
|
|
431
|
+
options = ui.app.paletteCommands().map((command) => ({ name: command.label, description: "", value: command.id }));
|
|
432
|
+
} else if (mode === "search") {
|
|
433
|
+
options = !String(palette.query ?? "").trim()
|
|
434
|
+
? [{ name: t("palette.searchPlaceholder"), description: "", value: "" }]
|
|
435
|
+
: !palette.results.length
|
|
436
|
+
? [{ name: palette.searching ? t("palette.searching") : t("palette.noMatches"), description: "", value: "" }]
|
|
437
|
+
: palette.results.map((result) => {
|
|
438
|
+
const info = formatMessage(result.message, null);
|
|
439
|
+
return {
|
|
440
|
+
name: `${sanitizeText(result.roomName)} ${info.time} ${info.sender} ${sanitizeText(result.snippet)}`,
|
|
441
|
+
description: "",
|
|
442
|
+
value: result.message.id,
|
|
443
|
+
};
|
|
444
|
+
});
|
|
445
|
+
} else if (mode === "info") {
|
|
446
|
+
options = palette.loading
|
|
447
|
+
? [{ name: t("common.loading"), description: "", value: "" }]
|
|
448
|
+
: palette.items.length
|
|
449
|
+
? palette.items.map((item) => ({ name: item.name, description: "", value: item.value }))
|
|
450
|
+
: [{ name: palette.error ? t("palette.unavailable") : t("palette.nothing"), description: "", value: "" }];
|
|
451
|
+
}
|
|
452
|
+
ui.paletteList.options = options;
|
|
453
|
+
if (isList) ui.paletteList.setSelectedIndex(Math.min(palette.selected ?? 0, Math.max(0, options.length - 1)));
|
|
454
|
+
|
|
455
|
+
let desiredHeight: number;
|
|
456
|
+
if (mode === "commands" || mode === "info") {
|
|
457
|
+
desiredHeight = Math.min(16, ui.renderer.height - 2, Math.max(9, options.length + 4));
|
|
458
|
+
} else if (isDetail) {
|
|
459
|
+
desiredHeight = Math.min(ui.renderer.height - 2, Math.max(12, Math.floor(ui.renderer.height * 0.8)));
|
|
460
|
+
} else if (isConfirm) {
|
|
461
|
+
desiredHeight = Math.min(9, Math.max(6, ui.renderer.height - 4));
|
|
462
|
+
} else {
|
|
463
|
+
desiredHeight = Math.min(16, Math.max(9, Math.floor(ui.renderer.height / 2) + 1));
|
|
464
|
+
}
|
|
465
|
+
desiredHeight = Math.max(4, Math.min(desiredHeight, ui.renderer.height - Math.max(1, Math.floor(ui.renderer.height / 4)) - 1));
|
|
466
|
+
paletteBox.bottom = Math.max(1, ui.renderer.height - Math.max(1, Math.floor(ui.renderer.height / 4)) - desiredHeight);
|
|
467
|
+
if (paletteBox.height !== desiredHeight) paletteBox.height = desiredHeight;
|
|
468
|
+
|
|
469
|
+
ui.paletteDetailMarkdown.syntaxStyle = markdownStyle(ui);
|
|
470
|
+
ui.paletteDetailMarkdown.fg = theme.text;
|
|
471
|
+
if (isDetail) {
|
|
472
|
+
const signature = `${theme.mode}:${state.language}:${palette.detail?.title}:${palette.detail?.markdown}`;
|
|
473
|
+
if (signature !== ui.detailSignature) {
|
|
474
|
+
ui.detailSignature = signature;
|
|
475
|
+
ui.paletteDetailMarkdown.content = palette.detail?.markdown ?? "";
|
|
476
|
+
ui.paletteDetailScroll.scrollTop = 0;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (isConfirm) {
|
|
480
|
+
ui.paletteConfirm.content = ` ${palette.confirm?.text ?? ""}`;
|
|
481
|
+
ui.paletteConfirm.fg = theme.warning;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const footer = palette.error
|
|
485
|
+
|| (mode === "prompt"
|
|
486
|
+
? palette.hint || t("palette.promptHint")
|
|
487
|
+
: mode === "search"
|
|
488
|
+
? t("palette.searchHint", {
|
|
489
|
+
scope: palette.scope === "all" ? t("palette.scopeRoom") : t("palette.scopeAll"),
|
|
490
|
+
searching: palette.searching ? t("palette.searchingSuffix") : "",
|
|
491
|
+
})
|
|
492
|
+
: mode === "detail"
|
|
493
|
+
? palette.hint || t("palette.detailHint")
|
|
494
|
+
: mode === "confirm"
|
|
495
|
+
? palette.hint || t("palette.confirmHint")
|
|
496
|
+
: palette.hint || (mode === "info" ? t("palette.listHint") : t("palette.runHint")));
|
|
497
|
+
ui.paletteHint.content = ` ${sanitizeText(footer)}${palette.searching && mode !== "search" ? ` · ${t("palette.working")}` : ""}`;
|
|
498
|
+
ui.paletteHint.fg = palette.error ? theme.error : theme.muted;
|
|
499
|
+
}
|
package/src/tui/ui-help.mjs
CHANGED
|
@@ -1,73 +1,64 @@
|
|
|
1
1
|
// Keyboard help overlay: themed shortcut columns, compact on short terminals.
|
|
2
2
|
import { StyledText, bold, fg } from "@opentui/core";
|
|
3
3
|
import { t } from "./i18n.mjs";
|
|
4
|
-
|
|
5
4
|
function shortcutChunks(title, rows, theme) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const chunks = [bold(fg(theme.accent)(`${title}\n`))];
|
|
6
|
+
for (const [key, label] of rows) {
|
|
7
|
+
chunks.push(fg(theme.accent)(key.padEnd(12)));
|
|
8
|
+
chunks.push(fg(theme.text)(`${label}\n`));
|
|
9
|
+
}
|
|
10
|
+
return chunks;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
function shortcutChunks(title, rows, theme) {
|
|
15
|
-
const chunks = [bold(fg(theme.accent)(`${title}\n`))];
|
|
16
|
-
for (const [key, label] of rows) {
|
|
17
|
-
chunks.push(fg(theme.accent)(key.padEnd(12)));
|
|
18
|
-
chunks.push(fg(theme.text)(`${label}\n`));
|
|
19
|
-
}
|
|
20
|
-
return chunks;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
12
|
export function syncHelp(ui, state) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
13
|
+
const show = Boolean(state.help) && !state.palette;
|
|
14
|
+
ui.helpBox.visible = show;
|
|
15
|
+
if (!show)
|
|
16
|
+
return;
|
|
17
|
+
ui.helpBox.borderColor = ui.theme.border;
|
|
18
|
+
ui.helpBox.backgroundColor = ui.theme.surface;
|
|
19
|
+
ui.helpBar.backgroundColor = ui.theme.raised;
|
|
20
|
+
ui.helpTitle.fg = ui.theme.text;
|
|
21
|
+
ui.helpClose.fg = ui.theme.muted;
|
|
22
|
+
ui.helpFooter.fg = ui.theme.muted;
|
|
23
|
+
const signature = `${ui.theme.mode}:${state.language}`;
|
|
24
|
+
if (signature === ui.helpSignature)
|
|
25
|
+
return;
|
|
26
|
+
ui.helpSignature = signature;
|
|
27
|
+
const compact = ui.renderer.height < 22;
|
|
28
|
+
const navigation = compact
|
|
29
|
+
? [
|
|
30
|
+
["↑ / ↓", t("help.selectRoom")],
|
|
31
|
+
["Enter", t("help.openJoin")],
|
|
32
|
+
["Tab", t("help.focusComposer")],
|
|
33
|
+
["PgUp / PgDn", t("help.scrollMessages")],
|
|
34
|
+
]
|
|
35
|
+
: [
|
|
36
|
+
["↑ / ↓", t("help.selectRoom")],
|
|
37
|
+
["Enter", t("help.openJoin")],
|
|
38
|
+
["Tab", t("help.focusComposer")],
|
|
39
|
+
["PgUp / PgDn", t("help.scrollMessages")],
|
|
40
|
+
["Alt+Home", t("help.firstMessage")],
|
|
41
|
+
["Alt+End", t("help.lastMessage")],
|
|
42
|
+
];
|
|
43
|
+
const composer = compact
|
|
44
|
+
? [
|
|
45
|
+
["Enter", t("help.sendMessage")],
|
|
46
|
+
["Esc", t("help.clearBlur")],
|
|
47
|
+
["/", t("help.inlineCommands")],
|
|
48
|
+
["@", t("help.mentionMembers")],
|
|
49
|
+
["Ctrl+C", t("help.quit")],
|
|
50
|
+
]
|
|
51
|
+
: [
|
|
52
|
+
["Enter", t("help.sendMessage")],
|
|
53
|
+
["Ctrl+J", t("help.newline")],
|
|
54
|
+
["Esc", t("help.clearBlur")],
|
|
55
|
+
["/", t("help.inlineCommands")],
|
|
56
|
+
["@", t("help.mentionMembers")],
|
|
57
|
+
["Alt+Space", t("help.paletteSearch")],
|
|
58
|
+
["Ctrl+R", t("help.refreshRooms")],
|
|
59
|
+
["/exit", t("help.quit")],
|
|
60
|
+
["Ctrl+C", t("help.quit")],
|
|
61
|
+
];
|
|
62
|
+
ui.helpLeft.content = new StyledText(shortcutChunks(t("help.navigation"), navigation, ui.theme));
|
|
63
|
+
ui.helpRight.content = new StyledText(shortcutChunks(t("help.composer"), composer, ui.theme));
|
|
64
|
+
}
|