@gloom-sh/terminal 0.20.9 → 0.20.11

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 (212) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
  3. package/src/api-client/auth.ts +6 -0
  4. package/src/api-client/data.ts +1 -0
  5. package/src/api-client/earnings.ts +15 -0
  6. package/src/api-client/index.ts +14 -3
  7. package/src/api-client/socket-connection.ts +355 -0
  8. package/src/api-client/socket-features.ts +75 -0
  9. package/src/api-client/socket-frames.ts +161 -0
  10. package/src/api-client/socket-listeners.ts +207 -0
  11. package/src/api-client/socket-quotes.ts +332 -0
  12. package/src/api-client/socket.ts +150 -983
  13. package/src/api-client/types/account.ts +10 -0
  14. package/src/api-client/types/billing.ts +10 -0
  15. package/src/api-client/types/econ.ts +19 -7
  16. package/src/api-client/types/market.ts +7 -0
  17. package/src/api-client/types/screener.ts +2 -0
  18. package/src/brokers/signed-in/adapter.ts +19 -5
  19. package/src/brokers/signed-in/client.ts +13 -1
  20. package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
  21. package/src/cli/commands/market.ts +18 -8
  22. package/src/cli/commands/overview.ts +26 -7
  23. package/src/cli/commands/ticker.ts +40 -15
  24. package/src/cli/desktop-pane-shot.ts +39 -0
  25. package/src/cli/errors.ts +20 -3
  26. package/src/cli/fx-pair.ts +11 -2
  27. package/src/cli/history-rows.ts +34 -3
  28. package/src/cli/index.ts +1 -1
  29. package/src/cli/listing-arg.ts +51 -13
  30. package/src/cli/pane-functions/headless.ts +4 -2
  31. package/src/cli/pane-functions/index.ts +1 -0
  32. package/src/cli/pane-functions/resolver.ts +2 -1
  33. package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
  34. package/src/cli/pane-functions/screenshot-types.ts +4 -0
  35. package/src/components/chart/composite/chart-layout.ts +7 -4
  36. package/src/components/chart/composite/composite-chart.tsx +6 -16
  37. package/src/components/chart/composite/toolbar.tsx +258 -82
  38. package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
  39. package/src/components/chart/native/kitty/manager.ts +2 -0
  40. package/src/components/chart/native/surface/manager.ts +211 -11
  41. package/src/components/command-bar/list/model.ts +13 -0
  42. package/src/components/command-bar/panel/index.tsx +2 -13
  43. package/src/components/command-bar/panel/layout.ts +1 -7
  44. package/src/components/command-bar/panel/runtime.ts +0 -1
  45. package/src/components/command-bar/panel/types.ts +0 -2
  46. package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
  47. package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
  48. package/src/components/command-bar/surface/index.tsx +10 -5
  49. package/src/components/command-bar/workflow/alert.ts +21 -7
  50. package/src/components/data-table/column-menu.tsx +89 -0
  51. package/src/components/data-table/sort-menu.tsx +9 -2
  52. package/src/components/data-table/table-pane.ts +3 -1
  53. package/src/components/data-table/view.tsx +33 -6
  54. package/src/components/form-modal/content.tsx +10 -0
  55. package/src/components/index.ts +1 -1
  56. package/src/components/layout/pane/footer/index.tsx +25 -11
  57. package/src/components/layout/pane/footer/model.ts +88 -21
  58. package/src/components/layout/pane/sidebar.tsx +125 -15
  59. package/src/components/layout/shell/active-drag.ts +18 -13
  60. package/src/components/layout/shell/drag/magnets.ts +34 -18
  61. package/src/components/metric-treemap/heat-surface.tsx +2 -1
  62. package/src/components/metric-treemap/index.tsx +3 -2
  63. package/src/components/ticker/list-table-view.tsx +5 -0
  64. package/src/components/ui/confirm-dialog.tsx +253 -7
  65. package/src/components/ui/data-table/column-order.ts +180 -0
  66. package/src/components/ui/data-table/index.tsx +13 -2
  67. package/src/components/ui/data-table/opentui/index.tsx +267 -23
  68. package/src/components/ui/data-table/opentui/model.ts +43 -4
  69. package/src/components/ui/data-table/types.ts +56 -0
  70. package/src/components/ui/data-table/use-column-order.ts +135 -0
  71. package/src/components/ui/index.ts +1 -1
  72. package/src/components/ui/list-view.tsx +4 -3
  73. package/src/components/ui/status.tsx +9 -6
  74. package/src/components/ui/table-layout.ts +120 -0
  75. package/src/docs/snapshot.json +39 -2
  76. package/src/i18n/es.ts +14 -0
  77. package/src/i18n/ja.ts +14 -0
  78. package/src/i18n/ko.ts +14 -0
  79. package/src/i18n/zh-cn.ts +14 -0
  80. package/src/i18n/zh-tw.ts +14 -0
  81. package/src/market-data/coordinator/index.ts +4 -3
  82. package/src/market-data/coordinator/quotes.ts +12 -4
  83. package/src/market-data/fx-closes.ts +14 -2
  84. package/src/market-data/market/change-basis.ts +35 -1
  85. package/src/market-data/market/status.ts +37 -0
  86. package/src/market-data/performance.ts +4 -1
  87. package/src/market-data/quotes/freshness.ts +12 -0
  88. package/src/market-data/quotes/live-valuation.ts +26 -3
  89. package/src/market-data/quotes/regular-session-valuation.ts +1 -1
  90. package/src/market-data/realized-volatility.ts +3 -0
  91. package/src/market-data/us-bond-market.ts +115 -0
  92. package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
  93. package/src/plugins/builtin/account-management/keyboard.ts +3 -0
  94. package/src/plugins/builtin/account-management/model.ts +1 -0
  95. package/src/plugins/builtin/account-management/pane.tsx +51 -5
  96. package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
  97. package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
  98. package/src/plugins/builtin/broker-manager/index.tsx +6 -6
  99. package/src/plugins/builtin/broker-manager/model.ts +15 -6
  100. package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
  101. package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
  102. package/src/plugins/builtin/broker-manager/table.ts +10 -4
  103. package/src/plugins/builtin/chat/sidebar.tsx +33 -16
  104. package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
  105. package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
  106. package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
  107. package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
  108. package/src/plugins/builtin/correlation/compute.ts +4 -3
  109. package/src/plugins/builtin/earnings/board-model.ts +33 -0
  110. package/src/plugins/builtin/earnings/board-table.ts +50 -11
  111. package/src/plugins/builtin/earnings/board.tsx +29 -13
  112. package/src/plugins/builtin/earnings/calendar.tsx +15 -3
  113. package/src/plugins/builtin/earnings/client.ts +4 -1
  114. package/src/plugins/builtin/earnings/headless.ts +27 -14
  115. package/src/plugins/builtin/econ/calendar-source.ts +3 -0
  116. package/src/plugins/builtin/equity-screener/live.ts +74 -18
  117. package/src/plugins/builtin/equity-screener/model.ts +19 -4
  118. package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
  119. package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
  120. package/src/plugins/builtin/equity-screener/results.ts +22 -2
  121. package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
  122. package/src/plugins/builtin/futures/index.tsx +15 -1
  123. package/src/plugins/builtin/futures/table.tsx +1 -1
  124. package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
  125. package/src/plugins/builtin/help/index.tsx +1 -1
  126. package/src/plugins/builtin/holders/pane.tsx +30 -20
  127. package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
  128. package/src/plugins/builtin/iv-history/events.ts +5 -0
  129. package/src/plugins/builtin/iv-history/headless.ts +19 -12
  130. package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
  131. package/src/plugins/builtin/macro-day/headless.ts +27 -8
  132. package/src/plugins/builtin/macro-day/model.ts +17 -4
  133. package/src/plugins/builtin/macro-day/releases.ts +36 -15
  134. package/src/plugins/builtin/market-halts/model.ts +3 -2
  135. package/src/plugins/builtin/market-movers/headless.ts +2 -1
  136. package/src/plugins/builtin/market-movers/index.tsx +3 -2
  137. package/src/plugins/builtin/market-movers/model.ts +75 -22
  138. package/src/plugins/builtin/market-movers/screener.ts +2 -1
  139. package/src/plugins/builtin/market-movers/table.ts +7 -5
  140. package/src/plugins/builtin/options/view.tsx +2 -0
  141. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  142. package/src/plugins/builtin/pe-band/model.ts +4 -0
  143. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
  144. package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
  145. package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
  146. package/src/plugins/builtin/portfolio-list/pane/index.tsx +15 -1
  147. package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
  148. package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
  149. package/src/plugins/builtin/portfolio-list/table.tsx +18 -1
  150. package/src/plugins/builtin/rate-path/pane.tsx +2 -0
  151. package/src/plugins/builtin/research/analyst-headless.ts +9 -1
  152. package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
  153. package/src/plugins/builtin/research/client.ts +25 -1
  154. package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
  155. package/src/plugins/builtin/research/event-model.ts +3 -13
  156. package/src/plugins/builtin/research/event-sources.ts +3 -1
  157. package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
  158. package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
  159. package/src/plugins/builtin/seasonality/pane.tsx +2 -1
  160. package/src/plugins/builtin/short-interest/headless.ts +2 -0
  161. package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
  162. package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
  163. package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
  164. package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
  165. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
  166. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
  167. package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
  168. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  169. package/src/plugins/builtin/world-indices/index.tsx +5 -1
  170. package/src/plugins/builtin/yield-curve/headless.ts +5 -1
  171. package/src/plugins/builtin/yield-curve/index.tsx +7 -1
  172. package/src/portfolio/column-values.ts +47 -14
  173. package/src/portfolio/return-metrics.ts +4 -2
  174. package/src/renderers/dom/data-table/column-drag.ts +147 -0
  175. package/src/renderers/dom/data-table/index.tsx +22 -0
  176. package/src/renderers/dom/data-table/row.tsx +27 -5
  177. package/src/renderers/dom/host/image-surface.tsx +19 -9
  178. package/src/renderers/dom/host/input.tsx +4 -0
  179. package/src/renderers/dom/styles.css +22 -0
  180. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
  181. package/src/renderers/opentui/chart-surface.tsx +1 -0
  182. package/src/renderers/opentui/frame-hits.ts +33 -0
  183. package/src/renderers/opentui/host.tsx +2 -0
  184. package/src/renderers/opentui/native-surface.ts +14 -21
  185. package/src/renderers/opentui/test-utils.tsx +3 -0
  186. package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
  187. package/src/sources/provider-errors.ts +12 -0
  188. package/src/sources/provider-router/index.ts +12 -4
  189. package/src/state/app/context/index.tsx +22 -0
  190. package/src/state/pane-session.ts +145 -0
  191. package/src/test-support/app-store.ts +24 -1
  192. package/src/tickers/search/home-listing.ts +44 -1
  193. package/src/tickers/search/index.ts +5 -2
  194. package/src/tickers/search/ranking.ts +7 -7
  195. package/src/tickers/us-listing.ts +11 -5
  196. package/src/time-series/base-series.ts +7 -1
  197. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  198. package/src/time-series/fundamentals/series.ts +6 -0
  199. package/src/time-series/live-quotes.ts +3 -9
  200. package/src/time-series/resolve.ts +1 -0
  201. package/src/types/financials.ts +20 -0
  202. package/src/types/headless.ts +9 -0
  203. package/src/ui/host.tsx +20 -0
  204. package/src/ui/pointer-drag.ts +11 -2
  205. package/src/utils/exchanges.ts +13 -8
  206. package/src/utils/fundamentals.ts +14 -3
  207. package/src/utils/price-earnings.ts +17 -10
  208. package/src/utils/price-history-integrity.ts +15 -0
  209. package/src/utils/reason-codes.ts +79 -0
  210. package/src/utils/share-multiples.cases.json +1667 -0
  211. package/src/utils/share-multiples.ts +384 -0
  212. package/src/utils/untrusted-text.ts +11 -0
