@gloom-sh/terminal 0.20.10 → 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 (103) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
  3. package/src/api-client/socket-connection.ts +355 -0
  4. package/src/api-client/socket-features.ts +75 -0
  5. package/src/api-client/socket-frames.ts +161 -0
  6. package/src/api-client/socket-listeners.ts +207 -0
  7. package/src/api-client/socket-quotes.ts +332 -0
  8. package/src/api-client/socket.ts +150 -983
  9. package/src/brokers/signed-in/adapter.ts +19 -5
  10. package/src/brokers/signed-in/client.ts +13 -1
  11. package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
  12. package/src/components/chart/native/kitty/manager.ts +2 -0
  13. package/src/components/chart/native/surface/manager.ts +211 -11
  14. package/src/components/command-bar/panel/index.tsx +2 -13
  15. package/src/components/command-bar/panel/layout.ts +1 -7
  16. package/src/components/command-bar/panel/runtime.ts +0 -1
  17. package/src/components/command-bar/panel/types.ts +0 -2
  18. package/src/components/data-table/column-menu.tsx +89 -0
  19. package/src/components/data-table/sort-menu.tsx +9 -2
  20. package/src/components/data-table/view.tsx +33 -6
  21. package/src/components/form-modal/content.tsx +10 -0
  22. package/src/components/index.ts +1 -1
  23. package/src/components/layout/pane/footer/index.tsx +25 -11
  24. package/src/components/layout/pane/footer/model.ts +62 -20
  25. package/src/components/layout/pane/sidebar.tsx +125 -15
  26. package/src/components/layout/shell/active-drag.ts +18 -13
  27. package/src/components/layout/shell/drag/magnets.ts +34 -18
  28. package/src/components/ticker/list-table-view.tsx +5 -0
  29. package/src/components/ui/data-table/column-order.ts +180 -0
  30. package/src/components/ui/data-table/index.tsx +12 -1
  31. package/src/components/ui/data-table/opentui/index.tsx +267 -23
  32. package/src/components/ui/data-table/opentui/model.ts +43 -4
  33. package/src/components/ui/data-table/types.ts +49 -0
  34. package/src/components/ui/data-table/use-column-order.ts +135 -0
  35. package/src/components/ui/index.ts +1 -1
  36. package/src/components/ui/table-layout.ts +120 -0
  37. package/src/docs/snapshot.json +3 -2
  38. package/src/i18n/es.ts +2 -0
  39. package/src/i18n/ja.ts +2 -0
  40. package/src/i18n/ko.ts +2 -0
  41. package/src/i18n/zh-cn.ts +2 -0
  42. package/src/i18n/zh-tw.ts +2 -0
  43. package/src/market-data/coordinator/index.ts +4 -3
  44. package/src/market-data/coordinator/quotes.ts +12 -4
  45. package/src/market-data/quotes/freshness.ts +12 -0
  46. package/src/market-data/quotes/live-valuation.ts +1 -1
  47. package/src/market-data/quotes/regular-session-valuation.ts +1 -1
  48. package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
  49. package/src/plugins/builtin/broker-manager/index.tsx +6 -6
  50. package/src/plugins/builtin/broker-manager/model.ts +15 -6
  51. package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
  52. package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
  53. package/src/plugins/builtin/broker-manager/table.ts +10 -4
  54. package/src/plugins/builtin/chat/sidebar.tsx +33 -16
  55. package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
  56. package/src/plugins/builtin/equity-screener/live.ts +74 -18
  57. package/src/plugins/builtin/equity-screener/model.ts +19 -4
  58. package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
  59. package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
  60. package/src/plugins/builtin/equity-screener/results.ts +22 -2
  61. package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
  62. package/src/plugins/builtin/futures/index.tsx +15 -1
  63. package/src/plugins/builtin/futures/table.tsx +1 -1
  64. package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
  65. package/src/plugins/builtin/holders/pane.tsx +30 -20
  66. package/src/plugins/builtin/iv-history/events.ts +5 -0
  67. package/src/plugins/builtin/iv-history/headless.ts +7 -2
  68. package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
  69. package/src/plugins/builtin/macro-day/headless.ts +12 -3
  70. package/src/plugins/builtin/options/view.tsx +2 -0
  71. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  72. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
  73. package/src/plugins/builtin/portfolio-list/pane/index.tsx +13 -0
  74. package/src/plugins/builtin/portfolio-list/table.tsx +5 -0
  75. package/src/plugins/builtin/rate-path/pane.tsx +2 -0
  76. package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
  77. package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
  78. package/src/plugins/builtin/seasonality/pane.tsx +2 -1
  79. package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
  80. package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
  81. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
  82. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
  83. package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
  84. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  85. package/src/plugins/builtin/world-indices/index.tsx +5 -1
  86. package/src/plugins/builtin/yield-curve/index.tsx +2 -1
  87. package/src/renderers/dom/data-table/column-drag.ts +147 -0
  88. package/src/renderers/dom/data-table/index.tsx +22 -0
  89. package/src/renderers/dom/data-table/row.tsx +27 -5
  90. package/src/renderers/dom/styles.css +22 -0
  91. package/src/renderers/opentui/chart-surface.tsx +1 -0
  92. package/src/renderers/opentui/frame-hits.ts +33 -0
  93. package/src/renderers/opentui/host.tsx +2 -0
  94. package/src/renderers/opentui/native-surface.ts +14 -21
  95. package/src/renderers/opentui/test-utils.tsx +3 -0
  96. package/src/state/app/context/index.tsx +22 -0
  97. package/src/test-support/app-store.ts +24 -1
  98. package/src/time-series/live-quotes.ts +3 -9
  99. package/src/ui/host.tsx +18 -0
  100. package/src/ui/pointer-drag.ts +11 -2
  101. package/src/utils/fundamentals.ts +14 -3
  102. package/src/utils/share-multiples.cases.json +780 -2
  103. package/src/utils/share-multiples.ts +154 -24
