@gloom-sh/terminal 0.20.9 → 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 (128) 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/index.ts +14 -3
  6. package/src/api-client/types/account.ts +10 -0
  7. package/src/api-client/types/billing.ts +10 -0
  8. package/src/api-client/types/econ.ts +19 -7
  9. package/src/api-client/types/market.ts +7 -0
  10. package/src/api-client/types/screener.ts +2 -0
  11. package/src/cli/commands/market.ts +18 -8
  12. package/src/cli/commands/overview.ts +26 -7
  13. package/src/cli/commands/ticker.ts +40 -15
  14. package/src/cli/desktop-pane-shot.ts +39 -0
  15. package/src/cli/errors.ts +20 -3
  16. package/src/cli/fx-pair.ts +11 -2
  17. package/src/cli/history-rows.ts +34 -3
  18. package/src/cli/index.ts +1 -1
  19. package/src/cli/listing-arg.ts +51 -13
  20. package/src/cli/pane-functions/headless.ts +4 -2
  21. package/src/cli/pane-functions/index.ts +1 -0
  22. package/src/cli/pane-functions/resolver.ts +2 -1
  23. package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
  24. package/src/cli/pane-functions/screenshot-types.ts +4 -0
  25. package/src/components/chart/composite/chart-layout.ts +7 -4
  26. package/src/components/chart/composite/composite-chart.tsx +6 -16
  27. package/src/components/chart/composite/toolbar.tsx +258 -82
  28. package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
  29. package/src/components/command-bar/list/model.ts +13 -0
  30. package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
  31. package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
  32. package/src/components/command-bar/surface/index.tsx +10 -5
  33. package/src/components/command-bar/workflow/alert.ts +21 -7
  34. package/src/components/data-table/table-pane.ts +3 -1
  35. package/src/components/layout/pane/footer/model.ts +26 -1
  36. package/src/components/metric-treemap/heat-surface.tsx +2 -1
  37. package/src/components/metric-treemap/index.tsx +3 -2
  38. package/src/components/ui/confirm-dialog.tsx +253 -7
  39. package/src/components/ui/data-table/index.tsx +1 -1
  40. package/src/components/ui/data-table/types.ts +7 -0
  41. package/src/components/ui/list-view.tsx +4 -3
  42. package/src/components/ui/status.tsx +9 -6
  43. package/src/docs/snapshot.json +36 -0
  44. package/src/i18n/es.ts +12 -0
  45. package/src/i18n/ja.ts +12 -0
  46. package/src/i18n/ko.ts +12 -0
  47. package/src/i18n/zh-cn.ts +12 -0
  48. package/src/i18n/zh-tw.ts +12 -0
  49. package/src/market-data/fx-closes.ts +14 -2
  50. package/src/market-data/market/change-basis.ts +35 -1
  51. package/src/market-data/market/status.ts +37 -0
  52. package/src/market-data/performance.ts +4 -1
  53. package/src/market-data/quotes/live-valuation.ts +25 -2
  54. package/src/market-data/realized-volatility.ts +3 -0
  55. package/src/market-data/us-bond-market.ts +115 -0
  56. package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
  57. package/src/plugins/builtin/account-management/keyboard.ts +3 -0
  58. package/src/plugins/builtin/account-management/model.ts +1 -0
  59. package/src/plugins/builtin/account-management/pane.tsx +51 -5
  60. package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
  61. package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
  62. package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
  63. package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
  64. package/src/plugins/builtin/correlation/compute.ts +4 -3
  65. package/src/plugins/builtin/earnings/board-model.ts +33 -0
  66. package/src/plugins/builtin/earnings/board-table.ts +50 -11
  67. package/src/plugins/builtin/earnings/board.tsx +29 -13
  68. package/src/plugins/builtin/earnings/calendar.tsx +15 -3
  69. package/src/plugins/builtin/earnings/client.ts +4 -1
  70. package/src/plugins/builtin/earnings/headless.ts +27 -14
  71. package/src/plugins/builtin/econ/calendar-source.ts +3 -0
  72. package/src/plugins/builtin/help/index.tsx +1 -1
  73. package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
  74. package/src/plugins/builtin/iv-history/headless.ts +12 -10
  75. package/src/plugins/builtin/macro-day/headless.ts +15 -5
  76. package/src/plugins/builtin/macro-day/model.ts +17 -4
  77. package/src/plugins/builtin/macro-day/releases.ts +36 -15
  78. package/src/plugins/builtin/market-halts/model.ts +3 -2
  79. package/src/plugins/builtin/market-movers/headless.ts +2 -1
  80. package/src/plugins/builtin/market-movers/index.tsx +3 -2
  81. package/src/plugins/builtin/market-movers/model.ts +75 -22
  82. package/src/plugins/builtin/market-movers/screener.ts +2 -1
  83. package/src/plugins/builtin/market-movers/table.ts +7 -5
  84. package/src/plugins/builtin/pe-band/model.ts +4 -0
  85. package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
  86. package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
  87. package/src/plugins/builtin/portfolio-list/pane/index.tsx +2 -1
  88. package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
  89. package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
  90. package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
  91. package/src/plugins/builtin/research/analyst-headless.ts +9 -1
  92. package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
  93. package/src/plugins/builtin/research/client.ts +25 -1
  94. package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
  95. package/src/plugins/builtin/research/event-model.ts +3 -13
  96. package/src/plugins/builtin/research/event-sources.ts +3 -1
  97. package/src/plugins/builtin/short-interest/headless.ts +2 -0
  98. package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
  99. package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
  100. package/src/plugins/builtin/yield-curve/headless.ts +5 -1
  101. package/src/plugins/builtin/yield-curve/index.tsx +5 -0
  102. package/src/portfolio/column-values.ts +47 -14
  103. package/src/portfolio/return-metrics.ts +4 -2
  104. package/src/renderers/dom/host/image-surface.tsx +19 -9
  105. package/src/renderers/dom/host/input.tsx +4 -0
  106. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
  107. package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
  108. package/src/sources/provider-errors.ts +12 -0
  109. package/src/sources/provider-router/index.ts +12 -4
  110. package/src/state/pane-session.ts +145 -0
  111. package/src/tickers/search/home-listing.ts +44 -1
  112. package/src/tickers/search/index.ts +5 -2
  113. package/src/tickers/search/ranking.ts +7 -7
  114. package/src/tickers/us-listing.ts +11 -5
  115. package/src/time-series/base-series.ts +7 -1
  116. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  117. package/src/time-series/fundamentals/series.ts +6 -0
  118. package/src/time-series/resolve.ts +1 -0
  119. package/src/types/financials.ts +20 -0
  120. package/src/types/headless.ts +9 -0
  121. package/src/ui/host.tsx +2 -0
  122. package/src/utils/exchanges.ts +13 -8
  123. package/src/utils/price-earnings.ts +17 -10
  124. package/src/utils/price-history-integrity.ts +15 -0
  125. package/src/utils/reason-codes.ts +79 -0
  126. package/src/utils/share-multiples.cases.json +889 -0
  127. package/src/utils/share-multiples.ts +254 -0
  128. package/src/utils/untrusted-text.ts +11 -0
