@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
@@ -37,16 +37,17 @@ const MAGNET_RELEASE_PX = 12;
37
37
  const TERMINAL_MAGNETS: MagnetDistances = { catchX: 1, catchY: 1, releaseX: 2, releaseY: 2 };
38
38
 
39
39
  /**
40
- * Desktop: past this pointer speed, in catch distances a second (300 px/s),
41
- * a release lands the pane where the pointer puts it, its magnets left out.
40
+ * Past this pointer speed, in catch distances a second (300 px/s on the
41
+ * desktop, 37.5 cells in the terminal), a release lands the pane where the
42
+ * pointer puts it, its magnets left out.
42
43
  */
43
44
  const MAGNET_TRAVEL_SPEED = 300 / MAGNET_CATCH_PX;
44
45
  /**
45
- * Desktop: below this pointer speed (60 px/s, about a px a frame) the pointer
46
- * is placing the pane, and it is drawn where its magnets hold it; faster, it
47
- * is drawn under the pointer. Drawing the magnets at a hand's usual speed
48
- * held the pane on each line it crossed, then jumped it up to 18 px, which
49
- * read as a drag that lags and stutters.
46
+ * Below this pointer speed (60 px/s, about a px a frame) the pointer is
47
+ * placing the pane, and it is drawn where its magnets hold it; faster, it is
48
+ * drawn under the pointer. Drawing the magnets at a hand's usual speed held
49
+ * the pane on each line it crossed, then jumped it up to 18 px (three cells
50
+ * in the terminal), which read as a drag that lags and stutters.
50
51
  */
51
52
  const MAGNET_PLACE_SPEED = 60 / MAGNET_CATCH_PX;
52
53
  /**
@@ -59,6 +60,12 @@ const GLIDE_RATE = 35;
59
60
  const SPEED_WINDOW_MS = 64;
60
61
  /** How long the pointer rests before the magnets catch where it stopped, ms. */
61
62
  export const MAGNET_REST_MS = 80;
63
+ /**
64
+ * The same in the terminal, which hears from the pointer only as it enters
65
+ * another cell: a hand placing a window there crosses five or so a second, so
66
+ * a pause shorter than that is still a drag.
67
+ */
68
+ export const TERMINAL_MAGNET_REST_MS = 200;
62
69
 
63
70
  /** Where the pointer was during a move, in cells, and when (ms). */