@@ -6,7 +6,12 @@ import {
6
6
  type CellRect,
7
7
  type NativeChartBitmap,
8
8
  } from "../../components/chart/native/chart-rasterizer";
9
- import { getNativeSurfaceManager } from "../../components/chart/native/surface/manager";
9
+ import {
10
+ getNativeSurfaceManager,
11
+ insetCellRect,
12
+ type CellInsets,
13
+ type NativeSurfaceAnchor,
14
+ } from "../../components/chart/native/surface/manager";
10
15
  import {
11
16
  getRenderableCellRect,
12
17
  resolveNativeSurfaceVisibleRect,
@@ -32,38 +37,24 @@ export interface NativeSurfaceTarget {
32
37
  pixelHeight: number;
33
38
  /** The source key plus the pixel size, so a resize uploads a fresh bitmap. */
34
39
  bitmapKey: string;
40
+ /** The box drawn over, which the image layer measures again after every frame. */
41
+ anchor: NativeSurfaceAnchor;
35
42
  }
36
43
 
37
- export interface CellInsets {
38
- top: number;
39
- right: number;
40
- bottom: number;
41
- left: number;
42
- }
44
+ export type { CellInsets };
43
45
 
44
46
  function sameTarget(left: NativeSurfaceTarget | null, right: NativeSurfaceTarget | null): boolean {
45
47
  if (left === right) return true;
46
48
  if (!left || !right) return false;
47
49
  return left.bitmapKey === right.bitmapKey
50
+ && left.anchor.renderable === right.anchor.renderable
51
+ && left.anchor.insets === right.anchor.insets
48
52
  && left.pixelWidth === right.pixelWidth
49
53
  && left.pixelHeight === right.pixelHeight
50
54
  && sameCellRect(left.rect, right.rect)
51
55
  && sameCellRect(left.visibleRect, right.visibleRect);
52
56
  }
53
57
 
54
- function insetRect(rect: CellRect, insets: CellInsets | undefined): CellRect | null {
55
- if (!insets) return rect;
56
- const width = rect.width - insets.left - insets.right;
57
- const height = rect.height - insets.top - insets.bottom;
58
- if (width <= 0 || height <= 0) return null;
59
- return {
60
- x: rect.x + insets.left,
61
- y: rect.y + insets.top,
62
- width,
63
- height,
64
- };
65
- }
66
-
67
58
  /**
68
59
  * Where a terminal image surface should draw, re-measured on every lifecycle
69
60
  * pass so it follows layout, scrolling and clipping.
@@ -96,7 +87,7 @@ export function useNativeSurfaceTarget(
96
87
  let mountTimer: Timer | null = null;
97
88
  const previousLifecyclePass = renderable.onLifecyclePass;
98
89
  const syncTarget = () => {
99
- const rect = insetRect(getRenderableCellRect(renderable), insets);
90
+ const rect = insetCellRect(getRenderableCellRect(renderable), insets);
100
91
  if (!rect || !renderer.resolution || renderer.terminalWidth <= 0 || renderer.terminalHeight <= 0) {
101
92
  setTarget((current) => (current === null ? current : null));
102
93
  return;
@@ -110,6 +101,7 @@ export function useNativeSurfaceTarget(
110
101
  pixelWidth: size.pixelWidth,
111
102
  pixelHeight: size.pixelHeight,
112
103
  bitmapKey: `${sourceKey}:${size.pixelWidth}x${size.pixelHeight}`,
104
+ anchor: { renderable, insets },
113
105
  };
114
106
  setTarget((current) => (sameTarget(current, nextTarget) ? current : nextTarget));
115
107
  };
@@ -170,6 +162,7 @@ export function useNativeSurface(
170
162
  visibleRect: target.visibleRect,
171
163
  bitmap,
172
164
  bitmapKey: target.bitmapKey,
165
+ anchor: target.anchor,
173
166
  });
174
167
  renderer.requestRender();
175
168
  }, [bitmap, nativeSurfaceManager, paneId, renderer, surfaceId, target]);
@@ -9,6 +9,7 @@ import { AppDialogBridge } from "../../app/dialog-bridge";
9
9
  import { OpenTuiDialogHostProvider } from "./dialog-host";
10
10
  import { OpenTuiInputHostProvider } from "./input-host";
11
11
  import { provideKittyServices } from "./kitty-services";
12
+ import { createFrameHits } from "./frame-hits";
12
13
  import { captureRendererFrame } from "./frame-capture";
13
14
  import { openTuiToastHost } from "./toast-host";
14
15
  import { openTuiUiHost } from "./ui-host";
@@ -90,6 +91,8 @@ function createTestNativeRendererHost(renderer: any): NativeRendererHost {
90
91
  }
91
92
  // What a feedback report and Ask Gloom read from the screen, as the app's host gives it.
92
93
  if (typeof renderer.captureFrame !== "function") renderer.captureFrame = () => captureRendererFrame(renderer);
94
+ // What covers a kitty image, as the app's host reads it.
95
+ if (!renderer.frameHits) renderer.frameHits = createFrameHits(renderer);
93
96
  return provideKittyServices(renderer as NativeRendererHost);
94
97
  }
95
98
 
@@ -376,6 +376,28 @@ export function useUpdatePaneSettings(paneId?: string) {
376
376
  }, [scopedPaneId, updateLayout]);
377
377
  }
378
378
 
379
+ /**
380
+ * Rewrites one setting of a pane that may be absent (a table drawn outside a
381
+ * pane): `update` gets its value and returns the next one, `undefined` to
382
+ * remove it, or the same value to leave the layout alone.
383
+ */
384
+ export function useOptionalPaneSettingUpdater(paneId: string | null, key: string) {
385
+ const updateLayout = useUpdatePaneLayout();
386
+ return useCallback((update: (value: unknown) => unknown) => {
387
+ if (!paneId) return;
388
+ updateLayout((layout) => {
389
+ const pane = findPaneInstance(layout, paneId);
390
+ if (!pane) return layout;
391
+ const current = pane.settings?.[key];
392
+ const next = update(current);
393
+ if (Object.is(next, current)) return layout;
394
+ if (next !== undefined) return setPaneSetting(layout, paneId, key, next);
395
+ const { [key]: _removed, ...rest } = pane.settings ?? {};
396
+ return setPaneSettings(layout, paneId, Object.keys(rest).length > 0 ? rest : undefined);
397
+ });
398
+ }, [key, paneId, updateLayout]);
399
+ }
400
+
379
401
  function useScopedPaneId(paneId?: string): string {
380
402
  const contextId = useOptionalPaneInstanceId();
381
403
  const id = paneId ?? contextId;
@@ -1,5 +1,5 @@
1
1
  import type { Dispatch } from "react";
2
- import type { AppAction, AppContextStoreValue, AppState } from "../state/app/context";
2
+ import { appReducer, type AppAction, type AppContextStoreValue, type AppState } from "../state/app/context";
3
3
 
4
4
  const ignoreAction: Dispatch<AppAction> = () => {};
5
5
  const noUnsubscribe = () => {};
@@ -19,3 +19,26 @@ export function createStaticAppStore(
19
19
  subscribe: () => noUnsubscribe,
20
20
  };
21
21
  }
22
+
23
+ /**
24
+ * An `AppContext` value that runs the app's reducer on every dispatch and
25
+ * notifies its subscribers, for a suite that checks what the app's own
26
+ * actions did to the state (a pane setting written, a layout saved).
27
+ */
28
+ export function createReducerAppStore(state: AppState): AppContextStoreValue {
29
+ let current = state;
30
+ const listeners = new Set<() => void>();
31
+ return {
32
+ dispatch: (action) => {
33
+ current = appReducer(current, action);
34
+ for (const listener of listeners) listener();
35
+ },
36
+ getState: () => current,
37
+ subscribe: (listener) => {
38
+ listeners.add(listener);
39
+ return () => {
40
+ listeners.delete(listener);
41
+ };
42
+ },
43
+ };
44
+ }
@@ -6,7 +6,7 @@ import type { ChartSeriesSpec, ChartSpec, SecuritySeriesSource } from "./types";
6
6
  import { activeStudyInputSeriesIds } from "./studies/resolve";
7
7
  import { withFormulaNextMonths } from "./formula-months";
8
8
  import { valuationSeriesUsesLiveQuote } from "./fundamentals";
9
- import { hasValidQuoteObservationTime } from "../market-data/quotes/freshness";
9
+ import { hasValidQuoteObservationTime, quoteStampBucket } from "../market-data/quotes/freshness";
10
10
  import type { InstrumentRef } from "../market-data/request-types";
11
11
  import type { QueryEntry } from "../market-data/result-types";
12
12
  import { buildQuoteKey, instrumentFromQuoteTarget, resolveEntryData } from "../market-data/selectors";
@@ -105,19 +105,13 @@ function isNewerQuote(next: Quote, current: Quote | undefined): boolean {
105
105
  && (next.stale === true) !== (current.stale === true));
106
106
  }
