gloomberb 0.20.8 → 0.20.10

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 (165) hide show
  1. package/package.json +1 -1
  2. package/src/api-client/auth.ts +6 -0
  3. package/src/api-client/data.ts +1 -0
  4. package/src/api-client/earnings.ts +15 -0
  5. package/src/api-client/futures-curve.ts +5 -1
  6. package/src/api-client/index.ts +14 -3
  7. package/src/api-client/types/account.ts +10 -0
  8. package/src/api-client/types/billing.ts +10 -0
  9. package/src/api-client/types/econ.ts +19 -7
  10. package/src/api-client/types/market.ts +7 -0
  11. package/src/api-client/types/screener.ts +2 -0
  12. package/src/cli/commands/market.ts +18 -8
  13. package/src/cli/commands/overview.ts +28 -7
  14. package/src/cli/commands/ticker.ts +40 -15
  15. package/src/cli/desktop-pane-shot.ts +39 -0
  16. package/src/cli/errors.ts +20 -3
  17. package/src/cli/fx-pair.ts +11 -2
  18. package/src/cli/history-rows.ts +34 -3
  19. package/src/cli/index.ts +1 -1
  20. package/src/cli/listing-arg.ts +51 -13
  21. package/src/cli/pane-functions/data.ts +3 -2
  22. package/src/cli/pane-functions/headless.ts +5 -2
  23. package/src/cli/pane-functions/index.ts +1 -0
  24. package/src/cli/pane-functions/resolver.ts +2 -1
  25. package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
  26. package/src/cli/pane-functions/screenshot-types.ts +4 -0
  27. package/src/cli/symbol-cells.ts +6 -0
  28. package/src/cli/symbol-list.ts +14 -6
  29. package/src/cli/symbol-rows.ts +12 -5
  30. package/src/components/chart/composite/chart-layout.ts +7 -4
  31. package/src/components/chart/composite/composite-chart.tsx +6 -16
  32. package/src/components/chart/composite/toolbar.tsx +258 -82
  33. package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
  34. package/src/components/command-bar/list/model.ts +13 -0
  35. package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
  36. package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
  37. package/src/components/command-bar/surface/index.tsx +10 -5
  38. package/src/components/command-bar/workflow/alert.ts +21 -7
  39. package/src/components/data-table/table-pane.ts +3 -1
  40. package/src/components/layout/pane/footer/model.ts +26 -1
  41. package/src/components/metric-treemap/heat-surface.tsx +2 -1
  42. package/src/components/metric-treemap/index.tsx +3 -2
  43. package/src/components/ui/confirm-dialog.tsx +253 -7
  44. package/src/components/ui/data-table/index.tsx +1 -1
  45. package/src/components/ui/data-table/types.ts +7 -0
  46. package/src/components/ui/list-view.tsx +4 -3
  47. package/src/components/ui/page-stack-view.tsx +24 -6
  48. package/src/components/ui/status.tsx +9 -6
  49. package/src/docs/snapshot.json +36 -0
  50. package/src/i18n/es.ts +12 -0
  51. package/src/i18n/ja.ts +12 -0
  52. package/src/i18n/ko.ts +12 -0
  53. package/src/i18n/zh-cn.ts +12 -0
  54. package/src/i18n/zh-tw.ts +12 -0
  55. package/src/market-data/futures-roll-returns.ts +226 -0
  56. package/src/market-data/fx-closes.ts +14 -2
  57. package/src/market-data/market/change-basis.ts +35 -1
  58. package/src/market-data/market/session-close-note.ts +41 -4
  59. package/src/market-data/market/status.ts +37 -0
  60. package/src/market-data/performance.ts +4 -1
  61. package/src/market-data/quotes/listing-enterprise-value.ts +8 -4
  62. package/src/market-data/quotes/live-valuation.ts +25 -2
  63. package/src/market-data/realized-volatility.ts +3 -0
  64. package/src/market-data/us-bond-market.ts +115 -0
  65. package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
  66. package/src/plugins/builtin/account-management/keyboard.ts +3 -0
  67. package/src/plugins/builtin/account-management/model.ts +1 -0
  68. package/src/plugins/builtin/account-management/pane.tsx +51 -5
  69. package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
  70. package/src/plugins/builtin/backtest/client.ts +9 -2
  71. package/src/plugins/builtin/backtest/pane.tsx +1 -1
  72. package/src/plugins/builtin/backtest/report.ts +22 -6
  73. package/src/plugins/builtin/backtest/window.ts +17 -9
  74. package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
  75. package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
  76. package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
  77. package/src/plugins/builtin/correlation/compute.ts +4 -3
  78. package/src/plugins/builtin/correlation/headless.ts +6 -2
  79. package/src/plugins/builtin/correlation/index.tsx +7 -3
  80. package/src/plugins/builtin/correlation/matrix/model.ts +15 -1
  81. package/src/plugins/builtin/correlation/relationship/model.ts +15 -1
  82. package/src/plugins/builtin/correlation/relationship/pane.tsx +4 -2
  83. package/src/plugins/builtin/earnings/board-model.ts +33 -0
  84. package/src/plugins/builtin/earnings/board-table.ts +50 -11
  85. package/src/plugins/builtin/earnings/board.tsx +29 -13
  86. package/src/plugins/builtin/earnings/calendar.tsx +15 -3
  87. package/src/plugins/builtin/earnings/client.ts +4 -1
  88. package/src/plugins/builtin/earnings/headless.ts +27 -14
  89. package/src/plugins/builtin/econ/calendar-source.ts +3 -0
  90. package/src/plugins/builtin/futures-curve/headless.ts +4 -1
  91. package/src/plugins/builtin/futures-curve/model.ts +24 -0
  92. package/src/plugins/builtin/help/index.tsx +1 -1
  93. package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
  94. package/src/plugins/builtin/iv-history/headless.ts +12 -10
  95. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -2
  96. package/src/plugins/builtin/kelly-sizer/history.ts +10 -3
  97. package/src/plugins/builtin/kelly-sizer/pane.tsx +2 -2
  98. package/src/plugins/builtin/kelly-sizer/sections.tsx +1 -1
  99. package/src/plugins/builtin/macro-day/headless.ts +15 -5
  100. package/src/plugins/builtin/macro-day/model.ts +17 -4
  101. package/src/plugins/builtin/macro-day/releases.ts +36 -15
  102. package/src/plugins/builtin/market-halts/model.ts +3 -2
  103. package/src/plugins/builtin/market-movers/headless.ts +2 -1
  104. package/src/plugins/builtin/market-movers/index.tsx +3 -2
  105. package/src/plugins/builtin/market-movers/model.ts +75 -22
  106. package/src/plugins/builtin/market-movers/screener.ts +2 -1
  107. package/src/plugins/builtin/market-movers/table.ts +7 -5
  108. package/src/plugins/builtin/pe-band/model.ts +4 -0
  109. package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
  110. package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
  111. package/src/plugins/builtin/portfolio-list/pane/index.tsx +2 -1
  112. package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
  113. package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
  114. package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
  115. package/src/plugins/builtin/realized-vol/headless.ts +11 -6
  116. package/src/plugins/builtin/realized-vol/model.ts +14 -6
  117. package/src/plugins/builtin/realized-vol/pane.tsx +2 -1
  118. package/src/plugins/builtin/realized-vol/settings.ts +2 -1
  119. package/src/plugins/builtin/research/analyst-headless.ts +9 -1
  120. package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
  121. package/src/plugins/builtin/research/client.ts +25 -1
  122. package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
  123. package/src/plugins/builtin/research/event-model.ts +3 -13
  124. package/src/plugins/builtin/research/event-sources.ts +3 -1
  125. package/src/plugins/builtin/seasonality/client.ts +66 -17
  126. package/src/plugins/builtin/seasonality/headless.ts +7 -2
  127. package/src/plugins/builtin/seasonality/model.ts +12 -3
  128. package/src/plugins/builtin/seasonality/pane.tsx +4 -2
  129. package/src/plugins/builtin/shared/use-quote-board.ts +28 -6
  130. package/src/plugins/builtin/short-interest/headless.ts +2 -0
  131. package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
  132. package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
  133. package/src/plugins/builtin/yield-curve/headless.ts +5 -1
  134. package/src/plugins/builtin/yield-curve/index.tsx +5 -0
  135. package/src/portfolio/column-values.ts +47 -14
  136. package/src/portfolio/return-metrics.ts +4 -2
  137. package/src/renderers/dom/desktop/controls.tsx +1 -1
  138. package/src/renderers/dom/host/image-surface.tsx +19 -9
  139. package/src/renderers/dom/host/input.tsx +4 -0
  140. package/src/renderers/dom/styles.css +7 -4
  141. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
  142. package/src/renderers/opentui/box-width.ts +30 -0
  143. package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
  144. package/src/sources/provider-errors.ts +12 -0
  145. package/src/sources/provider-router/index.ts +12 -4
  146. package/src/state/pane-session.ts +145 -0
  147. package/src/tickers/search/home-listing.ts +44 -1
  148. package/src/tickers/search/index.ts +5 -2
  149. package/src/tickers/search/ranking.ts +7 -7
  150. package/src/tickers/us-listing.ts +11 -5
  151. package/src/time-series/base-series.ts +7 -1
  152. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  153. package/src/time-series/fundamentals/series.ts +6 -0
  154. package/src/time-series/resolve.ts +1 -0
  155. package/src/types/financials.ts +36 -3
  156. package/src/types/headless.ts +15 -0
  157. package/src/ui/host.tsx +2 -0
  158. package/src/utils/exchanges.ts +13 -8
  159. package/src/utils/fundamentals.ts +49 -8
  160. package/src/utils/price-earnings.ts +17 -10
  161. package/src/utils/price-history-integrity.ts +15 -0
  162. package/src/utils/reason-codes.ts +79 -0
  163. package/src/utils/share-multiples.cases.json +889 -0
  164. package/src/utils/share-multiples.ts +254 -0
  165. package/src/utils/untrusted-text.ts +11 -0