64
71
  interface PointerSample {
@@ -75,7 +82,7 @@ function trackPointer(track: PointerSample[], sample: PointerSample): void {
75
82
  }
76
83
 
77
84
  /**
78
- * Desktop: when a moving pane's magnets act, over one drag. `travelling`
85
+ * When a moving pane's magnets act, over one drag. `travelling`
79
86
  * takes each move and says whether the pointer is on its way somewhere; while
80
87
  * it is, a release lands the pane where the pointer puts it, and `rest` (the
81
88
  * move run again) is set to run once the pointer has stopped for
@@ -90,6 +97,12 @@ export interface MagnetPace {
90
97
  travelling(sample: PointerSample, distances: MagnetDistances, rest?: () => void): boolean;
91
98
  /** Whether the pointer, as of `now`, moves slowly enough to be placing the pane: its magnets are drawn. */
92
99
  placing(now: number, distances: MagnetDistances): boolean;
100
+ /**
101
+ * Runs `onRest` once the pointer has stopped for `ms`, unless another event
102
+ * of the drag comes first: the terminal, which draws only when an event
103
+ * comes, draws the magnets that catch where it stopped.
104
+ */
105
+ rest(onRest: () => void, ms: number): void;
93
106
  /** Drops the rest check: another event of the drag came first. */
94
107
  cancel(): void;
95
108
  /** Forgets the pointer's path, for a new drag. */
@@ -106,6 +119,17 @@ export function createMagnetPace(): MagnetPace {
106
119
  rest = null;
107
120
  frame = null;
108
121
  };
122
+ const restThen = (onRest: () => void, ms = MAGNET_REST_MS) => {
123
+ cancel();
124
+ rest = setTimeout(() => {
125
+ rest = null;
126
+ if (typeof requestAnimationFrame !== "function") return onRest();
127
+ frame = requestAnimationFrame(() => {
128
+ frame = null;
129
+ onRest();
130
+ });
131
+ }, ms);
132
+ };
109
133
  return {
110
134
  travelling(sample, distances, onRest) {
111
135
  cancel();
@@ -113,19 +137,11 @@ export function createMagnetPace(): MagnetPace {
113
137
  // The same place again (a rest check, a repeated event) is not a move.
114
138
  if (!last || last.x !== sample.x || last.y !== sample.y) trackPointer(track, sample);
115
139
  if (pointerSpeed(track, sample.t, distances) <= MAGNET_TRAVEL_SPEED) return false;
116
- if (onRest) {
117
- rest = setTimeout(() => {
118
- rest = null;
119
- if (typeof requestAnimationFrame !== "function") return onRest();
120
- frame = requestAnimationFrame(() => {
121
- frame = null;
122
- onRest();
123
- });
124
- }, MAGNET_REST_MS);
125
- }
140
+ if (onRest) restThen(onRest);
126
141
  return true;
127
142
  },
128
143
  placing: (now, distances) => pointerSpeed(track, now, distances) < MAGNET_PLACE_SPEED,
144
+ rest: restThen,
129
145
  cancel,
130
146
  reset() {
131
147
  cancel();
@@ -26,6 +26,7 @@ import type { TickerRecord } from "../../types/ticker";
26
26
  import { PRICE_SPARKLINE_COLUMN_ID, PriceSparkline } from "../price-sparkline/view";
27
27
  import { DataTableView, type DataTableKeyEvent, type DataTableSelection } from "../data-table/view";
28
28
  import type { QuoteFlashDirection } from "../quote-flash";
29
+ import type { DataTableColumnReorder } from "../ui";
29
30
  import { objectVersion } from "../../utils/object-version";
30
31
  import { getCompletedRegularSessionDisplay } from "../../market-data/market/status";
31
32
  import { QUOTE_EXPORT_IDENTITY_HEADERS, quoteExportIdentityCells } from "../../market-data/quotes/export-identity";
@@ -152,6 +153,8 @@ export interface TickerListTableViewProps {
152
153
  addTickerShortcut?: string;
153
154
  virtualize?: boolean;
154
155
  overscan?: number;
156
+ /** How the header drags reorder the columns (`DataTableProps.columnReorder`). */
157
+ columnReorder?: false | DataTableColumnReorder;
155
158
  }
156
159
 
157
160
  const FLASHABLE_QUOTE_COLUMN_IDS = new Set([
@@ -287,6 +290,7 @@ export function TickerListTableView({
287
290
  virtualize = true,
288
291
  overscan = 4,
289
292
  exportName,
293
+ columnReorder,
290
294
  }: TickerListTableViewProps) {
291
295
  const commandBarShortcut = useCommandBarShortcut();
292
296
  const resolvedEmptyHint = emptyHint ?? tf("Press {shortcut} to add one.", { shortcut: addTickerShortcut ?? commandBarShortcut });
@@ -445,6 +449,7 @@ export function TickerListTableView({
445
449
  <DataTableView<TickerRecord, ColumnConfig>
446
450
  focused={focused}
447
451
  columns={columns}
452
+ columnReorder={columnReorder}
448
453
  items={items}
449
454
  isNavigable={summaries.length ? isNavigableRow : undefined}
450
455
  sortColumnId={sortColumnId ?? null}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Dragging a table's header moves its column, and the pane remembers the
3
+ * order. These are the rules every renderer and the pane's settings share:
4
+ * which leading columns stay put, where a drop lands, how a remembered order
5
+ * applies to the columns a pane passes, and how a move is written back.
6
+ */
7
+
8
+ /**
9
+ * The pane setting a table's remembered column order is kept under, by table
10
+ * (`DataTableColumnReorder.key`). Every kit table in every pane writes it, so
11
+ * it takes the reserved `pane.` prefix: a plugin's own settings never use it.
12
+ */
13
+ export const COLUMN_ORDER_SETTING = "pane.columnOrder";
14
+
15
+ /** How far a press on a header moves before it drags its column rather than sorting: pixels on the desktop and the web. */
16
+ export const COLUMN_DRAG_THRESHOLD_PX = 5;
17
+ /** The same in the terminal, in cells: a click that wobbles by one cell still sorts. */
18
+ export const COLUMN_DRAG_THRESHOLD_CELLS = 2;
19
+
20
+ /** Narrower than this, a leading column is a mark beside the row's name (a status dot, a star, a rank), not the name. */
21
+ const ROW_NAME_MIN_WIDTH = 4;
22
+
23
+ interface OrderedColumn {
24
+ id: string;
25
+ label: string;
26
+ width: number;
27
+ }
28
+
29
+ /**
30
+ * The leading columns that name the row and stay first: the first column, and
31
+ * with it the narrow unlabeled or rank columns before it, so a selection
32
+ * marker or a rank stays beside the ticker it marks.
33
+ */
34
+ export function rowAnchorColumnCount(columns: readonly OrderedColumn[]): number {
35
+ let count = 0;
36
+ for (const column of columns) {
37
+ count += 1;
38
+ if (column.label.trim() !== "" && column.width >= ROW_NAME_MIN_WIDTH) break;
39
+ }
40
+ return count;
41
+ }
42
+
43
+ /**
44
+ * The columns in the remembered order. The anchored columns stay first as the
45
+ * pane gave them; the others follow `saved`, and one it does not name (a
46
+ * column the pane added since) keeps its place after the column before it in
47
+ * the pane's own order. The same array when nothing moves.
48
+ */
49
+ export function orderColumns<C extends { id: string }>(
50
+ columns: readonly C[],
51
+ saved: readonly string[] | undefined,
52
+ anchored: number,
53
+ ): readonly C[] {
54
+ if (!saved || saved.length === 0 || columns.length - anchored < 2) return columns;
55
+ const rank = new Map(saved.map((id, index) => [id, index]));
56
+ const rest = columns.slice(anchored);
57
+ const placed = rest.filter((column) => rank.has(column.id))
58
+ .sort((left, right) => rank.get(left.id)! - rank.get(right.id)!);
59
+ if (placed.length === 0) return columns;
60
+ rest.forEach((column, index) => {
61
+ if (rank.has(column.id)) return;
62
+ let at = 0;
63
+ for (let before = index - 1; before >= 0; before -= 1) {
64
+ const position = placed.indexOf(rest[before]!);
65
+ if (position >= 0) {
66
+ at = position + 1;
67
+ break;
68
+ }
69
+ }
70
+ placed.splice(at, 0, column);
71
+ });
72
+ const ordered = [...columns.slice(0, anchored), ...placed];
73
+ return ordered.every((column, index) => column === columns[index]) ? columns : ordered;
74
+ }
75
+
76
+ /**
77
+ * The gap a dragged column would drop into, for a pointer at `x`: 0 before the
78
+ * first column, `spans.length` after the last, never before the anchored ones.
79
+ * `spans` are the columns' extents in the same units as `x`. `frozenEnd` is
80
+ * where a frozen first column ends on screen while the table is scrolled
81
+ * under it: the columns it covers cannot be dropped beside, so a pointer over
82
+ * it means the first gap past it, and a column it half covers is judged by
83
+ * the part that shows.
84
+ */
85
+ export function columnDropBoundary(
86
+ spans: readonly { start: number; end: number }[],
87
+ x: number,
88
+ anchored: number,
89
+ frozenEnd?: number,
90
+ ): number {
91
+ const reach = frozenEnd ?? Number.NEGATIVE_INFINITY;
92
+ const at = Math.max(x, reach);
93
+ let boundary = spans.length;
94
+ for (let index = 0; index < spans.length; index += 1) {
95
+ const span = spans[index]!;
96
+ if (index > 0 && span.end <= reach) continue;
97
+ const start = index > 0 ? Math.max(span.start, reach) : span.start;
98
+ if (at < (start + span.end) / 2) {
99
+ boundary = index;
100
+ break;
101
+ }
102
+ }
103
+ return Math.max(anchored, boundary);
104
+ }
105
+
106
+ /** The index a column dragged from `from` lands at when dropped into gap `boundary`, or null when it stays where it is. */
107
+ export function columnDropIndex(from: number, boundary: number): number | null {
108
+ if (boundary === from || boundary === from + 1) return null;
109
+ return boundary > from ? boundary - 1 : boundary;
110
+ }
111
+
112
+ /** The ids with `columnId` moved to `toIndex`, or null when that is no move (an anchored column, the same place). */
113
+ export function moveColumnId(
114
+ ids: readonly string[],
115
+ columnId: string,
116
+ toIndex: number,
117
+ anchored: number,
118
+ ): string[] | null {
119
+ const from = ids.indexOf(columnId);
120
+ if (from < anchored) return null;
121
+ const to = Math.max(anchored, Math.min(ids.length - 1, toIndex));
122
+ if (to === from) return null;
123
+ const next = ids.filter((id) => id !== columnId);
124
+ next.splice(to, 0, columnId);
125
+ return next;
126
+ }
127
+
128
+ /**
129
+ * The order to remember once a move turns the table's `before` order into
130
+ * `after` (the same ids). The table's ids take the places they held in
131
+ * `saved` in their new order, so a column the table does not show now (one
132
+ * a narrow pane dropped, another view's) keeps its own place. Ids `saved`
133
+ * does not have yet go in after the id before them in `before`.
134
+ */
135
+ export function rememberColumnOrder(
136
+ saved: readonly string[] | undefined,
137
+ before: readonly string[],
138
+ after: readonly string[],
139
+ ): string[] {
140
+ const base = [...(saved ?? [])];
141
+ let last = -1;
142
+ for (const id of before) {
143
+ const at = base.indexOf(id);
144
+ if (at >= 0) {
145
+ last = at;
146
+ continue;
147
+ }
148
+ last += 1;
149
+ base.splice(last, 0, id);
150
+ }
151
+ const shown = new Set(after);
152
+ const slots = base.flatMap((id, index) => shown.has(id) ? [index] : []);
153
+ slots.forEach((slot, index) => {
154
+ base[slot] = after[index]!;
155
+ });
156
+ return base;
157
+ }
158
+
159
+ /** `order` put back in `defaultOrder`'s order; ids it does not list keep their order after those it does. */
160
+ export function defaultColumnOrder(order: readonly string[], defaultOrder: readonly string[]): string[] {
161
+ const rank = new Map(defaultOrder.map((id, index) => [id, index]));
162
+ return order
163
+ .map((id, index) => ({ id, index, rank: rank.get(id) ?? Number.POSITIVE_INFINITY }))
164
+ .sort((left, right) => left.rank - right.rank || left.index - right.index)
165
+ .map((entry) => entry.id);
166
+ }
167
+
168
+ /** The remembered orders in a pane's settings, by table; anything else there reads as none. */
169
+ export function readColumnOrders(value: unknown): Readonly<Record<string, readonly string[]>> {
170
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
171
+ const orders: Record<string, readonly string[]> = {};
172
+ for (const [key, ids] of Object.entries(value as Record<string, unknown>)) {
173
+ if (Array.isArray(ids) && ids.every((id) => typeof id === "string")) orders[key] = ids as string[];
174
+ }
175
+ return orders;
176
+ }
177
+
178
+ export function sameIds(left: readonly string[], right: readonly string[]): boolean {
179
+ return left.length === right.length && left.every((id, index) => id === right[index]);
180
+ }
@@ -12,10 +12,12 @@ import { registerPaneTableExporter } from "../../../state/pane-table-export-regi
12
12
  import { createDataTableCsv } from "../../data-table/export";
13
13
  import { headerCase } from "../header-case";
14
14
  import { figureColumnCells } from "./render-cell";
15
+ import { useDataTableColumnOrder } from "./use-column-order";
15
16
 
16
17
  export type {
17
18
  DataTableCell,
18
19
  DataTableColumn,
20
+ DataTableColumnReorder,
19
21
  DataTableProps,
20
22
  DataTableSectionHeader,
21
23
  DataTableVisibleRange,
@@ -26,7 +28,16 @@ export function DataTable<T, C extends DataTableColumn = DataTableColumn>(
26
28
  ) {
27
29
  // Every renderer, report and export reads the cells through this, so a column of figures lines up everywhere.
28
30
  const renderCell = useMemo(() => figureColumnCells(ownProps.renderCell), [ownProps.renderCell]);
29
- const props = { ...ownProps, renderCell };
31
+ // A caller that already ordered the columns (`DataTableView`) passes the move it resolved.
32
+ const order = useDataTableColumnOrder(ownProps.columns, ownProps.onColumnMove ? false : ownProps.columnReorder);
33
+ const props = {
34
+ ...ownProps,
35
+ renderCell,
36
+ // Exports and reports read the columns in the order the reader sees them.
37
+ columns: order.columns,
38
+ onColumnMove: ownProps.onColumnMove ?? order.onColumnMove,
39
+ anchoredColumns: ownProps.onColumnMove ? ownProps.anchoredColumns : order.anchoredColumns,
40
+ };
30
41
  const paneId = useOptionalPaneInstanceId();
31
42
  const renderer = useRendererHost();
32
43
  const propsRef = useRef(props);