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