@@ -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
  }
@@ -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 ?? {}),
@@ -3,9 +3,11 @@ import type { DataTableKeyEvent } from "./view";
3
3
  import type { PaneFooterSegment } from "../layout/pane/footer";
4
4
  import { useShortcut } from "../../react/input";
5
5
  import { isPlainKey } from "../../utils/keyboard";
6
+ import { readableStatus } from "../../utils/reason-codes";
6
7
 
8
+ /** `loading`, and the failure in words: a bare reason code (UPSTREAM_ERROR) reads as what happened. */
7
9
  export function loadingErrorFooterInfo(loading: boolean, error: string | null | undefined): PaneFooterSegment[] {
8
- const message = error?.trim() ?? "";
10
+ const message = readableStatus(error?.trim() ?? "");
9
11
  return [
10
12
  ...(loading ? [{ id: "loading", parts: [{ text: "loading", tone: "muted" as const }] }] : []),
11
13
  ...(message ? [{ id: "error", parts: [{ text: message, tone: "warning" as const }] }] : []),
@@ -3,6 +3,7 @@ import { t, tf } from "../../../../i18n";
3
3
  import { type CompanyFrom, companyFromLabel } from "../../../../types/company-from";
4
4
  import { clipToDisplayWidth, displayWidth } from "../../../../utils/format";
5
5
  import { formatShortDate } from "../../../../utils/datetime-format";
6
+ import { readableStatus } from "../../../../utils/reason-codes";
6
7
  import { getShortcutHintWidth } from "../../../ui/shortcut-hint";
7
8
  import { KEY_HINT_GAP_PX, keycapText, keyHintCells, keyHintTitle, keyHintWords } from "../../../ui/key-hint-words";
8
9
 
@@ -544,7 +545,31 @@ export function combinePaneFooterRegistrations(registrations: Map<string, PaneFo
544
545
  const shown = kept.some((hint) => !hint.besideOthers && !hint.disabled) ? kept : kept.filter((hint) => !hint.besideOthers);
545
546
 
546
547
  if (info.length === 0 && shown.length === 0 && menu.length === 0 && keys.length === 0) return EMPTY_FOOTER;
547
- return { info: savedCopyFirst(info), hints: shown, menu, keys };
548
+ return { info: savedCopyFirst(info.map(readableFailure)), hints: shown, menu, keys };
549
+ }
550
+
551
+ const failureTone = (part: PaneFooterPart) => part.tone === "warning" || part.tone === "negative";
552
+
553
+ /**
554
+ * A failure a pane put in its footer itself, in words: a bare reason code
555
+ * (UPSTREAM_ERROR) reads as what happened, as `loadingErrorFooterInfo` says
556
+ * it. Only warning and negative parts, so a symbol shown as data stays.
557
+ */
558
+ function readableFailure(segment: PaneFooterSegment): PaneFooterSegment {
559
+ const read = (parts: PaneFooterPart[]) => {
560
+ let changed = false;
561
+ const next = parts.map((part) => {
562
+ const text = failureTone(part) ? readableStatus(part.text) : part.text;
563
+ if (text === part.text) return part;
564
+ changed = true;
565
+ return { ...part, text };
566
+ });
567
+ return changed ? next : parts;
568
+ };
569
+ const parts = read(segment.parts);
570
+ const variants = segment.variants?.map(read);
571
+ const same = parts === segment.parts && (variants ?? []).every((variant, index) => variant === segment.variants![index]);
572
+ return same ? segment : { ...segment, parts, ...(variants ? { variants } : {}) };
548
573
  }
549
574
 
550
575
  /**
@@ -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
  }
@@ -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) => (
@@ -93,7 +93,7 @@ export function DataTable<T, C extends DataTableColumn = DataTableColumn>(
93
93
  paneInstanceId: paneId,
94
94
  sortColumnId: props.sortColumnId,
95
95
  sortDirection: props.sortDirection,
96
- columns: props.columns.map((column) => ({ id: column.id, label: column.label })),
96
+ columns: props.columns.map((column) => ({ id: column.id, label: column.label, ...(column.mayBeBlank ? { mayBeBlank: true } : {}) })),
97
97
  rowCount: props.items.length,
98
98
  selectedId: firstSelectedId(props),
99
99
  ...(props.reportEveryRow ? { rows: cachedReportedRows(props, reportedRowsRef) } : {}),
@@ -20,6 +20,13 @@ export type DataTableColumn = Pick<
20
20
  */
21
21
  title?: string;
22
22
  flexGrow?: number;
23
+ /**
24
+ * Every row can leave this column blank with nothing missing: its value
25
+ * comes after an event the row is still waiting on (an earnings move, an
26
+ * IPO's first-day return, a halt's resumption). `shot --strict` counts a
27
+ * column blank in every row as data the pane lost, except this one.
28
+ */
29
+ mayBeBlank?: boolean;
23
30
  };
24
31
 
25
32
  export interface DataTableCell {