@@ -8,6 +8,7 @@ import {
8
8
  type NativeChartBitmap,
9
9
  } from "../chart-rasterizer";
10
10
  import { KittyImageManager } from "../kitty/manager";
11
+ import { getRenderableCellRect, resolveNativeSurfaceVisibleRect, type NativeSurfaceRenderableNode } from "./visibility";
11
12
 
12
13
  export interface NativePaneLayer {
13
14
  paneId: string;
@@ -29,6 +30,28 @@ export interface NativeLocalOccluder {
29
30
  rect: CellRect;
30
31
  }
31
32
 
33
+ export interface CellInsets {
34
+ top: number;
35
+ right: number;
36
+ bottom: number;
37
+ left: number;
38
+ }
39
+
40
+ /**
41
+ * The box an image draws over. After every frame the terminal shows, the
42
+ * image is measured again from it and kept off every cell something else drew
43
+ * on top of it, so it follows the layout, scrolling and clipping of that frame,
44
+ * goes when the box leaves the screen, and never shows over a window, menu,
45
+ * bar or toast that covers it.
46
+ */
47
+ export interface NativeSurfaceAnchor {
48
+ renderable: NativeSurfaceRenderableNode;
49
+ /** Cells kept clear inside the box, as a border or padding does. */
50
+ insets?: CellInsets;
51
+ /** Part of the inset box, from its top-left cell: a crosshair strip over its chart. */
52
+ region?: CellRect;
53
+ }
54
+
32
55
  export interface NativeSurfaceSnapshot {
33
56
  id: string;
34
57
  paneId: string;
@@ -38,6 +61,7 @@ export interface NativeSurfaceSnapshot {
38
61
  bitmapKey: string;
39
62
  /** Kitty stacking order; defaults to the plot layer. */
40
63
  imageZIndex?: number;
64
+ anchor?: NativeSurfaceAnchor;
41
65
  }
42
66
 
43
67
  interface SurfaceEntry {
@@ -89,15 +113,150 @@ function sameWindowState(a: NativeWindowState, b: NativeWindowState): boolean {
89
113
  return true;
90
114
  }
91
115
 
116
+ function sameInsets(a: CellInsets | undefined, b: CellInsets | undefined): boolean {
117
+ if (a === b) return true;
118
+ if (!a || !b) return false;
119
+ return a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left;
120
+ }
121
+
122
+ function sameAnchor(a: NativeSurfaceAnchor | undefined, b: NativeSurfaceAnchor | undefined): boolean {
123
+ if (a === b) return true;
124
+ if (!a || !b) return false;
125
+ return a.renderable === b.renderable
126
+ && sameInsets(a.insets, b.insets)
127
+ && sameCellRect(a.region ?? null, b.region ?? null);
128
+ }
129
+
92
130
  function sameSnapshot(a: NativeSurfaceSnapshot, b: NativeSurfaceSnapshot): boolean {
93
131
  return a.id === b.id
94
132
  && a.paneId === b.paneId
95
133
  && a.bitmapKey === b.bitmapKey
96
134
  && a.imageZIndex === b.imageZIndex
135
+ && sameAnchor(a.anchor, b.anchor)
97
136
  && sameCellRect(a.rect, b.rect)
98
137
  && sameCellRect(a.visibleRect, b.visibleRect);
99
138
  }
100
139
 
140
+ export function insetCellRect(rect: CellRect, insets: CellInsets | undefined): CellRect | null {
141
+ if (!insets) return rect;
142
+ const width = rect.width - insets.left - insets.right;
143
+ const height = rect.height - insets.top - insets.bottom;
144
+ if (width <= 0 || height <= 0) return null;
145
+ return { x: rect.x + insets.left, y: rect.y + insets.top, width, height };
146
+ }
147
+
148
+ /**
149
+ * Where an anchored image is in the frame just drawn: its box (or the part of
150
+ * it the region names) and the cells of it its ancestors leave on screen, none
151
+ * once the box is hidden, destroyed or out of the tree.
152
+ */
153
+ function measureNativeSurfaceAnchor(
154
+ anchor: NativeSurfaceAnchor,
155
+ terminalWidth: number,
156
+ terminalHeight: number,
157
+ attached: (renderable: unknown) => boolean,
158
+ ): { rect: CellRect; visibleRect: CellRect | null } | null {
159
+ const box = insetCellRect(getRenderableCellRect(anchor.renderable), anchor.insets);
160
+ if (!box) return null;
161
+ const rect = anchor.region
162
+ ? { x: box.x + anchor.region.x, y: box.y + anchor.region.y, width: anchor.region.width, height: anchor.region.height }
163
+ : box;
164
+ if (!attached(anchor.renderable)) return { rect, visibleRect: null };
165
+ const outer = resolveNativeSurfaceVisibleRect(anchor.renderable, terminalWidth, terminalHeight);
166
+ return { rect, visibleRect: outer ? intersectCellRects(rect, outer) : null };
167
+ }
168
+
169
+ /** The renderable a pane window carries its pane id on. */
170
+ const PANE_ID_PROPERTY = "data-gloom-pane-id";
171
+ const MAX_ANCESTOR_DEPTH = 256;
172
+ /** More pieces than this means something scattered covers the image: it is hidden instead. */
173
+ const MAX_UNCOVERED_FRAGMENTS = 128;
174
+
175
+ type ParentedNode = { parent?: unknown } | null | undefined;
176
+
177
+ function parentOf(node: unknown): unknown {
178
+ return node && typeof node === "object" ? (node as ParentedNode)?.parent ?? null : null;
179
+ }
180
+
181
+ /**
182
+ * Whether a renderable the frame drew on top of an anchored image covers it.
183
+ * The image's own pane draws over its charts on purpose (legends, toolbars,
184
+ * axis labels): only its explicit local occluders cut those. Anything else
185
+ * covers the image where it or a box it sits in fills its cells, up to the
186
+ * first box the image also sits in: a window, a menu, a bar, a toast. A
187
+ * see-through layer (a click catcher) does not, and text without a background
188
+ * draws over the image anyway.
189
+ */
190
+ function createCoverTest(
191
+ anchor: NativeSurfaceRenderableNode,
192
+ paints: (renderable: unknown) => boolean,
193
+ ): (hit: unknown) => boolean {
194
+ // The image's ancestors up to its pane window hold its own pane's drawing;
195
+ // the ones above it hold everything else.
196
+ const chain: unknown[] = [];
197
+ let home = -1;
198
+ let node = parentOf(anchor);
199
+ for (let depth = 0; node && depth < MAX_ANCESTOR_DEPTH; depth += 1) {
200
+ chain.push(node);
201
+ if (home < 0 && typeof (node as Record<string, unknown>)[PANE_ID_PROPERTY] === "string") home = chain.length - 1;
202
+ node = parentOf(node);
203
+ }
204
+ // Outside any pane, what the image's own component draws beside it is its own.
205
+ if (home < 0) home = chain.length > 0 ? 0 : -1;
206
+ const own = new Set<unknown>([anchor, ...chain.slice(0, home + 1)]);
207
+ const shared = new Set<unknown>(chain.slice(home + 1));
208
+ const known = new Map<unknown, boolean>();
209
+ return (hit) => {
210
+ if (hit == null || hit === anchor) return false;
211
+ const cached = known.get(hit);
212
+ if (cached !== undefined) return cached;
213
+ let covers = false;
214
+ let current: unknown = hit;
215
+ for (let depth = 0; current && depth < MAX_ANCESTOR_DEPTH; depth += 1) {
216
+ if (own.has(current)) {
217
+ covers = false;
218
+ break;
219
+ }
220
+ if (shared.has(current)) break;
221
+ if (paints(current)) covers = true;
222
+ current = parentOf(current);
223
+ }
224
+ known.set(hit, covers);
225
+ return covers;
226
+ };
227
+ }
228
+
229
+ /**
230
+ * The cells of `rect` nothing covers, as rectangles: runs of uncovered cells
231
+ * row by row, a run that lines up with the one above it extending it down.
232
+ */
233
+ function uncoveredCellRects(rect: CellRect, covered: (x: number, y: number) => boolean): CellRect[] {
234
+ const done: CellRect[] = [];
235
+ let open: CellRect[] = [];
236
+ const right = rect.x + rect.width;
237
+ for (let y = rect.y; y < rect.y + rect.height; y += 1) {
238
+ const next: CellRect[] = [];
239
+ let start = -1;
240
+ for (let x = rect.x; x <= right; x += 1) {
241
+ const free = x < right && !covered(x, y);
242
+ if (free && start < 0) start = x;
243
+ if (!free && start >= 0) {
244
+ const above = open.find((candidate) => candidate.x === start && candidate.x + candidate.width === x);
245
+ if (above) {
246
+ above.height += 1;
247
+ next.push(above);
248
+ } else {
249
+ next.push({ x: start, y, width: x - start, height: 1 });
250
+ }
251
+ start = -1;
252
+ }
253
+ }
254
+ for (const candidate of open) if (!next.includes(candidate)) done.push(candidate);
255
+ open = next;
256
+ }
257
+ return [...done, ...open];
258
+ }
259
+
101
260
  export function computeSurfaceVisibleFragments(
102
261
  rect: CellRect,
103
262
  visibleRect: CellRect | null,
@@ -126,7 +285,16 @@ export class NativeSurfaceManager {
126
285
  private readonly surfaces = new Map<string, SurfaceEntry>();
127
286
  private readonly localOccluders = new Map<string, NativeLocalOccluder>();
128
287
 
129
- constructor(private readonly renderer: CliRenderer) {}
288
+ private readonly onFrame = () => {
289
+ if (this.surfaces.size === 0) return;
290
+ this.frameSync();
291
+ };
292
+
293
+ constructor(private readonly renderer: CliRenderer) {
294
+ // Only a terminal host reports what its frames drew; then every frame it
295
+ // shows re-measures the anchored images and re-cuts them all.
296
+ if (renderer.frameHits && typeof renderer.on === "function") renderer.on("frame", this.onFrame);
297
+ }
130
298
 
131
299
  setWindowState(windowState: NativeWindowState) {
132
300
  if (sameWindowState(this.windowState, windowState)) {
@@ -139,7 +307,10 @@ export class NativeSurfaceManager {
139
307
  this.syncAll();
140
308
  }
141
309
 
142
- upsertSurface(snapshot: NativeSurfaceSnapshot) {
310
+ upsertSurface(incoming: NativeSurfaceSnapshot) {
311
+ // An anchored image goes where its box is in the frame on screen, which
312
+ // the rect React measured before that frame's layout can trail.
313
+ const snapshot = this.onScreen(incoming);
143
314
  const existing = this.surfaces.get(snapshot.id);
144
315
  if (existing) {
145
316
  if (sameSnapshot(existing.snapshot, snapshot)) {
@@ -208,21 +379,56 @@ export class NativeSurfaceManager {
208
379
  return [...this.surfaces.values()]
209
380
  .map(({ snapshot }) => ({ snapshot, zIndex: this.paneZIndex(snapshot.paneId) }))
210
381
  .sort((a, b) => a.zIndex - b.zIndex || (a.snapshot.imageZIndex ?? 0) - (b.snapshot.imageZIndex ?? 0))
211
- .map(({ snapshot, zIndex }) => ({
382
+ .map(({ snapshot }) => ({
212
383
  rect: snapshot.rect,
213
- fragments: computeSurfaceVisibleFragments(snapshot.rect, snapshot.visibleRect, zIndex, snapshot.paneId, occluders),
384
+ fragments: this.visibleFragments(snapshot, occluders),
214
385
  bitmap: snapshot.bitmap,
215
386
  }))
216
387
  .filter((image) => image.fragments.length > 0);
217
388
  }
218
389
 
219
390
  destroy() {
391
+ if (this.renderer.frameHits && typeof this.renderer.off === "function") this.renderer.off("frame", this.onFrame);
220
392
  for (const id of [...this.surfaces.keys()]) {
221
393
  this.removeSurface(id);
222
394
  }
223
395
  this.localOccluders.clear();
224
396
  }
225
397
 
398
+ /** After a frame: each anchored image where its box is now, each image off what now covers it. */
399
+ private frameSync() {
400
+ for (const entry of this.surfaces.values()) {
401
+ entry.snapshot = this.onScreen(entry.snapshot);
402
+ this.syncSurface(entry);
403
+ }
404
+ }
405
+
406
+ /** An anchored snapshot measured from its box as the frame on screen laid it out. */
407
+ private onScreen(snapshot: NativeSurfaceSnapshot): NativeSurfaceSnapshot {
408
+ const attached = this.renderer.frameHits?.attached;
409
+ if (!snapshot.anchor || !attached) return snapshot;
410
+ const measured = measureNativeSurfaceAnchor(snapshot.anchor, this.renderer.terminalWidth, this.renderer.terminalHeight, attached);
411
+ if (!measured) return snapshot.visibleRect === null ? snapshot : { ...snapshot, visibleRect: null };
412
+ if (sameCellRect(measured.rect, snapshot.rect) && sameCellRect(measured.visibleRect, snapshot.visibleRect)) return snapshot;
413
+ return { ...snapshot, rect: measured.rect, visibleRect: measured.visibleRect };
414
+ }
415
+
416
+ /** The cells of an image left to show: its visible rect, less the layout's occluders and whatever the frame drew over it. */
417
+ private visibleFragments(snapshot: NativeSurfaceSnapshot, occluders: NativeOccluder[]): CellRect[] {
418
+ const fragments = computeSurfaceVisibleFragments(
419
+ snapshot.rect,
420
+ snapshot.visibleRect,
421
+ this.paneZIndex(snapshot.paneId),
422
+ snapshot.paneId,
423
+ occluders,
424
+ );
425
+ const hits = this.renderer.frameHits;
426
+ if (!hits || !snapshot.anchor || fragments.length === 0) return fragments;
427
+ const covers = createCoverTest(snapshot.anchor.renderable, hits.paints);
428
+ const uncovered = fragments.flatMap((fragment) => uncoveredCellRects(fragment, (x, y) => covers(hits.at(x, y))));
429
+ return uncovered.length > MAX_UNCOVERED_FRAGMENTS ? [] : uncovered.sort(compareRects);
430
+ }
431
+
226
432
  private paneZIndex(paneId: string): number {
227
433
  return this.windowState.paneLayers.find((layer) => layer.paneId === paneId)?.zIndex ?? 0;
228
434
  }
@@ -249,13 +455,7 @@ export class NativeSurfaceManager {
249
455
  return;
250
456
  }
251
457
 
252
- const fragments = computeSurfaceVisibleFragments(
253
- entry.snapshot.rect,
254
- entry.snapshot.visibleRect,
255
- this.paneZIndex(entry.snapshot.paneId),
256
- entry.snapshot.paneId,
257
- this.resolvedOccluders(),
258
- );
458
+ const fragments = this.visibleFragments(entry.snapshot, this.resolvedOccluders());
259
459
 
260
460
  const placements = computeNativePlacements(
261
461
  entry.snapshot.rect,
@@ -2,6 +2,7 @@ import type { CommandBarResultLine } from "../../../types/plugin";
2
2
  import type { TickerRecord } from "../../../types/ticker";
3
3
  import type { BrokerContractRef, TickerListingRef } from "../../../types/instrument";
4
4
  import type { InstrumentRef } from "../../../market-data/request-types";
5
+ import { ASSIST_CATEGORY } from "../assist/model";
5
6
  import {
6
7
  buildSections,
7
8
  type CommandBarCategoryPriorities,
@@ -222,6 +223,14 @@ export function resolveListPageTarget(
222
223
  return target;
223
224
  }
224
225
 
226
+ /**
227
+ * Whether every row is the AI's offer (`Ask AI — sign up to enable`), which
228
+ * no Enter takes: nothing in the list answers what was typed.
229
+ */
230
+ function onlyAssistOffers(results: readonly ResultItem[]): boolean {
231
+ return results.length > 0 && results.every((item) => item.category === ASSIST_CATEGORY && !isDefaultSelectable(item));
232
+ }
233
+
225
234
  export function buildNativeListRows(listState: ListScreenState, rows: CommandBarListRow[]): CommandBarListRow[] {
226
235
  if (listState.searching && rows.length === 0) {
227
236
  return [{ kind: "spinner", id: "searching", label: "Searching…" }];
@@ -232,5 +241,9 @@ export function buildNativeListRows(listState: ListScreenState, rows: CommandBar
232
241
  if (listState.searching) {
233
242
  return [...rows, { kind: "spinner", id: "searching", label: "Searching…" }];
234
243
  }
244
+ // A query nothing matches says so above the offer, rather than leave the offer looking like the answer.
245
+ if (listState.query.trim() && onlyAssistOffers(listState.results)) {
246
+ return [{ kind: "message", id: "empty", label: listState.emptyLabel }, { kind: "spacer", id: "spacer:empty" }, ...rows];
247
+ }
235
248
  return rows;
236
249
  }
@@ -65,7 +65,6 @@ export function CommandBarPanel({
65
65
  onThemeCommit,
66
66
  onThemePreview,
67
67
  panelBounds,
68
- clearBounds = null,
69
68
  queryDisplayWidth,
70
69
  rootGhostSuffix,
71
70
  rootShortcutFeedback,
@@ -136,6 +135,8 @@ export function CommandBarPanel({
136
135
  return (
137
136
  // The click-away overlay starts where the sheet does: the header above it
138
137
  // holds the bar's input, and a click there must reach it, not close the bar.
138
+ // It draws nothing: the panes beside and below the sheet stay as they are,
139
+ // a chart image among them too, and only the sheet covers them.
139
140
  <Box
140
141
  position="absolute"
141
142
  top={panelBounds.y}
@@ -149,18 +150,6 @@ export function CommandBarPanel({
149
150
  onOverlayClose();
150
151
  }}
151
152
  >
152
- {/* The terminal sheet's rows are its own, edge to edge: no piece of a pane shows at its sides. */}
153
- {clearBounds && (
154
- <Box
155
- position="absolute"
156
- top={clearBounds.y}
157
- left={clearBounds.x}
158
- width={clearBounds.width}
159
- height={clearBounds.height}
160
- backgroundColor={palette.panelBg}
161
- zIndex={100}
162
- />
163
- )}
164
153
  <Box
165
154
  position="absolute"
166
155
  top={0}
@@ -27,13 +27,8 @@ export interface CommandBarPanelLayout {
27
27
  listBodyHeight: number;
28
28
  nativeOccluderRect: LayoutBounds;
29
29
  nativePanelPaddingColumns: number;
30
+ /** The sheet, the one thing the open bar covers: the panes beside and below it stay as they are. */
30
31
  panelBounds: LayoutBounds;
31
- /**
32
- * The rows the terminal sheet clears behind it, relative to its top, edge
33
- * to edge: a pane cut by the sheet's sides shows only pieces of its words
34
- * and borders. Null on the desktop, whose sheet is a floating surface.
35
- */
36
- clearBounds: LayoutBounds | null;
37
32
  queryDisplayWidth: number;
38
33
  labelWidth: number;
39
34
  trailingWidth: number;
@@ -154,7 +149,6 @@ export function resolveCommandBarPanelLayout({
154
149
  width: barWidth,
155
150
  height: barHeight,
156
151
  },
157
- clearBounds: nativePaneChrome ? null : { x: 0, y: 0, width: termWidth, height: barHeight },
158
152
  queryDisplayWidth,
159
153
  labelWidth,
160
154
  trailingWidth,
@@ -214,7 +214,6 @@ export function useCommandBarPanelRuntime({
214
214
  onThemeCommit: handleThemeCommit,
215
215
  onThemePreview: applyThemePreview,
216
216
  panelBounds: panelLayout.panelBounds,
217
- clearBounds: panelLayout.clearBounds,
218
217
  queryDisplayWidth: panelLayout.queryDisplayWidth,
219
218
  rootGhostSuffix,
220
219
  rootShortcutFeedback,
@@ -30,8 +30,6 @@ export interface CommandBarPanelProps {
30
30
  onThemeCommit: (themeId: string) => void;
31
31
  onThemePreview: (themeId: string | null) => void;
32
32
  panelBounds: LayoutBounds;
33
- /** What the terminal sheet clears behind it (see CommandBarPanelLayout); null on the desktop. */
34
- clearBounds?: LayoutBounds | null;
35
33
  queryDisplayWidth: number;
36
34
  rootGhostSuffix: string | null;
37
35
  rootShortcutFeedback: string | null;
@@ -97,6 +97,8 @@ export function useCommandBarTickerSearchActions({
97
97
  ...tickerSelectionFromSearchResult(candidate.result),
98
98
  label: candidate.label,
99
99
  instrumentType: candidate.instrumentType,
100
+ // The names search found the saved listing by ("micro" for MSFT): it is an exact match as its search row is.
101
+ searchAliases: candidate.searchAliases,
100
102
  detail,
101
103
  badge,
102
104
  name,
@@ -162,10 +162,15 @@ export function mergeTickerSearchResultItems(
162
162
  }
163
163
 
164
164
  const SEARCH_BUSY_ITEM_ID = "search-busy";
165
+ const SEARCH_ERROR_ITEM_ID = "search-error";
165
166
 
166
- /** The busy row among a search's rows: a list left with no instruments keeps it, so nothing there reads as no listing. */
167
- function searchBusyRows(items: readonly ResultItem[]): ResultItem[] {
168
- return items.filter((item) => item.id === SEARCH_BUSY_ITEM_ID);
167
+ /**
168
+ * The busy or failed row among a search's rows: a list left with no
169
+ * instruments keeps it, so a search that did not answer never reads as one
170
+ * that found nothing.
171
+ */
172
+ function searchStatusRows(items: readonly ResultItem[]): ResultItem[] {
173
+ return items.filter((item) => item.id === SEARCH_BUSY_ITEM_ID || item.id === SEARCH_ERROR_ITEM_ID);
169
174
  }
170
175
 
171
176
  /**
@@ -185,7 +190,7 @@ export function tickerSearchFailureItems(error: unknown, query: string, localIte
185
190
  }], localItems);
186
191
  }
187
192
  return [{
188
- id: "search-error",
193
+ id: SEARCH_ERROR_ITEM_ID,
189
194
  label: "Search failed",
190
195
  detail: "Check your connection",
191
196
  category: "Search",
@@ -213,7 +218,9 @@ function isInstrumentItem(item: ResultItem): boolean {
213
218
  * further exchange of one already shown, so Saputo's SAP on Toronto is not
214
219
  * pushed out by SAP SE's fourth German venue; the rows keep their ranked order.
215
220
  * Info rows ("no matches", "search failed") are dropped: the instruments are
216
- * an extra here, never the answer.
221
+ * an extra here, never the answer. With no instruments left, a busy or
222
+ * failed search keeps its row, and one that found nothing leaves the list to
223
+ * say so (`buildNativeListRows`).
217
224
  */
218
225
  export function mergePlainRootTickerResults(
219
226
  query: string,
@@ -253,8 +260,8 @@ export function mergePlainRootTickerResults(
253
260
  const commandNamed = wordNamesCommand(query, rootItems);
254
261
  rootItems = leadWithNamedCommands(query, rootItems);
255
262
  if (instruments.length === 0) {
256
- const busy = searchBusyRows(providerItems);
257
- return busy.length > 0 ? [...rootItems, ...busy] : rootItems;
263
+ const status = searchStatusRows(providerItems);
264
+ return status.length > 0 ? [...rootItems, ...status] : rootItems;
258
265
  }
259
266
 
260
267
  // A listing that stopped trading is still the one its symbol names (SIVB, TWTR), unless a live listing
@@ -432,7 +439,7 @@ export function venueDropdownResults(symbol: string, items: ResultItem[], suffix
432
439
  if (!venueMatchesSuffix(item, suffix)) continue;
433
440
  rows.push(item.category === "Exact Match" ? item : { ...item, category: "Exact Match" });
434
441
  }
435
- return rows.length > 0 ? rows : searchBusyRows(items);
442
+ return rows.length > 0 ? rows : searchStatusRows(items);
436
443
  }
437
444
 
438
445
  /**
@@ -44,6 +44,7 @@ import { resolveSelectionKeyHints } from "../selection-hint";
44
44
  import { findPaneInstance } from "../../../types/config";
45
45
  import { getBasePaneDisplayTitle } from "../../layout/pane/title";
46
46
  import { isDialogOpen } from "../../../ui/dialog-stack";
47
+ import { logFailure } from "../../../utils/log-failure";
47
48
 
48
49
  interface CommandBarProps {
49
50
  dataProvider: DataProvider;
@@ -194,7 +195,6 @@ export function CommandBar({
194
195
  openInlineConfirm,
195
196
  openModeRoute,
196
197
  openPaneTemplateWorkflow,
197
- openPluginCommandWorkflow,
198
198
  paneShortcutItems,
199
199
  persistLayoutChange,
200
200
  pluginCommandItems,
@@ -365,14 +365,19 @@ export function CommandBar({
365
365
  if (row) runRootRow({ item: row, query: rootQueryRef.current, rank, isShortcut: () => false }, run);
366
366
  else run();
367
367
  }, [assistState, rootQueryRef, runRootRow, visibleListStateRef]);
368
+ // The offer runs the step that turns the AI on: Sign Up, or for an account
369
+ // whose email is not verified yet, sending the verification again.
368
370
  const startAssistSignUp = useCallback(() => {
369
- const signUpCommand = getAvailablePluginCommands().find((command) => command.id === "auth-signup");
370
- if (signUpCommand?.wizard?.length) {
371
- openPluginCommandWorkflow(signUpCommand);
371
+ const commands = getAvailablePluginCommands();
372
+ const command = commands.find((candidate) => candidate.id === "auth-signup")
373
+ ?? commands.find((candidate) => candidate.id === "auth-resend-verification");
374
+ if (command) {
375
+ Promise.resolve(createPluginCommandItem(command).action())
376
+ .catch(logFailure("command-bar.assist", "Start sign up from the AI offer failed"));
372
377
  return;
373
378
  }
374
379
  setRootQuery("Sign Up");
375
- }, [getAvailablePluginCommands, openPluginCommandWorkflow, setRootQuery]);
380
+ }, [createPluginCommandItem, getAvailablePluginCommands, setRootQuery]);
376
381
  // The assistant pane ships with the cloud plugin, so the row only exists
377
382
  // while that pane template is registered.
378
383
  const askGloomTemplate = useMemo(() => (
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useRef } from "react";
2
- import { tf } from "../../../i18n";
2
+ import { t, tf } from "../../../i18n";
3
+ import { extendedSessionLineLabel, getLatestPrintDisplay, type SessionPriceDisplay } from "../../../market-data/market/status";
3
4
  import type { DataProvider } from "../../../types/data-provider";
4
5
  import type { Quote } from "../../../types/financials";
5
6
  import { coerceFieldString } from "../helpers";
@@ -24,8 +25,19 @@ function formatAlertWorkflowPrice(value: number): string {
24
25
  return Number.isFinite(value) ? String(value) : "";
25
26
  }
26
27
 
27
- function formatAlertWorkflowQuote(quote: Quote): string {
28
- const price = formatAlertWorkflowPrice(quote.price);
28
+ /**
29
+ * The price an alert is judged on, as the form shows it: the latest print, an
30
+ * extended-hours one named by its session (158.78 After-Hours), as `quote`
31
+ * names it beside Last.
32
+ */
33
+ function formatAlertWorkflowCurrentPrice(print: SessionPriceDisplay): string {
34
+ const price = formatAlertWorkflowPrice(print.price);
35
+ const session = print.session;
36
+ return session ? `${price} ${extendedSessionLineLabel({ ...print, session }, t)}` : price;
37
+ }
38
+
39
+ function formatAlertWorkflowQuote(quote: Quote, print: SessionPriceDisplay): string {
40
+ const price = formatAlertWorkflowCurrentPrice(print);
29
41
  const exchange = quote.fullExchangeName || quote.exchangeName || quote.listingExchangeName || "";
30
42
  const name = quote.name || quote.symbol;
31
43
  const source = quote.dataSource === "delayed" ? "delayed" : quote.dataSource || "";
@@ -113,11 +125,13 @@ export function useAlertWorkflowQuoteSync({
113
125
  void dataProvider.getQuote(alertWorkflowSymbol, "")
114
126
  .then((quote) => {
115
127
  if (quoteRequestRef.current !== requestId) return;
116
- if (!quote || typeof quote.price !== "number" || !Number.isFinite(quote.price)) {
128
+ // An alert is judged on the latest print, extended hours included: the target starts there.
129
+ const print = getLatestPrintDisplay(quote);
130
+ if (!quote || !print || !Number.isFinite(print.price)) {
117
131
  throw new Error(tf('No quote found for "{symbol}".', { symbol: alertWorkflowSymbol }));
118
132
  }
119
133
 
120
- const quotePrice = formatAlertWorkflowPrice(quote.price);
134
+ const quotePrice = formatAlertWorkflowPrice(print.price);
121
135
  updateRoute((route) => {
122
136
  if (!isSetAlertWorkflow(route)) return route;
123
137
  if (normalizeAlertWorkflowSymbol(route.values.symbol) !== alertWorkflowSymbol) return route;
@@ -133,8 +147,8 @@ export function useAlertWorkflowQuoteSync({
133
147
  ...route,
134
148
  values: nextValues,
135
149
  fields: updateAlertWorkflowFieldDescriptions(route.fields, {
136
- symbol: formatAlertWorkflowQuote(quote),
137
- price: tf("Current price {price}; edit to set the target.", { price: quotePrice }),
150
+ symbol: formatAlertWorkflowQuote(quote, print),
151
+ price: tf("Current price {price}; edit to set the target.", { price: formatAlertWorkflowCurrentPrice(print) }),
138
152
  }),
139
153
  payloadMeta: {
140
154
  ...(route.payloadMeta ?? {}),
@@ -0,0 +1,89 @@
1
+ import { useMemo, useRef } from "react";
2
+ import { t, tf } from "../../i18n";
3
+ import type { ContextMenuItem } from "../../types/context-menu";
4
+ import { useOptionalDialog, type PromptContext } from "../../ui/dialog";
5
+ import { logFailure } from "../../utils/log-failure";
6
+ import { ChoiceDialog } from "../ui/choice-dialog";
7
+ import type { DataTableColumn } from "../ui";
8
+
9
+ const NO_ITEMS: readonly ContextMenuItem[] = [];
10
+
11
+ function columnName(column: DataTableColumn): string {
12
+ return column.label.trim() || column.title || column.id;
13
+ }
14
+
15
+ /**
16
+ * The pane menu's column entries while the table is focused: "Move Column…"
17
+ * does a header drag from the keyboard (a column, then the one it should
18
+ * follow), and "Reset Columns" puts the pane's own order back once the reader
19
+ * has changed it.
20
+ */
21
+ export function useDataTableColumnMenuItems({
22
+ enabled,
23
+ columns,
24
+ anchoredColumns,
25
+ onColumnMove,
26
+ customized,
27
+ reset,
28
+ }: {
29
+ enabled: boolean;
30
+ columns: readonly DataTableColumn[];
31
+ anchoredColumns: number;
32
+ onColumnMove?: (columnId: string, toIndex: number) => void;
33
+ customized: boolean;
34
+ reset: () => void;
35
+ }): readonly ContextMenuItem[] {
36
+ const dialog = useOptionalDialog();
37
+ const latest = useRef({ columns, anchoredColumns, onColumnMove });
38
+ latest.current = { columns, anchoredColumns, onColumnMove };
39
+ const movable = !!onColumnMove && columns.length - anchoredColumns >= 2;
40
+
41
+ return useMemo(() => {
42
+ if (!enabled || !movable) return NO_ITEMS;
43
+ const move = async () => {
44
+ if (!dialog) return;
45
+ const current = latest.current;
46
+ const columnId = await dialog.prompt<string>({
47
+ closeOnClickOutside: true,
48
+ content: (ctx: PromptContext<string>) => (
49
+ <ChoiceDialog
50
+ {...ctx}
51
+ title={t("Move Column")}
52
+ choices={current.columns.slice(current.anchoredColumns).map((column) => ({ id: column.id, label: columnName(column) }))}
53
+ />
54
+ ),
55
+ });
56
+ const from = current.columns.findIndex((column) => column.id === columnId);
57
+ if (!columnId || from < 0) return;
58
+ // After the column it should follow: the one it follows now is chosen to begin with.
59
+ const others = current.columns.filter((column) => column.id !== columnId);
60
+ const start = Math.max(0, current.anchoredColumns - 1);
61
+ const target = await dialog.prompt<string>({
62
+ closeOnClickOutside: true,
63
+ content: (ctx: PromptContext<string>) => (
64
+ <ChoiceDialog
65
+ {...ctx}
66
+ title={tf("Move {column}", { column: columnName(current.columns[from]!) })}
67
+ selectedChoiceId={String(from)}
68
+ choices={[
69
+ ...current.anchoredColumns === 0 ? [{ id: "0", label: t("First") }] : [],
70
+ ...others.slice(start).map((column, index) => ({
71
+ id: String(start + index + 1),
72
+ label: tf("After {column}", { column: columnName(column) }),
73
+ })),
74
+ ]}
75
+ />
76
+ ),
77
+ });
78
+ if (target) latest.current.onColumnMove?.(columnId, Number(target));
79
+ };
80
+ return [
81
+ ...dialog ? [{
82
+ id: "move-column",
83
+ label: "Move Column…",
84
+ onSelect: () => move().catch(logFailure("data-table", "Move Column failed")),
85
+ }] : [],
86
+ ...customized ? [{ id: "reset-columns", label: "Reset Columns", onSelect: reset }] : [],
87
+ ];
88
+ }, [customized, dialog, enabled, movable, reset]);
89
+ }