107
107
 
108
- /** Every chart bar boundary, intraday or calendar, is a whole minute. */
109
- const QUOTE_TIME_BUCKET_MS = 60_000;
110
-
111
- function quoteTimeBucket(quote: Quote): number {
112
- return Number.isFinite(quote.lastUpdated) ? Math.floor(quote.lastUpdated / QUOTE_TIME_BUCKET_MS) : Number.NaN;
113
- }
114
-
115
108
  function hasResolutionRelevantChange(next: Quote, current: Quote | undefined): boolean {
116
109
  if (!current) return true;
117
110
  // Bid/ask updates restamp a quote many times a second without moving its
118
111
  // price or volume. The stamp alone matters only when it crosses into
119
112
  // another minute, where it can open a bar at the same price.
120
- return !Object.is(quoteTimeBucket(next), quoteTimeBucket(current))
113
+ // Every chart bar boundary, intraday or calendar, is a whole minute (quoteStampBucket).
114
+ return !Object.is(quoteStampBucket(next), quoteStampBucket(current))
121
115
  || next.price !== current.price
122
116
  || next.volume !== current.volume
123
117
  || next.stale !== current.stale
package/src/ui/host.tsx CHANGED
@@ -167,6 +167,8 @@ interface ScrollBarRenderable {
167
167
  visible: boolean;
168
168
  /** Terminal only: whether a click on the bar moves the keyboard focus to it. */
169
169
  focusable?: boolean;
170
+ /** Terminal only: shows the bar again while the content overflows, after `visible` was set. */
171
+ resetVisibilityControl?(): void;
170
172
  on?(event: "change", handler: () => void): void;
171
173
  off?(event: "change", handler: () => void): void;
172
174
  }
@@ -267,6 +269,20 @@ export interface NativePaneImage {
267
269
  cells?: { cols: number; rows: number; cells: NativeFrameCell[] };
268
270
  }
269
271
 
272
+ /**
273
+ * What the frame on screen drew on top, cell by cell: kitty images are drawn
274
+ * out of band, so the terminal image layer reads this to keep each image under
275
+ * whatever covers it.
276
+ */
277
+ export interface NativeFrameHits {
278
+ /** The renderable drawn last at a cell of the frame on screen, or null. */
279
+ at(x: number, y: number): unknown;
280
+ /** Whether a renderable fills its cells (a background), rather than only grouping or writing over others. */
281
+ paints(renderable: unknown): boolean;
282
+ /** Whether a renderable is still in the tree the terminal draws. */
283
+ attached(renderable: unknown): boolean;
284
+ }
285
+
270
286
  /** The last frame the terminal renderer drew, as styled rows. */
271
287
  export interface NativeFrameCapture {
272
288
  cols: number;
@@ -304,6 +320,8 @@ export interface NativeRendererHost {
304
320
  removePostProcessFn?(processFn: NativePostProcessFn): void;
305
321
  /** Terminal renderers only. Kitty graphics are drawn out of band and come back as blank cells. */
306
322
  captureFrame?(): NativeFrameCapture | null;
323
+ /** Terminal renderers only: what each cell of the frame on screen drew on top. */
324
+ frameHits?: NativeFrameHits;
307
325
  /**
308
326
  * Terminal renderers only: a PNG of a rectangle of the frame shown now, in
309
327
  * cells, its characters drawn in a bundled font and its kitty images put back.
@@ -1,5 +1,4 @@
1
- export function capturePointerDrag(renderer: unknown, renderable: unknown): void {
2
- if (!renderable) return;
1
+ function setCapture(renderer: unknown, renderable: unknown): void {
3
2
  const hostCapture = (renderer as { captureMouseRenderable?: (target: unknown) => void }).captureMouseRenderable;
4
3
  if (typeof hostCapture === "function") {
5
4
  hostCapture.call(renderer, renderable);
@@ -10,3 +9,13 @@ export function capturePointerDrag(renderer: unknown, renderable: unknown): void
10
9
  capture.call(renderer, renderable);
11
10
  }
12
11
  }
12
+
13
+ export function capturePointerDrag(renderer: unknown, renderable: unknown): void {
14
+ if (!renderable) return;
15
+ setCapture(renderer, renderable);
16
+ }
17
+
18
+ /** Ends a capture whose release never came (the button let go outside the window), so the next press goes where it lands. */
19
+ export function releasePointerDrag(renderer: unknown): void {
20
+ setCapture(renderer, undefined);
21
+ }
@@ -572,11 +572,22 @@ export function trailingEpsSourceNote(
572
572
 
573
573
  type PriceEarningsBasis = Pick<Fundamentals, "financialCurrency" | "ttmConversion" | "epsCurrency" | "trailingPEConversion">;
574
574
 
575
- /** The trailing EPS in the price's currency: converted at the rate the served P/E used when it says so. */
576
- export function priceEarningsEps(fundamentals: Pick<Fundamentals, "eps" | "trailingPEConversion"> | undefined): number | undefined {
575
+ /** The minor units a quote can be priced in, as Gloom Cloud reads them: pence, South African cents and agorot. */
576
+ const MINOR_QUOTE_UNITS = new Set(["GBp", "GBX", "ZAc", "ZAC", "ILA"]);
577
+
578
+ /**
579
+ * The trailing EPS in the price's currency and unit: converted at the rate the served P/E used when it says so, a
580
+ * rate into the major unit, so a price in pence, South African cents or agorot takes it a hundredfold (30,000 ILA
581
+ * over 2.50 USD at 3.7037 ILS is 32.4, not 3,240).
582
+ */
583
+ export function priceEarningsEps(
584
+ fundamentals: Pick<Fundamentals, "eps" | "trailingPEConversion"> | undefined,
585
+ quoteCurrency?: string | null,
586
+ ): number | undefined {
577
587
  const eps = fundamentals?.eps;
578
588
  const rate = fundamentals?.trailingPEConversion?.rate;
579
- return typeof eps === "number" && typeof rate === "number" && Number.isFinite(rate) && rate > 0 ? eps * rate : eps;
589
+ if (typeof eps !== "number" || typeof rate !== "number" || !Number.isFinite(rate) || !(rate > 0)) return eps;
590
+ return eps * rate * (MINOR_QUOTE_UNITS.has(quoteCurrency?.trim() ?? "") ? 100 : 1);
580
591
  }
581
592
 
582
593
  /**