@@ -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 {
@@ -71,9 +71,10 @@ export interface ListViewProps {
71
71
  selectOnHover?: boolean;
72
72
  autoScrollToIndex?: boolean;
73
73
  /**
74
- * The rows are checkboxes (ToggleList). A focused desktop row toggles on
75
- * Space and leaves Enter to the surface around the list, the way a checkbox
76
- * leaves Enter to its dialog's default button.
74
+ * The rows are checkboxes (ToggleList), or choices a dialog asks beside its
75
+ * buttons. A focused desktop row toggles or picks on Space and leaves Enter
76
+ * to the surface around the list, the way a checkbox leaves Enter to its
77
+ * dialog's default button.
77
78
  */
78
79
  checkboxRows?: boolean;
79
80
  onMouseScroll?: (event: any) => void;
@@ -3,6 +3,7 @@ import { t, tf } from "../../i18n";
3
3
  import { useThemeColors } from "../../theme/theme-context";
4
4
  import { Box, Text, useUiCapabilities } from "../../ui";
5
5
  import { formatRelativeAge } from "../../utils/datetime-format";
6
+ import { readableError } from "../../utils/reason-codes";
6
7
  import { Spinner } from "./loading";
7
8
  import { ButtonActionScope } from "./action-scope";
8
9
  import { blendForContrast, higherContrast } from "../../theme/color-utils";
@@ -206,7 +207,8 @@ function EmptyStateBody({ title, message, hint, actions, retry, status = "empty"
206
207
  onPress={feedback.press}
207
208
  />
208
209
  ) : null;
209
- // Provider messages must wrap at narrow pane widths rather than lose their tail.
210
+ // Provider messages must wrap at narrow pane widths rather than lose their tail,
211
+ // and a bare reason code (UPSTREAM_ERROR) a pane passed on reads as words.
210
212
  return (
211
213
  <Box
212
214
  id={domId}
@@ -215,9 +217,9 @@ function EmptyStateBody({ title, message, hint, actions, retry, status = "empty"
215
217
  data-gloom-ui="empty-state"
216
218
  style={inset ? NATIVE_STATE_INSET : undefined}
217
219
  >
218
- <Box><Text fg={status === "error" ? colors.negative : colors.textDim} wrapText>{t(title)}</Text></Box>
219
- {message && <Box><Text fg={colors.textMuted} wrapText>{t(message)}</Text></Box>}
220
- {hint && <Box><Text fg={colors.textMuted} wrapText>{t(hint)}</Text></Box>}
220
+ <Box><Text fg={status === "error" ? colors.negative : colors.textDim} wrapText>{t(readableError(title))}</Text></Box>
221
+ {message && <Box><Text fg={colors.textMuted} wrapText>{t(readableError(message))}</Text></Box>}
222
+ {hint && <Box><Text fg={colors.textMuted} wrapText>{t(readableError(hint))}</Text></Box>}
221
223
  {/* Wraps in a narrow pane rather than clipping the second action; a terminal wraps without a blank row. */}
222
224
  {(retryButton || actions) && (
223
225
  <Box flexDirection="row" flexWrap="wrap" gap={1} rowGap={nativePaneChrome ? undefined : 0} marginTop={1}>
@@ -243,18 +245,19 @@ export function Notice({ children, tone = "warning", variant = "inline" }: Notic
243
245
  const native = useUiCapabilities().nativePaneChrome;
244
246
  const color = tone === "muted" ? colors.textDim : colors[tone];
245
247
  const status = tone === "negative" ? "error" : "notice";
248
+ const body = typeof children === "string" ? readableError(children) : children;
246
249
  // Inline feedback keeps its original single-text shape: a flex row here collapses inside content-sized parents.
247
250
  if (variant !== "callout") {
248
251
  return (
249
252
  <Box data-gloom-status={status} data-gloom-ui="notice">
250
- <Text fg={color} wrapText>{children}</Text>
253
+ <Text fg={color} wrapText>{body}</Text>
251
254
  </Box>
252
255
  );
253
256
  }
254
257
  const foreground = blendForContrast(color, colors.panel, higherContrast("#000000", "#ffffff", colors.panel), 4.5);
255
258
  return (
256
259
  <Box flexDirection="row" gap={1} paddingX={1} paddingY={native ? 0.35 : 0} backgroundColor={colors.panel} border={["left"]} borderColor={color} data-gloom-status={status} data-gloom-ui="notice" role={native ? tone === "negative" ? "alert" : "status" : undefined} aria-atomic={native ? true : undefined}>
257
- <Text fg={foreground}>!</Text><Box flexGrow={1} minWidth={0}><Text fg={foreground} wrapText>{children}</Text></Box>
260
+ <Text fg={foreground}>!</Text><Box flexGrow={1} minWidth={0}><Text fg={foreground} wrapText>{body}</Text></Box>
258
261
  </Box>
259
262
  );
260
263
  }
@@ -787,6 +787,18 @@
787
787
  "shot": "https://gloom.sh/screenshots/fn/CRYP.png",
788
788
  "lesson": "/academy/crypto-and-prediction-markets/crypto-from-zero"
789
789
  },
790
+ {
791
+ "code": "GTP",
792
+ "name": "Layer 2 metrics",
793
+ "description": "Ethereum and its layer 2 chains",
794
+ "detail": "Ethereum and its layer 2 chains side by side: transactions, active addresses, fees, transaction cost, stablecoin supply and value secured, with 30-day changes and a daily history chart. Data from growthepie.",
795
+ "category": "markets",
796
+ "plugin": {
797
+ "id": "growthepie",
798
+ "name": "growthepie"
799
+ },
800
+ "shot": "https://gloom.sh/screenshots/fn/GTP.png"
801
+ },
790
802
  {
791
803
  "code": "ETFF",
792
804
  "name": "Crypto ETF flows",
@@ -834,6 +846,18 @@
834
846
  "shot": "https://gloom.sh/screenshots/fn/FNG.png",
835
847
  "lesson": "/academy/macro-markets-and-news/markets/sentiment-and-valuation"
836
848
  },
849
+ {
850
+ "code": "CFNG",
851
+ "name": "Crypto fear and greed",
852
+ "description": "Crypto sentiment gauge",
853
+ "detail": "The crypto Fear and Greed Index from Alternative.me: today's reading, yesterday, last week and last month, and its history.",
854
+ "category": "markets",
855
+ "plugin": {
856
+ "id": "crypto-fear-greed",
857
+ "name": "Crypto Fear & Greed"
858
+ },
859
+ "shot": "https://gloom.sh/screenshots/fn/CFNG.png"
860
+ },
837
861
  {
838
862
  "code": "COT",
839
863
  "name": "CFTC positioning",
@@ -1138,6 +1162,18 @@
1138
1162
  "shot": "https://gloom.sh/screenshots/fn/PM.png",
1139
1163
  "lesson": "/academy/crypto-and-prediction-markets/prediction-markets"
1140
1164
  },
1165
+ {
1166
+ "code": "ADJ",
1167
+ "name": "Adjacent indices",
1168
+ "description": "Prediction-market indices",
1169
+ "detail": "Adjacent's indices built on prediction markets, with each one's level and 1D and 7D moves, its chart and constituents, plus reference rates and CFTC filings.",
1170
+ "category": "markets",
1171
+ "plugin": {
1172
+ "id": "adjacent-indices",
1173
+ "name": "Adjacent"
1174
+ },
1175
+ "shot": "https://gloom.sh/screenshots/fn/ADJ.png"
1176
+ },
1141
1177
  {
1142
1178
  "code": "POLL",
1143
1179
  "name": "Polls",