@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
@@ -39,6 +39,7 @@ import {
39
39
  NO_LATCH,
40
40
  snapMovedRect,
41
41
  snapResizedRect,
42
+ TERMINAL_MAGNET_REST_MS,
42
43
  type MagnetDistances,
43
44
  type MagnetGlide,
44
45
  type MagnetLatch,
@@ -203,15 +204,16 @@ export function useShellActiveDrag({
203
204
  return { rect, partners: rects };
204
205
  };
205
206
  const magnetArea = { x: 0, y: 0, width, height: contentHeight };
206
- // Desktop: past the travel speed a release lands the pane where the
207
- // pointer puts it, its magnets left out (the rest check runs the last move
208
- // again once the pointer has stopped, so a release then catches). What
209
- // they hold to still follows every move, so it rests where it would have.
207
+ // The move run again once the pointer rests. A release lands where the
208
+ // pane is drawn: no catch after it.
209
+ const runAgain = event.type === "drag" ? () => { if (dragRef.current === drag) handleRef.current(event); } : undefined;
210
+ // Past the travel speed a release lands the pane where the pointer puts
211
+ // it, its magnets left out (the rest check runs the last move again once
212
+ // the pointer has stopped, so a release then catches). What they hold to
213
+ // still follows every move, so it rests where it would have.
210
214
  const travelling = () => {
211
- if (!nativePaneChrome || drag.type !== "pane-drag") return false;
212
- // A release lands where the pane is drawn: no catch after it.
213
- const rest = event.type === "drag" ? () => { if (dragRef.current === drag) handleRef.current(event); } : undefined;
214
- return memo.pace.travelling({ t: performance.now(), x: preciseX, y: preciseShellY }, magnetDistances, rest);
215
+ if (drag.type !== "pane-drag") return false;
216
+ return memo.pace.travelling({ t: performance.now(), x: preciseX, y: preciseShellY }, magnetDistances, runAgain);
215
217
  };
216
218
  // Where a move lands the pane (`rect`), and where its magnets hold it as
217
219
  // the pointer slows down (`snapped`).
@@ -224,13 +226,16 @@ export function useShellActiveDrag({
224
226
  memo.latch = snapped.latch;
225
227
  return { rect: travelling() ? rect : snapped.rect, snapped: snapped.rect };
226
228
  };
227
- // Desktop: the moving pane is drawn under the pointer while it moves, and
228
- // where its magnets hold it once the pointer slows down to place it,
229
- // gliding between the two (the frames after the pointer stops carry the
230
- // glide on). The terminal draws where a release would land it.
229
+ // The moving pane is drawn under the pointer while it moves, and where
230
+ // its magnets hold it once the pointer slows down to place it. The
231
+ // desktop glides between the two (the frames after the pointer stops
232
+ // carry the glide on); the terminal steps onto the magnets, on the move
233
+ // run again once the pointer rests.
231
234
  const drawMove = (paneId: string, free: FloatingRect, moved: { rect: FloatingRect; snapped: FloatingRect }) => {
232
235
  if (!nativePaneChrome) {
233
- updateDragFloatingRect({ paneId, rect: moved.rect });
236
+ const placing = memo.pace.placing(performance.now(), magnetDistances);
237
+ updateDragFloatingRect({ paneId, rect: placing ? moved.snapped : free });
238
+ if (!placing && runAgain) memo.pace.rest(runAgain, TERMINAL_MAGNET_REST_MS);
234
239
  return;
235
240
  }
236
241
  const { snapped } = moved;
@@ -37,16 +37,17 @@ const MAGNET_RELEASE_PX = 12;
37
37
  const TERMINAL_MAGNETS: MagnetDistances = { catchX: 1, catchY: 1, releaseX: 2, releaseY: 2 };
38
38
 
39
39
  /**
40
- * Desktop: past this pointer speed, in catch distances a second (300 px/s),
41
- * a release lands the pane where the pointer puts it, its magnets left out.
40
+ * Past this pointer speed, in catch distances a second (300 px/s on the
41
+ * desktop, 37.5 cells in the terminal), a release lands the pane where the
42
+ * pointer puts it, its magnets left out.
42
43
  */
43
44
  const MAGNET_TRAVEL_SPEED = 300 / MAGNET_CATCH_PX;
44
45
  /**
45
- * Desktop: below this pointer speed (60 px/s, about a px a frame) the pointer
46
- * is placing the pane, and it is drawn where its magnets hold it; faster, it
47
- * is drawn under the pointer. Drawing the magnets at a hand's usual speed
48
- * held the pane on each line it crossed, then jumped it up to 18 px, which
49
- * read as a drag that lags and stutters.
46
+ * Below this pointer speed (60 px/s, about a px a frame) the pointer is
47
+ * placing the pane, and it is drawn where its magnets hold it; faster, it is
48
+ * drawn under the pointer. Drawing the magnets at a hand's usual speed held
49
+ * the pane on each line it crossed, then jumped it up to 18 px (three cells
50
+ * in the terminal), which read as a drag that lags and stutters.
50
51
  */
51
52
  const MAGNET_PLACE_SPEED = 60 / MAGNET_CATCH_PX;
52
53
  /**
@@ -59,6 +60,12 @@ const GLIDE_RATE = 35;
59
60
  const SPEED_WINDOW_MS = 64;
60
61
  /** How long the pointer rests before the magnets catch where it stopped, ms. */
61
62
  export const MAGNET_REST_MS = 80;
63
+ /**
64
+ * The same in the terminal, which hears from the pointer only as it enters
65
+ * another cell: a hand placing a window there crosses five or so a second, so
66
+ * a pause shorter than that is still a drag.
67
+ */
68
+ export const TERMINAL_MAGNET_REST_MS = 200;
62
69
 
63
70
  /** Where the pointer was during a move, in cells, and when (ms). */
64
71
  interface PointerSample {
@@ -75,7 +82,7 @@ function trackPointer(track: PointerSample[], sample: PointerSample): void {
75
82
  }
76
83
 
77
84
  /**
78
- * Desktop: when a moving pane's magnets act, over one drag. `travelling`
85
+ * When a moving pane's magnets act, over one drag. `travelling`
79
86
  * takes each move and says whether the pointer is on its way somewhere; while
80
87
  * it is, a release lands the pane where the pointer puts it, and `rest` (the
81
88
  * move run again) is set to run once the pointer has stopped for
@@ -90,6 +97,12 @@ export interface MagnetPace {
90
97
  travelling(sample: PointerSample, distances: MagnetDistances, rest?: () => void): boolean;
91
98
  /** Whether the pointer, as of `now`, moves slowly enough to be placing the pane: its magnets are drawn. */
92
99
  placing(now: number, distances: MagnetDistances): boolean;
100
+ /**
101
+ * Runs `onRest` once the pointer has stopped for `ms`, unless another event
102
+ * of the drag comes first: the terminal, which draws only when an event
103
+ * comes, draws the magnets that catch where it stopped.
104
+ */
105
+ rest(onRest: () => void, ms: number): void;
93
106
  /** Drops the rest check: another event of the drag came first. */
94
107
  cancel(): void;
95
108
  /** Forgets the pointer's path, for a new drag. */
@@ -106,6 +119,17 @@ export function createMagnetPace(): MagnetPace {
106
119
  rest = null;
107
120
  frame = null;
108
121
  };
122
+ const restThen = (onRest: () => void, ms = MAGNET_REST_MS) => {
123
+ cancel();
124
+ rest = setTimeout(() => {
125
+ rest = null;
126
+ if (typeof requestAnimationFrame !== "function") return onRest();
127
+ frame = requestAnimationFrame(() => {
128
+ frame = null;
129
+ onRest();
130
+ });
131
+ }, ms);
132
+ };
109
133
  return {
110
134
  travelling(sample, distances, onRest) {
111
135
  cancel();
@@ -113,19 +137,11 @@ export function createMagnetPace(): MagnetPace {
113
137
  // The same place again (a rest check, a repeated event) is not a move.
114
138
  if (!last || last.x !== sample.x || last.y !== sample.y) trackPointer(track, sample);
115
139
  if (pointerSpeed(track, sample.t, distances) <= MAGNET_TRAVEL_SPEED) return false;
116
- if (onRest) {
117
- rest = setTimeout(() => {
118
- rest = null;
119
- if (typeof requestAnimationFrame !== "function") return onRest();
120
- frame = requestAnimationFrame(() => {
121
- frame = null;
122
- onRest();
123
- });
124
- }, MAGNET_REST_MS);
125
- }
140
+ if (onRest) restThen(onRest);
126
141
  return true;
127
142
  },
128
143
  placing: (now, distances) => pointerSpeed(track, now, distances) < MAGNET_PLACE_SPEED,
144
+ rest: restThen,
129
145
  cancel,
130
146
  reset() {
131
147
  cancel();
@@ -13,6 +13,7 @@ import {
13
13
  import { useThemeColors } from "../../theme/theme-context";
14
14
  import { t } from "../../i18n";
15
15
  import { clipToDisplayWidth, padTo } from "../../utils/format";
16
+ import { readableError } from "../../utils/reason-codes";
16
17
  import type { FloatMetricTreemapTile, MetricTreemapItem } from "./layout";
17
18
  import {
18
19
  buildMetricTreemapScene,
@@ -820,7 +821,7 @@ export function HeatTreemapSurface<T>(props: HeatTreemapSurfaceProps<T>) {
820
821
  if (props.scene.tiles.length === 0) {
821
822
  return (
822
823
  <Box width={props.width} height={props.height} paddingX={1} paddingY={1}>
823
- <Text fg={colors.textDim}>{t(props.emptyStateTitle ?? "No chart data")}</Text>
824
+ <Text fg={colors.textDim}>{t(readableError(props.emptyStateTitle ?? "No chart data"))}</Text>
824
825
  </Box>
825
826
  );
826
827
  }
@@ -4,6 +4,7 @@ import { blendHex, colors, priceColor } from "../../theme/colors";
4
4
  import { blendForContrast, higherContrast } from "../../theme/color-utils";
5
5
  import { t } from "../../i18n";
6
6
  import { padTo } from "../../utils/format";
7
+ import { readableError } from "../../utils/reason-codes";
7
8
  import {
8
9
  buildMetricTreemap,
9
10
  buildMetricTreemapRects,
@@ -249,7 +250,7 @@ function DesktopMetricTreemapSurface<T>({ items, width, height, selectedId, onSe
249
250
  if (tiles.length === 0) {
250
251
  return (
251
252
  <Box width={width} height={height} paddingX={1} paddingY={1}>
252
- <Text fg={colors.textDim}>{t(emptyStateTitle ?? "No chart data")}</Text>
253
+ <Text fg={colors.textDim}>{t(readableError(emptyStateTitle ?? "No chart data"))}</Text>
253
254
  </Box>
254
255
  );
255
256
  }
@@ -328,7 +329,7 @@ export function MetricTreemapSurface<T>({
328
329
  if (tiles.length === 0) {
329
330
  return (
330
331
  <Box width={width} height={height} paddingX={1} paddingY={1}>
331
- <Text fg={colors.textDim}>{t(emptyStateTitle ?? "No chart data")}</Text>
332
+ <Text fg={colors.textDim}>{t(readableError(emptyStateTitle ?? "No chart data"))}</Text>
332
333
  </Box>
333
334
  );
334
335
  }
@@ -26,6 +26,7 @@ import type { TickerRecord } from "../../types/ticker";
26
26
  import { PRICE_SPARKLINE_COLUMN_ID, PriceSparkline } from "../price-sparkline/view";
27
27
  import { DataTableView, type DataTableKeyEvent, type DataTableSelection } from "../data-table/view";
28
28
  import type { QuoteFlashDirection } from "../quote-flash";
29
+ import type { DataTableColumnReorder } from "../ui";
29
30
  import { objectVersion } from "../../utils/object-version";
30
31
  import { getCompletedRegularSessionDisplay } from "../../market-data/market/status";
31
32
  import { QUOTE_EXPORT_IDENTITY_HEADERS, quoteExportIdentityCells } from "../../market-data/quotes/export-identity";
@@ -152,6 +153,8 @@ export interface TickerListTableViewProps {
152
153
  addTickerShortcut?: string;
153
154
  virtualize?: boolean;
154
155
  overscan?: number;
156
+ /** How the header drags reorder the columns (`DataTableProps.columnReorder`). */
157
+ columnReorder?: false | DataTableColumnReorder;
155
158
  }
156
159
 
157
160
  const FLASHABLE_QUOTE_COLUMN_IDS = new Set([
@@ -287,6 +290,7 @@ export function TickerListTableView({
287
290
  virtualize = true,
288
291
  overscan = 4,
289
292
  exportName,
293
+ columnReorder,
290
294
  }: TickerListTableViewProps) {
291
295
  const commandBarShortcut = useCommandBarShortcut();
292
296
  const resolvedEmptyHint = emptyHint ?? tf("Press {shortcut} to add one.", { shortcut: addTickerShortcut ?? commandBarShortcut });
@@ -445,6 +449,7 @@ export function TickerListTableView({
445
449
  <DataTableView<TickerRecord, ColumnConfig>
446
450
  focused={focused}
447
451
  columns={columns}
452
+ columnReorder={columnReorder}
448
453
  items={items}
449
454
  isNavigable={summaries.length ? isNavigableRow : undefined}
450
455
  sortColumnId={sortColumnId ?? null}
@@ -1,13 +1,39 @@
1
- import { useCallback, useRef, type ReactNode } from "react";
2
- import { Box, Text, useUiHost } from "../../ui";
1
+ import { useCallback, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";
2
+ import { Box, Text, TextAttributes, useUiHost } from "../../ui";
3
3
  import { colors } from "../../theme/colors";
4
4
  import { t, tf } from "../../i18n";
5
5
  import { type DialogApi, type PromptContext, useDialogKeyboard } from "../../ui/dialog";
6
+ import type { InputRenderable } from "../../ui/host";
7
+ import type { KeyEventLike } from "../../react/input";
6
8
  import { isPlainKey } from "../../utils/keyboard";
7
9
  import { Button, type ButtonVariant } from "./button";
8
10
  import { DialogActions } from "./dialog-actions";
11
+ import { TextField } from "./fields";
9
12
  import { DialogFrame, fitDialogWidth } from "./frame";
13
+ import { ListView, listCursorMove, type ListViewItem } from "./list-view";
10
14
  import { logFailure } from "../../utils/log-failure";
15
+ import { sliceWholeCharacters } from "../../utils/untrusted-text";
16
+
17
+ /**
18
+ * An optional question a confirm asks under its body, such as why: one of a
19
+ * few choices and a short note. Nothing in it is required and it adds no
20
+ * step: the buttons and keys answer the dialog as they do without it.
21
+ */
22
+ export interface ConfirmDialogQuestion {
23
+ /** Over the choices, e.g. "What made you decide to cancel? (optional)". */
24
+ label: string;
25
+ choices: ReadonlyArray<{ id: string; label: string }>;
26
+ /** The note field's placeholder; left out, the dialog asks for no note. */
27
+ notePlaceholder?: string;
28
+ /** The most characters the note takes. */
29
+ noteMaxLength?: number;
30
+ }
31
+
32
+ /** What a confirm's question got: the choice picked and the note, trimmed, when there was one. */
33
+ export interface ConfirmDialogAnswer {
34
+ choice?: string;
35
+ note?: string;
36
+ }
11
37
 
12
38
  export interface ConfirmDialogProps extends PromptContext<boolean> {
13
39
  title: string;
@@ -43,6 +69,15 @@ export interface ConfirmDialogProps extends PromptContext<boolean> {
43
69
  * and only `y` or the confirm button confirms.
44
70
  */
45
71
  defaultAction?: "confirm" | "cancel";
72
+ /**
73
+ * Asks an optional question under the body. The arrows pick a choice, and
74
+ * Space or a click on the picked one clears it. Tab moves into the note and
75
+ * back; while the note has the keys, what is typed goes there, Enter leaves
76
+ * it and only Esc answers the dialog.
77
+ */
78
+ question?: ConfirmDialogQuestion;
79
+ /** With `question`: what it got, called as the dialog confirms. */
80
+ onAnswer?: (answer: ConfirmDialogAnswer) => void;
46
81
  }
47
82
 
48
83
  export function ConfirmDialog({
@@ -60,16 +95,28 @@ export function ConfirmDialog({
60
95
  formButtons = false,
61
96
  keyGraceMs = 0,
62
97
  defaultAction = "confirm",
98
+ question,
99
+ onAnswer,
63
100
  }: ConfirmDialogProps) {
64
101
  const enterCancels = defaultAction === "cancel";
65
102
  const desktop = useUiHost().kind === "desktop-web";
66
103
  const openedAt = useRef(Date.now());
67
- const confirm = useCallback(() => resolve(true), [resolve]);
104
+ const answer = useQuestionAnswer(question);
105
+ const confirm = useCallback(() => {
106
+ if (question) onAnswer?.(answer.read());
107
+ resolve(true);
108
+ }, [answer, onAnswer, question, resolve]);
68
109
  const cancel = useCallback(() => resolve(false), [resolve]);
69
110
 
70
111
  // Every key, even with a field focused under the dialog: a confirm has
71
- // nothing to type into, so nothing below should take one.
112
+ // nothing to type into but its own note, so nothing below should take one.
72
113
  useDialogKeyboard((event) => {
114
+ // The note takes what is typed, `y` and `n` included. Stopping a key here
115
+ // would keep it from the note too, so only the dialog's own keys stop.
116
+ if (question && answer.noteHasKeys(event) && event.name !== "escape") {
117
+ answer.handleNoteKey(event);
118
+ return;
119
+ }
73
120
  event.stopPropagation();
74
121
  if (event.name === "escape") {
75
122
  event.preventDefault();
@@ -81,6 +128,7 @@ export function ConfirmDialog({
81
128
  return;
82
129
  }
83
130
  const enter = event.name === "enter" || event.name === "return";
131
+ if (question && answer.handleKey(event)) return;
84
132
  if (enter && enterCancels) {
85
133
  event.preventDefault();
86
134
  cancel();
@@ -97,7 +145,7 @@ export function ConfirmDialog({
97
145
  cancel();
98
146
  return;
99
147
  }
100
- // Two buttons and nothing to type: Tab has nowhere to go.
148
+ // Two buttons and nothing to type (a note takes Tab above): Tab has nowhere to go.
101
149
  if (event.name === "tab") event.preventDefault();
102
150
  }, { allowEditable: true });
103
151
 
@@ -115,8 +163,11 @@ export function ConfirmDialog({
115
163
  />
116
164
  );
117
165
  const cancelButton = <Button label={cancelLabel} variant={enterCancels ? "primary" : "secondary"} disabled={busy} desktopShortcut={keys ? (enterCancels ? "Enter" : "Esc") : undefined} onPress={cancel} />;
166
+ const noteKey = question?.notePlaceholder !== undefined;
118
167
  const keyLine = enterCancels
119
- ? tf("y {action} · Enter or Esc {cancel}", { action: t(confirmLabel).toLowerCase(), cancel: t(cancelLabel).toLowerCase() })
168
+ ? noteKey
169
+ ? tf("y {action} · Tab note · Enter or Esc {cancel}", { action: t(confirmLabel).toLowerCase(), cancel: t(cancelLabel).toLowerCase() })
170
+ : tf("y {action} · Enter or Esc {cancel}", { action: t(confirmLabel).toLowerCase(), cancel: t(cancelLabel).toLowerCase() })
120
171
  : tf("Enter {action} · Esc cancel", { action: t(confirmLabel).toLowerCase() });
121
172
  return (
122
173
  <DialogFrame
@@ -127,6 +178,12 @@ export function ConfirmDialog({
127
178
  >
128
179
  <Box flexDirection="column" {...(desktop ? { style: { width: fitDialogWidth(width) } } : { width })}>
129
180
  {renderBody(body)}
181
+ {question && (
182
+ <>
183
+ <Box height={1} />
184
+ <QuestionFields question={question} answer={answer} width={width} disabled={busy} />
185
+ </>
186
+ )}
130
187
  {status && (
131
188
  <>
132
189
  <Box height={1} />
@@ -134,7 +191,10 @@ export function ConfirmDialog({
134
191
  </>
135
192
  )}
136
193
  <Box height={1} />
137
- <DialogActions alignEnd={formButtons}>
194
+ <DialogActions
195
+ alignEnd={formButtons}
196
+ hints={question && keys ? { keys: [{ key: "↑↓", label: "choose" }, ...noteKey ? [{ key: "Tab", label: "note" }] : []] } : undefined}
197
+ >
138
198
  {formButtons ? cancelButton : confirmButton}
139
199
  {formButtons ? confirmButton : cancelButton}
140
200
  </DialogActions>
@@ -143,6 +203,175 @@ export function ConfirmDialog({
143
203
  );
144
204
  }
145
205
 
206
+ interface QuestionAnswer {
207
+ items: ListViewItem[];
208
+ choiceIndex: number;
209
+ note: string;
210
+ noteFocused: boolean;
211
+ noteInputRef: RefObject<InputRenderable | null>;
212
+ /** A click or Space on a choice: picks it, or clears it when it was the one picked. */
213
+ toggle(index: number): void;
214
+ setNote(note: string): void;
215
+ /** Moves the keyboard into the note or out of it, the field's own focus with it. */
216
+ focusNote(focused: boolean): void;
217
+ read(): ConfirmDialogAnswer;
218
+ /**
219
+ * Whether the note has the keys, ahead of the render that shows it. Only the
220
+ * note itself: a field under the dialog that kept the focus takes nothing
221
+ * from the dialog, which answers `y` and Enter as it does without a note.
222
+ */
223
+ noteHasKeys(event: KeyEventLike): boolean;
224
+ /** A key while the note has the keys: Tab and Enter leave it; the rest is typing. */
225
+ handleNoteKey(event: KeyEventLike): void;
226
+ /**
227
+ * A key while the note does not have them: the arrows pick, Space clears
228
+ * the choice or picks it back, Tab enters the note. True when it was one.
229
+ */
230
+ handleKey(event: KeyEventLike): boolean;
231
+ }
232
+
233
+ function isTabKey(event: KeyEventLike): boolean {
234
+ return event.name === "tab" && !event.ctrl && !event.meta && !event.alt;
235
+ }
236
+
237
+ function useQuestionAnswer(question: ConfirmDialogQuestion | undefined): QuestionAnswer {
238
+ const items = useMemo<ListViewItem[]>(() => (question?.choices ?? []).map(({ id, label }) => ({ id, label: t(label) })), [question?.choices]);
239
+ const [choiceIndex, setChoiceIndex] = useState(-1);
240
+ const [note, setNoteState] = useState("");
241
+ const [noteFocused, setNoteFocused] = useState(false);
242
+ // Terminal input can deliver a pick, the note and `y` before React renders.
243
+ const choiceRef = useRef(-1);
244
+ // The choice last picked, where the arrows and Space go on from once it is cleared.
245
+ const cursorRef = useRef(-1);
246
+ const noteRef = useRef("");
247
+ const noteFocusedRef = useRef(false);
248
+ const noteInputRef = useRef<InputRenderable | null>(null);
249
+ const hasNote = question?.notePlaceholder !== undefined;
250
+ const setChoice = (index: number) => {
251
+ if (index < -1 || index >= items.length) return;
252
+ if (index >= 0) cursorRef.current = index;
253
+ choiceRef.current = index;
254
+ setChoiceIndex(index);
255
+ };
256
+ // No reason stays a choice: the picked one clears.
257
+ const toggle = (index: number) => setChoice(index === choiceRef.current ? -1 : index);
258
+ const setNote = (next: string) => {
259
+ noteRef.current = next;
260
+ setNoteState(next);
261
+ };
262
+ const focusNote = (focused: boolean) => {
263
+ const next = focused && hasNote;
264
+ noteFocusedRef.current = next;
265
+ setNoteFocused(next);
266
+ // Now, not on the render the flag makes: the next key must find the field
267
+ // that has it, and a note left must not take Enter or `y` as typing.
268
+ if (next) noteInputRef.current?.focus?.();
269
+ else noteInputRef.current?.blur?.();
270
+ };
271
+ return {
272
+ items,
273
+ choiceIndex,
274
+ note,
275
+ noteFocused,
276
+ noteInputRef,
277
+ toggle,
278
+ setNote,
279
+ focusNote,
280
+ read: () => {
281
+ const choice = question?.choices[choiceRef.current]?.id;
282
+ const trimmed = sliceWholeCharacters(noteRef.current.trim(), question?.noteMaxLength ?? Infinity);
283
+ return { ...(choice ? { choice } : {}), ...(hasNote && trimmed ? { note: trimmed } : {}) };
284
+ },
285
+ noteHasKeys: (event) => {
286
+ if (!noteFocusedRef.current) return false;
287
+ if (event.targetEditable === true && noteInputRef.current?.focused === true) return true;
288
+ // The note lost the keys without saying so: they are the dialog's, and the note stops showing them.
289
+ focusNote(false);
290
+ return false;
291
+ },
292
+ handleNoteKey: (event) => {
293
+ if (!isTabKey(event) && event.name !== "enter" && event.name !== "return") return;
294
+ event.preventDefault();
295
+ event.stopPropagation();
296
+ focusNote(false);
297
+ },
298
+ handleKey: (event) => {
299
+ if (hasNote && isTabKey(event)) {
300
+ event.preventDefault();
301
+ focusNote(true);
302
+ return true;
303
+ }
304
+ if (isPlainKey(event, "space")) {
305
+ event.preventDefault();
306
+ if (cursorRef.current >= 0) toggle(cursorRef.current);
307
+ return true;
308
+ }
309
+ const move = listCursorMove(event, items.length);
310
+ if (!move) return false;
311
+ event.preventDefault();
312
+ setChoice(move(items, choiceRef.current >= 0 ? choiceRef.current : cursorRef.current));
313
+ return true;
314
+ },
315
+ };
316
+ }
317
+
318
+ function QuestionFields({
319
+ question,
320
+ answer,
321
+ width,
322
+ disabled,
323
+ }: {
324
+ question: ConfirmDialogQuestion;
325
+ answer: QuestionAnswer;
326
+ width: number;
327
+ disabled: boolean;
328
+ }) {
329
+ const desktop = useUiHost().kind === "desktop-web";
330
+ const label = t(question.label);
331
+ return (
332
+ <Box flexDirection="column">
333
+ {/* A form label, as a TextField draws its own: bold and a row above its control on the desktop. */}
334
+ <Box height={1}>
335
+ <Text fg={colors.textDim} attributes={desktop ? TextAttributes.BOLD : 0}>{label}</Text>
336
+ </Box>
337
+ {desktop && <Box height={1} />}
338
+ <ListView
339
+ items={answer.items}
340
+ selectedIndex={answer.choiceIndex}
341
+ remoteLabel={label}
342
+ rowGap={0}
343
+ surface="framed"
344
+ height={answer.items.length}
345
+ // Enter answers the dialog, a focused choice too: Space picks or clears it.
346
+ checkboxRows
347
+ onSelect={(index) => {
348
+ if (disabled) return;
349
+ answer.focusNote(false);
350
+ answer.toggle(index);
351
+ }}
352
+ />
353
+ {question.notePlaceholder !== undefined && (
354
+ <>
355
+ <Box height={1} />
356
+ <TextField
357
+ accessibleLabel={t(question.notePlaceholder)}
358
+ value={answer.note}
359
+ placeholder={t(question.notePlaceholder)}
360
+ maxLength={question.noteMaxLength}
361
+ focused={answer.noteFocused}
362
+ inputRef={answer.noteInputRef}
363
+ disabled={disabled}
364
+ width={desktop ? undefined : width}
365
+ onMouseDown={() => answer.focusNote(true)}
366
+ onBlur={() => answer.focusNote(false)}
367
+ onChange={answer.setNote}
368
+ />
369
+ </>
370
+ )}
371
+ </Box>
372
+ );
373
+ }
374
+
146
375
  export type ConfirmDialogOptions = Omit<ConfirmDialogProps, keyof PromptContext<boolean>> & {
147
376
  /** A click on the backdrop cancels. On by default. */
148
377
  closeOnClickOutside?: boolean;
@@ -163,6 +392,23 @@ export async function confirmDialog(
163
392
  return confirmed === true;
164
393
  }
165
394
 
395
+ /**
396
+ * A confirmDialog that asks `question` under its body: the answer when the
397
+ * person confirms, empty when they skipped the question, and null when they
398
+ * cancelled (Cancel, Esc, a click outside or a failed dialog).
399
+ */
400
+ export async function confirmDialogWithAnswer(
401
+ dialog: DialogApi,
402
+ { closeOnClickOutside = true, ...props }: ConfirmDialogOptions & { question: ConfirmDialogQuestion },
403
+ ): Promise<ConfirmDialogAnswer | null> {
404
+ let answer: ConfirmDialogAnswer = {};
405
+ const confirmed = await dialog.prompt<boolean>({
406
+ closeOnClickOutside,
407
+ content: (context) => <ConfirmDialog {...context} {...props} onAnswer={(next) => { answer = next; }} />,
408
+ }).catch(logFailure("ui.confirm-dialog", "Open confirm dialog failed", false));
409
+ return confirmed === true ? answer : null;
410
+ }
411
+
166
412
  function renderBody(body: ReactNode | string | string[]): ReactNode {
167
413
  if (Array.isArray(body)) {
168
414
  return body.map((line, index) => (