@gloom-sh/terminal 0.20.9 → 0.20.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
  3. package/src/api-client/auth.ts +6 -0
  4. package/src/api-client/data.ts +1 -0
  5. package/src/api-client/earnings.ts +15 -0
  6. package/src/api-client/index.ts +14 -3
  7. package/src/api-client/socket-connection.ts +355 -0
  8. package/src/api-client/socket-features.ts +75 -0
  9. package/src/api-client/socket-frames.ts +161 -0
  10. package/src/api-client/socket-listeners.ts +207 -0
  11. package/src/api-client/socket-quotes.ts +332 -0
  12. package/src/api-client/socket.ts +150 -983
  13. package/src/api-client/types/account.ts +10 -0
  14. package/src/api-client/types/billing.ts +10 -0
  15. package/src/api-client/types/econ.ts +19 -7
  16. package/src/api-client/types/market.ts +7 -0
  17. package/src/api-client/types/screener.ts +2 -0
  18. package/src/brokers/signed-in/adapter.ts +19 -5
  19. package/src/brokers/signed-in/client.ts +13 -1
  20. package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
  21. package/src/cli/commands/market.ts +18 -8
  22. package/src/cli/commands/overview.ts +26 -7
  23. package/src/cli/commands/ticker.ts +40 -15
  24. package/src/cli/desktop-pane-shot.ts +39 -0
  25. package/src/cli/errors.ts +20 -3
  26. package/src/cli/fx-pair.ts +11 -2
  27. package/src/cli/history-rows.ts +34 -3
  28. package/src/cli/index.ts +1 -1
  29. package/src/cli/listing-arg.ts +51 -13
  30. package/src/cli/pane-functions/headless.ts +4 -2
  31. package/src/cli/pane-functions/index.ts +1 -0
  32. package/src/cli/pane-functions/resolver.ts +2 -1
  33. package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
  34. package/src/cli/pane-functions/screenshot-types.ts +4 -0
  35. package/src/components/chart/composite/chart-layout.ts +7 -4
  36. package/src/components/chart/composite/composite-chart.tsx +6 -16
  37. package/src/components/chart/composite/toolbar.tsx +258 -82
  38. package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
  39. package/src/components/chart/native/kitty/manager.ts +2 -0
  40. package/src/components/chart/native/surface/manager.ts +211 -11
  41. package/src/components/command-bar/list/model.ts +13 -0
  42. package/src/components/command-bar/panel/index.tsx +2 -13
  43. package/src/components/command-bar/panel/layout.ts +1 -7
  44. package/src/components/command-bar/panel/runtime.ts +0 -1
  45. package/src/components/command-bar/panel/types.ts +0 -2
  46. package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
  47. package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
  48. package/src/components/command-bar/surface/index.tsx +10 -5
  49. package/src/components/command-bar/workflow/alert.ts +21 -7
  50. package/src/components/data-table/column-menu.tsx +89 -0
  51. package/src/components/data-table/sort-menu.tsx +9 -2
  52. package/src/components/data-table/table-pane.ts +3 -1
  53. package/src/components/data-table/view.tsx +33 -6
  54. package/src/components/form-modal/content.tsx +10 -0
  55. package/src/components/index.ts +1 -1
  56. package/src/components/layout/pane/footer/index.tsx +25 -11
  57. package/src/components/layout/pane/footer/model.ts +88 -21
  58. package/src/components/layout/pane/sidebar.tsx +125 -15
  59. package/src/components/layout/shell/active-drag.ts +18 -13
  60. package/src/components/layout/shell/drag/magnets.ts +34 -18
  61. package/src/components/metric-treemap/heat-surface.tsx +2 -1
  62. package/src/components/metric-treemap/index.tsx +3 -2
  63. package/src/components/ticker/list-table-view.tsx +5 -0
  64. package/src/components/ui/confirm-dialog.tsx +253 -7
  65. package/src/components/ui/data-table/column-order.ts +180 -0
  66. package/src/components/ui/data-table/index.tsx +13 -2
  67. package/src/components/ui/data-table/opentui/index.tsx +267 -23
  68. package/src/components/ui/data-table/opentui/model.ts +43 -4
  69. package/src/components/ui/data-table/types.ts +56 -0
  70. package/src/components/ui/data-table/use-column-order.ts +135 -0
  71. package/src/components/ui/index.ts +1 -1
  72. package/src/components/ui/list-view.tsx +4 -3
  73. package/src/components/ui/status.tsx +9 -6
  74. package/src/components/ui/table-layout.ts +120 -0
  75. package/src/docs/snapshot.json +39 -2
  76. package/src/i18n/es.ts +14 -0
  77. package/src/i18n/ja.ts +14 -0
  78. package/src/i18n/ko.ts +14 -0
  79. package/src/i18n/zh-cn.ts +14 -0
  80. package/src/i18n/zh-tw.ts +14 -0
  81. package/src/market-data/coordinator/index.ts +4 -3
  82. package/src/market-data/coordinator/quotes.ts +12 -4
  83. package/src/market-data/fx-closes.ts +14 -2
  84. package/src/market-data/market/change-basis.ts +35 -1
  85. package/src/market-data/market/status.ts +37 -0
  86. package/src/market-data/performance.ts +4 -1
  87. package/src/market-data/quotes/freshness.ts +12 -0
  88. package/src/market-data/quotes/live-valuation.ts +26 -3
  89. package/src/market-data/quotes/regular-session-valuation.ts +1 -1
  90. package/src/market-data/realized-volatility.ts +3 -0
  91. package/src/market-data/us-bond-market.ts +115 -0
  92. package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
  93. package/src/plugins/builtin/account-management/keyboard.ts +3 -0
  94. package/src/plugins/builtin/account-management/model.ts +1 -0
  95. package/src/plugins/builtin/account-management/pane.tsx +51 -5
  96. package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
  97. package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
  98. package/src/plugins/builtin/broker-manager/index.tsx +6 -6
  99. package/src/plugins/builtin/broker-manager/model.ts +15 -6
  100. package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
  101. package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
  102. package/src/plugins/builtin/broker-manager/table.ts +10 -4
  103. package/src/plugins/builtin/chat/sidebar.tsx +33 -16
  104. package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
  105. package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
  106. package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
  107. package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
  108. package/src/plugins/builtin/correlation/compute.ts +4 -3
  109. package/src/plugins/builtin/earnings/board-model.ts +33 -0
  110. package/src/plugins/builtin/earnings/board-table.ts +50 -11
  111. package/src/plugins/builtin/earnings/board.tsx +29 -13
  112. package/src/plugins/builtin/earnings/calendar.tsx +15 -3
  113. package/src/plugins/builtin/earnings/client.ts +4 -1
  114. package/src/plugins/builtin/earnings/headless.ts +27 -14
  115. package/src/plugins/builtin/econ/calendar-source.ts +3 -0
  116. package/src/plugins/builtin/equity-screener/live.ts +74 -18
  117. package/src/plugins/builtin/equity-screener/model.ts +19 -4
  118. package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
  119. package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
  120. package/src/plugins/builtin/equity-screener/results.ts +22 -2
  121. package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
  122. package/src/plugins/builtin/futures/index.tsx +15 -1
  123. package/src/plugins/builtin/futures/table.tsx +1 -1
  124. package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
  125. package/src/plugins/builtin/help/index.tsx +1 -1
  126. package/src/plugins/builtin/holders/pane.tsx +30 -20
  127. package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
  128. package/src/plugins/builtin/iv-history/events.ts +5 -0
  129. package/src/plugins/builtin/iv-history/headless.ts +19 -12
  130. package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
  131. package/src/plugins/builtin/macro-day/headless.ts +27 -8
  132. package/src/plugins/builtin/macro-day/model.ts +17 -4
  133. package/src/plugins/builtin/macro-day/releases.ts +36 -15
  134. package/src/plugins/builtin/market-halts/model.ts +3 -2
  135. package/src/plugins/builtin/market-movers/headless.ts +2 -1
  136. package/src/plugins/builtin/market-movers/index.tsx +3 -2
  137. package/src/plugins/builtin/market-movers/model.ts +75 -22
  138. package/src/plugins/builtin/market-movers/screener.ts +2 -1
  139. package/src/plugins/builtin/market-movers/table.ts +7 -5
  140. package/src/plugins/builtin/options/view.tsx +2 -0
  141. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  142. package/src/plugins/builtin/pe-band/model.ts +4 -0
  143. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
  144. package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
  145. package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
  146. package/src/plugins/builtin/portfolio-list/pane/index.tsx +15 -1
  147. package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
  148. package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
  149. package/src/plugins/builtin/portfolio-list/table.tsx +18 -1
  150. package/src/plugins/builtin/rate-path/pane.tsx +2 -0
  151. package/src/plugins/builtin/research/analyst-headless.ts +9 -1
  152. package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
  153. package/src/plugins/builtin/research/client.ts +25 -1
  154. package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
  155. package/src/plugins/builtin/research/event-model.ts +3 -13
  156. package/src/plugins/builtin/research/event-sources.ts +3 -1
  157. package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
  158. package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
  159. package/src/plugins/builtin/seasonality/pane.tsx +2 -1
  160. package/src/plugins/builtin/short-interest/headless.ts +2 -0
  161. package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
  162. package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
  163. package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
  164. package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
  165. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
  166. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
  167. package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
  168. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  169. package/src/plugins/builtin/world-indices/index.tsx +5 -1
  170. package/src/plugins/builtin/yield-curve/headless.ts +5 -1
  171. package/src/plugins/builtin/yield-curve/index.tsx +7 -1
  172. package/src/portfolio/column-values.ts +47 -14
  173. package/src/portfolio/return-metrics.ts +4 -2
  174. package/src/renderers/dom/data-table/column-drag.ts +147 -0
  175. package/src/renderers/dom/data-table/index.tsx +22 -0
  176. package/src/renderers/dom/data-table/row.tsx +27 -5
  177. package/src/renderers/dom/host/image-surface.tsx +19 -9
  178. package/src/renderers/dom/host/input.tsx +4 -0
  179. package/src/renderers/dom/styles.css +22 -0
  180. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
  181. package/src/renderers/opentui/chart-surface.tsx +1 -0
  182. package/src/renderers/opentui/frame-hits.ts +33 -0
  183. package/src/renderers/opentui/host.tsx +2 -0
  184. package/src/renderers/opentui/native-surface.ts +14 -21
  185. package/src/renderers/opentui/test-utils.tsx +3 -0
  186. package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
  187. package/src/sources/provider-errors.ts +12 -0
  188. package/src/sources/provider-router/index.ts +12 -4
  189. package/src/state/app/context/index.tsx +22 -0
  190. package/src/state/pane-session.ts +145 -0
  191. package/src/test-support/app-store.ts +24 -1
  192. package/src/tickers/search/home-listing.ts +44 -1
  193. package/src/tickers/search/index.ts +5 -2
  194. package/src/tickers/search/ranking.ts +7 -7
  195. package/src/tickers/us-listing.ts +11 -5
  196. package/src/time-series/base-series.ts +7 -1
  197. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  198. package/src/time-series/fundamentals/series.ts +6 -0
  199. package/src/time-series/live-quotes.ts +3 -9
  200. package/src/time-series/resolve.ts +1 -0
  201. package/src/types/financials.ts +20 -0
  202. package/src/types/headless.ts +9 -0
  203. package/src/ui/host.tsx +20 -0
  204. package/src/ui/pointer-drag.ts +11 -2
  205. package/src/utils/exchanges.ts +13 -8
  206. package/src/utils/fundamentals.ts +14 -3
  207. package/src/utils/price-earnings.ts +17 -10
  208. package/src/utils/price-history-integrity.ts +15 -0
  209. package/src/utils/reason-codes.ts +79 -0
  210. package/src/utils/share-multiples.cases.json +1667 -0
  211. package/src/utils/share-multiples.ts +384 -0
  212. package/src/utils/untrusted-text.ts +11 -0
@@ -666,15 +666,9 @@ function ThemedCompositeChart({
666
666
  const patchLayout = useCallback((patch: ChartLayoutPrefs | ((layout: ChartLayoutPrefs) => ChartLayoutPrefs)) => {
667
667
  layoutStateRef.current.onChartLayoutChange((layout) => patchChartLayout(layout, typeof patch === "function" ? patch(layout) : patch));
668
668
  }, []);
669
- // The tool in hand, read when the bar is toggled (the keyboard hook below holds it).
670
- const toolInHandRef = useRef<{ armed: boolean; putDown: () => void }>({ armed: false, putDown: () => {} });
671
- // Shift+T and the chevrons act on the bar as it shows: a bar open only for
672
- // the tool in hand folds again, the tool put down, and stays hidden.
669
+ // Shift+T and the bar's own button keep it open, or let it fold to the tool in hand again.
673
670
  const toggleToolbar = useCallback(() => {
674
- const tool = toolInHandRef.current;
675
- const hidden = layoutStateRef.current.chartLayout.toolbarHidden === true && !tool.armed;
676
- if (!hidden && tool.armed) tool.putDown();
677
- patchLayout({ toolbarHidden: !hidden });
671
+ patchLayout({ toolbarPinned: layoutStateRef.current.chartLayout.toolbarPinned !== true });
678
672
  }, [patchLayout]);
679
673
  const toggleLegendCollapsed = useCallback(() => patchLayout((layout) => ({ legendCollapsed: !layout.legendCollapsed })), [patchLayout]);
680
674
  const resetPanelHeights = useCallback(() => {
@@ -721,7 +715,7 @@ function ThemedCompositeChart({
721
715
  const legendCollapsed = legendCollapsible && chartLayout.legendCollapsed === true;
722
716
  const projectedPanelCount = projectedScene?.panels.length ?? 0;
723
717
  const layoutControls = useMemo(() => ({
724
- toolbarHidden: chartLayout.toolbarHidden === true,
718
+ toolbarPinned: chartLayout.toolbarPinned === true,
725
719
  toggleToolbar,
726
720
  legendCollapsible,
727
721
  legendCollapsed,
@@ -734,7 +728,7 @@ function ThemedCompositeChart({
734
728
  restorePanels: resetPanelMaximized,
735
729
  }), [
736
730
  chartLayout.panelWeights,
737
- chartLayout.toolbarHidden,
731
+ chartLayout.toolbarPinned,
738
732
  layoutPanels?.length,
739
733
  legendCollapsed,
740
734
  legendCollapsible,
@@ -794,7 +788,6 @@ function ThemedCompositeChart({
794
788
  pickDrawColor,
795
789
  layout: layoutControls,
796
790
  });
797
- toolInHandRef.current = { armed: armedTool !== null, putDown: () => armTool(null) };
798
791
  const pressFromPointer = useCallback(() => {
799
792
  onPress?.();
800
793
  activateFromPointer();
@@ -1045,9 +1038,6 @@ function ThemedCompositeChart({
1045
1038
  // drawing. A chart outside a pane (a share page) keeps them.
1046
1039
  const toolbarWanted = paneFocused !== false || armedTool !== null || pointerDragging || toolSpan !== null;
1047
1040
  const showToolbar = interactive && navigable && toolbarWanted && plotWidth > CHART_TOOLBAR_WIDTH + 4;
1048
- // Hidden, the bar folds to the button that brings it back, and opens again
1049
- // while a tool picked from the keys is in hand, so the plot says which one.
1050
- const toolbarFolded = showToolbar && chartLayout.toolbarHidden === true && armedTool === null;
1051
1041
  // Bars shorter than a day carry a time of day the cursor reads out.
1052
1042
  const intradayBars = baseScene.timeZone !== undefined || visibleSeries.some((entry) => (
1053
1043
  !!entry.historyResolution && isIntradayResolution(entry.historyResolution)
@@ -1119,8 +1109,8 @@ function ThemedCompositeChart({
1119
1109
  drawColor={drawColor}
1120
1110
  showColors={isDrawingTool(armedTool) || !!selectedDrawingId}
1121
1111
  levelTool={levelsEditable}
1122
- folded={toolbarFolded}
1123
- onToggleFolded={() => {
1112
+ pinned={chartLayout.toolbarPinned === true}
1113
+ onTogglePinned={() => {
1124
1114
  pressFromPointer();
1125
1115
  toggleToolbar();
1126
1116
  }}
@@ -1,46 +1,64 @@
1
- import { Box, Text, useShortcutLabel } from "../../../ui";
1
+ import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
2
+ import { Box, Text, useShortcutLabel, type BoxRenderable } from "../../../ui";
2
3
  import { colors as themeColors, hoverBg } from "../../../theme/colors";
3
4
  import { consumeChartMouseEvent, type ChartMouseEvent } from "../core/pointer";
4
5
  import { CHART_DRAWING_COLORS, type ChartToolKind } from "./tools";
5
6
  import { CHART_TOOLS } from "./tool-catalog";
6
7
 
7
- /** Icon cells plus the gap between chips. */
8
- export const CHART_TOOLBAR_WIDTH = CHART_TOOLS.length * 3 + (CHART_TOOLS.length - 1);
8
+ /** The bar's tools, a gap, and the handle that opens it. */
9
+ export const CHART_TOOLBAR_WIDTH = CHART_TOOLS.length * 3 + (CHART_TOOLS.length - 1) + 4;
9
10
 
10
- /** The bar's own button that folds it away, and the one it folds to. */
11
- const FOLD_BUTTON = {
12
- label: "Hide drawing tools",
13
- shortcut: "Shift+T",
14
- glyph: "\u2039",
15
- icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M10 3.5 5.5 8l4.5 4.5" fill="none" stroke="#000" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
16
- };
17
- const UNFOLD_BUTTON = {
18
- label: "Show drawing tools",
19
- shortcut: "Shift+T",
11
+ /** How long the bar stays open once the pointer has left it. */
12
+ export const CHART_TOOLBAR_FOLD_DELAY_MS = 300;
13
+
14
+ const SHORTCUT = "Shift+T";
15
+ /** The handle's icon and its hint, in px on the desktop: together they fix its width, so it keeps it when the bar opens. */
16
+ const HANDLE_ICON_PX = 13;
17
+ const HANDLE_HINT_PX = 9;
18
+ const HANDLE_WIDTH = `calc(var(--gloom-space-xs) * 2 + ${HANDLE_ICON_PX + HANDLE_HINT_PX}px)`;
19
+ /** The hint on the folded handle: the bar opens to its right. */
20
+ const OPEN_CHEVRON = {
20
21
  glyph: "\u203a",
21
22
  icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M6 3.5 10.5 8 6 12.5" fill="none" stroke="#000" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
22
23
  };
24
+ /** The handle of a bar kept open, which folds it. */
25
+ const FOLD_CHEVRON = {
26
+ glyph: "\u2039",
27
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M10 3.5 5.5 8l4.5 4.5" fill="none" stroke="#000" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
28
+ };
23
29
 
24
- function ChartToolButton({
25
- tool,
30
+ interface PressEventLike {
31
+ key?: string;
32
+ preventDefault?: () => void;
33
+ stopPropagation?: () => void;
34
+ }
35
+
36
+ /** One of the chart's icon buttons: the control radius, the icon button's hover fill, a 13px icon. */
37
+ function ChartIconButton({
38
+ label,
26
39
  active,
27
40
  isDesktopWeb,
28
41
  onPress,
29
42
  role = "composite-chart-tool",
30
- reveal,
43
+ pressed,
44
+ expanded,
45
+ width,
46
+ children,
31
47
  }: {
32
- tool: { label: string; glyph: string; icon: string; shortcut?: string; hint?: string };
48
+ label: string;
33
49
  active: boolean;
34
50
  isDesktopWeb: boolean;
35
51
  onPress: () => void;
36
52
  role?: string;
37
- /** Drawn only while the pointer is over the bar (desktop and web). */
38
- reveal?: boolean;
53
+ /** A toggle: pressed while it is the chart's tool. */
54
+ pressed?: boolean;
55
+ /** A disclosure: open while the bar shows its tools. */
56
+ expanded?: boolean;
57
+ /** The desktop button's width when it is not its icon's (CSS length). */
58
+ width?: string;
59
+ /** Terminal cells for a glyph, or the desktop's masks. */
60
+ children: ReactNode;
39
61
  }) {
40
- const keyLabel = useShortcutLabel();
41
- const named = tool.shortcut ? `${tool.label} (${keyLabel(tool.shortcut)})` : tool.label;
42
- const label = tool.hint ? `${named}. ${tool.hint}` : named;
43
- const color = active ? themeColors.text : themeColors.textDim;
44
62
  return (
45
63
  <Box
46
64
  flexDirection="row"
@@ -59,42 +77,128 @@ function ChartToolButton({
59
77
  data-gloom-interactive="true"
60
78
  data-gloom-role={role}
61
79
  data-gloom-label={label}
62
- data-gloom-reveal={reveal ? "hover" : undefined}
63
80
  data-active={active ? "true" : "false"}
64
81
  title={isDesktopWeb ? label : undefined}
65
- // A tool is a toggle button: the icon button family, pressed while it is the chart's tool.
66
82
  role={isDesktopWeb ? "button" : undefined}
67
83
  aria-label={isDesktopWeb ? label : undefined}
68
- aria-pressed={isDesktopWeb ? active : undefined}
84
+ aria-pressed={isDesktopWeb ? pressed : undefined}
85
+ aria-expanded={isDesktopWeb ? expanded : undefined}
86
+ // Focusable for assistive technology, which opens the bar with the focus.
87
+ // The keyboard's own way is Shift+T: the window keeps Tab for itself.
88
+ tabIndex={isDesktopWeb ? 0 : undefined}
89
+ onKeyDown={isDesktopWeb
90
+ ? (event: PressEventLike) => {
91
+ if (event.key !== "Enter" && event.key !== " ") return;
92
+ event.preventDefault?.();
93
+ event.stopPropagation?.();
94
+ onPress();
95
+ }
96
+ : undefined}
69
97
  // Cells size the terminal strip; the desktop chip sizes to its icon.
70
98
  // The icon button's look: the control radius, the hover fill.
71
- style={isDesktopWeb ? { width: "auto", paddingInline: "var(--gloom-space-xs)", borderRadius: "var(--gloom-radius-md)" } : undefined}
99
+ style={isDesktopWeb ? { width: width ?? "auto", paddingInline: "var(--gloom-space-xs)", borderRadius: "var(--gloom-radius-md)" } : undefined}
100
+ >
101
+ {children}
102
+ </Box>
103
+ );
104
+ }
105
+
106
+ function MaskIcon({ icon, color, size = HANDLE_ICON_PX, visible = true }: { icon: string; color: string; size?: number; visible?: boolean }) {
107
+ return (
108
+ <Box
109
+ flexShrink={0}
110
+ visible={visible}
111
+ style={{
112
+ width: size,
113
+ height: size,
114
+ backgroundColor: color,
115
+ maskImage: svgMaskUrl(icon),
116
+ WebkitMaskImage: svgMaskUrl(icon),
117
+ maskSize: "contain",
118
+ WebkitMaskSize: "contain",
119
+ maskRepeat: "no-repeat",
120
+ WebkitMaskRepeat: "no-repeat",
121
+ maskPosition: "center",
122
+ WebkitMaskPosition: "center",
123
+ }}
124
+ />
125
+ );
126
+ }
127
+
128
+ function ChartToolButton({
129
+ tool,
130
+ active,
131
+ isDesktopWeb,
132
+ onPress,
133
+ }: {
134
+ tool: { label: string; glyph: string; icon: string; shortcut?: string; hint?: string };
135
+ active: boolean;
136
+ isDesktopWeb: boolean;
137
+ onPress: () => void;
138
+ }) {
139
+ const keyLabel = useShortcutLabel();
140
+ const named = tool.shortcut ? `${tool.label} (${keyLabel(tool.shortcut)})` : tool.label;
141
+ const label = tool.hint ? `${named}. ${tool.hint}` : named;
142
+ const color = active ? themeColors.text : themeColors.textDim;
143
+ return (
144
+ <ChartIconButton label={label} active={active} pressed={active} isDesktopWeb={isDesktopWeb} onPress={onPress}>
145
+ {isDesktopWeb ? <MaskIcon icon={tool.icon} color={color} /> : <Text fg={color}>{tool.glyph}</Text>}
146
+ </ChartIconButton>
147
+ );
148
+ }
149
+
150
+ /**
151
+ * The bar's one fixed button, first in it so the pointer that opened the bar
152
+ * is still on it. Folded, it shows the tool in hand, with a hint that it
153
+ * opens; open, only the chevron, which keeps the bar open or lets it fold.
154
+ */
155
+ function ChartToolbarHandle({
156
+ tool,
157
+ armed,
158
+ expanded,
159
+ pinned,
160
+ isDesktopWeb,
161
+ onPress,
162
+ }: {
163
+ tool: { label: string; glyph: string; icon: string };
164
+ /** A tool is in hand, not the resting pan. */
165
+ armed: boolean;
166
+ expanded: boolean;
167
+ pinned: boolean;
168
+ isDesktopWeb: boolean;
169
+ onPress: () => void;
170
+ }) {
171
+ const keyLabel = useShortcutLabel();
172
+ const keys = keyLabel(SHORTCUT);
173
+ const label = expanded
174
+ ? pinned ? `Hide drawing tools (${keys})` : `Keep drawing tools open (${keys})`
175
+ : `${tool.label}. Show drawing tools (${keys})`;
176
+ const color = armed ? themeColors.text : themeColors.textDim;
177
+ const chevron = pinned ? FOLD_CHEVRON : OPEN_CHEVRON;
178
+ return (
179
+ <ChartIconButton
180
+ label={label}
181
+ active={armed && !expanded}
182
+ expanded={expanded}
183
+ width={HANDLE_WIDTH}
184
+ isDesktopWeb={isDesktopWeb}
185
+ onPress={onPress}
186
+ role="composite-chart-toolbar-toggle"
72
187
  >
73
188
  {isDesktopWeb ? (
74
- <Box
75
- flexShrink={0}
76
- style={{
77
- width: 13,
78
- height: 13,
79
- backgroundColor: color,
80
- maskImage: svgMaskUrl(tool.icon),
81
- WebkitMaskImage: svgMaskUrl(tool.icon),
82
- maskSize: "contain",
83
- WebkitMaskSize: "contain",
84
- maskRepeat: "no-repeat",
85
- WebkitMaskRepeat: "no-repeat",
86
- maskPosition: "center",
87
- WebkitMaskPosition: "center",
88
- }}
89
- />
189
+ <>
190
+ {/* Hidden, not removed, once the bar is open: the pointer that opened it is on this icon, and a press that lands as the bar opens still reaches the button.
191
+ The button keeps its width, so a pointer that came in at its edge is still on it. */}
192
+ <MaskIcon icon={tool.icon} color={color} visible={!expanded} />
193
+ <MaskIcon icon={chevron.icon} color={themeColors.textDim} size={expanded ? HANDLE_ICON_PX : HANDLE_HINT_PX} />
194
+ </>
90
195
  ) : (
91
- <Text fg={color}>{tool.glyph}</Text>
196
+ <Text fg={color}>{expanded ? chevron.glyph : `${tool.glyph}${chevron.glyph}`}</Text>
92
197
  )}
93
- </Box>
198
+ </ChartIconButton>
94
199
  );
95
200
  }
96
201
 
97
-
98
202
  function svgMaskUrl(svg: string): string {
99
203
  return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
100
204
  }
@@ -152,8 +256,8 @@ export function ChartToolbar({
152
256
  drawColor,
153
257
  showColors,
154
258
  levelTool,
155
- folded,
156
- onToggleFolded,
259
+ pinned,
260
+ onTogglePinned,
157
261
  onArmTool,
158
262
  onPickColor,
159
263
  }: {
@@ -165,15 +269,20 @@ export function ChartToolbar({
165
269
  showColors: boolean;
166
270
  /** The chart's levels can be edited here. */
167
271
  levelTool: boolean;
168
- /** Hidden by the user: the bar is the one button that brings it back. */
169
- folded: boolean;
170
- /** Folds the bar away, from the button it shows under the pointer, or opens it again. */
171
- onToggleFolded: () => void;
272
+ /** Kept open by the user. Otherwise the bar is folded to the tool in hand and opens under the pointer. */
273
+ pinned: boolean;
274
+ /** Keeps the bar open, or lets it fold again. */
275
+ onTogglePinned: () => void;
172
276
  onArmTool: (tool: ChartToolKind | null) => void;
173
277
  onPickColor: (color: string) => void;
174
278
  }) {
279
+ const barRef = useRef<BoxRenderable | null>(null);
280
+ const { open, onHover, onLeave, onFocus, onBlur, fold } = useToolbarOpening(barRef);
281
+ const expanded = pinned || open;
282
+ const tool = CHART_TOOLS.find((entry) => entry.kind === armedTool) ?? CHART_TOOLS[0]!;
175
283
  return (
176
284
  <Box
285
+ ref={barRef}
177
286
  position="absolute"
178
287
  left={left}
179
288
  top={top}
@@ -194,29 +303,37 @@ export function ChartToolbar({
194
303
  }
195
304
  : undefined}
196
305
  data-gloom-role="composite-chart-toolbar"
197
- data-gloom-reveal-scope="true"
198
- data-folded={folded ? "true" : undefined}
306
+ data-folded={expanded ? undefined : "true"}
307
+ data-pinned={pinned ? "true" : undefined}
308
+ onMouseOver={onHover}
309
+ onMouseOut={onLeave}
310
+ onFocus={isDesktopWeb ? onFocus : undefined}
311
+ onBlur={isDesktopWeb ? onBlur : undefined}
199
312
  >
200
- {folded ? (
201
- <ChartToolButton
202
- tool={UNFOLD_BUTTON}
203
- active={false}
204
- isDesktopWeb={isDesktopWeb}
205
- onPress={onToggleFolded}
206
- role="composite-chart-toolbar-toggle"
207
- />
208
- ) : null}
209
- {folded ? null : CHART_TOOLS.filter((tool) => levelTool || tool.kind !== "level").map((tool) => (
313
+ <ChartToolbarHandle
314
+ tool={tool}
315
+ armed={armedTool !== null}
316
+ expanded={expanded}
317
+ pinned={pinned}
318
+ isDesktopWeb={isDesktopWeb}
319
+ onPress={() => {
320
+ // Pressed while the bar is open only for the pointer or the focus,
321
+ // it stays open; pressed while kept open, it folds now.
322
+ if (pinned) fold();
323
+ onTogglePinned();
324
+ }}
325
+ />
326
+ {expanded ? CHART_TOOLS.filter((entry) => levelTool || entry.kind !== "level").map((entry) => (
210
327
  <ChartToolButton
211
- key={tool.kind ?? "pan"}
212
- tool={tool}
213
- active={armedTool === tool.kind}
328
+ key={entry.kind ?? "pan"}
329
+ tool={entry}
330
+ active={armedTool === entry.kind}
214
331
  isDesktopWeb={isDesktopWeb}
215
- onPress={() => onArmTool(tool.kind)}
332
+ onPress={() => onArmTool(entry.kind)}
216
333
  />
217
- ))}
334
+ )) : null}
218
335
  {/* Colours only take space while something can use them. */}
219
- {!folded && showColors ? CHART_DRAWING_COLORS.map((color) => (
336
+ {expanded && showColors ? CHART_DRAWING_COLORS.map((color) => (
220
337
  <ChartColorSwatch
221
338
  key={color}
222
339
  color={color}
@@ -225,18 +342,77 @@ export function ChartToolbar({
225
342
  onPress={() => onPickColor(color)}
226
343
  />
227
344
  )) : null}
228
- {/* The way to fold the bar shows under the pointer, so a chart at rest
229
- draws the bar as it always has; the terminal has Shift+T and the menu. */}
230
- {!folded && isDesktopWeb ? (
231
- <ChartToolButton
232
- tool={FOLD_BUTTON}
233
- active={false}
234
- isDesktopWeb={isDesktopWeb}
235
- onPress={onToggleFolded}
236
- role="composite-chart-toolbar-toggle"
237
- reveal
238
- />
239
- ) : null}
240
345
  </Box>
241
346
  );
242
347
  }
348
+
349
+ const TOOLBAR_SELECTOR = "[data-gloom-role=composite-chart-toolbar]";
350
+
351
+ /**
352
+ * Whether a pointer event lies on the bar. A mouseout between two of its icons
353
+ * does, and is no leaving. The desktop reads the bar's own box in px; the
354
+ * terminal compares its cells.
355
+ */
356
+ function pointerOnBar(bar: BoxRenderable | null, event: ChartMouseEvent): boolean {
357
+ const element = event.target?.closest?.(TOOLBAR_SELECTOR) as { getBoundingClientRect?: () => DOMRect } | null | undefined;
358
+ if (element?.getBoundingClientRect && typeof event.pixelX === "number" && typeof event.pixelY === "number") {
359
+ const box = element.getBoundingClientRect();
360
+ return event.pixelX >= box.left && event.pixelX < box.right && event.pixelY >= box.top && event.pixelY < box.bottom;
361
+ }
362
+ if (!bar || typeof event.x !== "number" || typeof event.y !== "number") return false;
363
+ const x = Number(bar.x);
364
+ const y = Number(bar.y);
365
+ return event.x >= x && event.x < x + Number(bar.width) && event.y >= y && event.y < y + Number(bar.height);
366
+ }
367
+
368
+ /**
369
+ * Whether the pointer or assistive focus has the bar open: the pointer opens it
370
+ * at once and keeps it open for a moment after it leaves the bar.
371
+ */
372
+ function useToolbarOpening(bar: { current: BoxRenderable | null }) {
373
+ const [hovered, setHovered] = useState(false);
374
+ const [focused, setFocused] = useState(false);
375
+ const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
376
+ const insideRef = useRef(false);
377
+ // Folded by a press under the pointer: it stays folded until the pointer has left the bar.
378
+ const foldedUnderPointerRef = useRef(false);
379
+ const clearTimer = useCallback(() => {
380
+ if (timerRef.current === null) return;
381
+ clearTimeout(timerRef.current);
382
+ timerRef.current = null;
383
+ }, []);
384
+ useEffect(() => clearTimer, [clearTimer]);
385
+ const onHover = useCallback(() => {
386
+ clearTimer();
387
+ insideRef.current = true;
388
+ if (!foldedUnderPointerRef.current) setHovered(true);
389
+ }, [clearTimer]);
390
+ const onLeave = useCallback((event: ChartMouseEvent) => {
391
+ // From one icon to the next, or into the gap between: still on the bar.
392
+ if (pointerOnBar(bar.current, event)) return;
393
+ clearTimer();
394
+ insideRef.current = false;
395
+ // Back within the delay, it opens: the press that folded it is over.
396
+ foldedUnderPointerRef.current = false;
397
+ timerRef.current = setTimeout(() => {
398
+ timerRef.current = null;
399
+ setHovered(false);
400
+ }, CHART_TOOLBAR_FOLD_DELAY_MS);
401
+ }, [bar, clearTimer]);
402
+ const fold = useCallback(() => {
403
+ foldedUnderPointerRef.current = insideRef.current;
404
+ setHovered(false);
405
+ setFocused(false);
406
+ }, []);
407
+ // A press focuses a button too; only focus that shows its ring (assistive technology's) opens the bar.
408
+ const onFocus = useCallback((event: { target?: unknown }) => {
409
+ const target = event.target as { matches?: (selector: string) => boolean } | null;
410
+ if (target?.matches?.(":focus-visible") === true) setFocused(true);
411
+ }, []);
412
+ const onBlur = useCallback((event: { currentTarget?: unknown; relatedTarget?: unknown }) => {
413
+ const root = event.currentTarget as { contains?: (node: unknown) => boolean } | null;
414
+ if (event.relatedTarget && root?.contains?.(event.relatedTarget)) return;
415
+ setFocused(false);
416
+ }, []);
417
+ return { open: hovered || focused, onHover, onLeave, onFocus, onBlur, fold };
418
+ }
@@ -64,8 +64,8 @@ export interface KeyboardToolDrag {
64
64
 
65
65
  /** The chart's own layout: its tool bar, its legend and its panels' heights. */
66
66
  export interface CompositeChartLayoutControls {
67
- /** The bar is saved hidden; it still opens while a tool is in hand. */
68
- toolbarHidden: boolean;
67
+ /** The bar is kept open; otherwise it folds to the tool in hand and opens under the pointer. */
68
+ toolbarPinned: boolean;
69
69
  toggleToolbar: () => void;
70
70
  /** The legend has more than one series, so it can fold to its first. */
71
71
  legendCollapsible: boolean;
@@ -728,8 +728,7 @@ export function useCompositeChartKeyboard({
728
728
  const levelToolKeys = toolsActive && armedTool === "level" && levelsEditable;
729
729
  const canDeleteLevel = toolsActive && levelsEditable && !!selectedLevel?.editable && !selectedLevel.draggable;
730
730
  const pinState = pin ? pin.pinned : null;
731
- // Hidden as it shows: a saved hidden bar is open while a tool is in hand.
732
- const toolbarHidden = layout.toolbarHidden && armedTool === null;
731
+ const toolbarPinned = layout.toolbarPinned;
733
732
  const {
734
733
  legendCollapsible,
735
734
  legendCollapsed,
@@ -811,7 +810,7 @@ export function useCompositeChartKeyboard({
811
810
  if (resettable) menu.push({ id: "chart-reset", label: "Reset Zoom", accelerator: "0", onSelect: () => chartActionsRef.current.reset() });
812
811
  menu.push({
813
812
  id: "chart-toolbar",
814
- label: toolbarHidden ? "Show Drawing Tools" : "Hide Drawing Tools",
813
+ label: toolbarPinned ? "Hide Drawing Tools" : "Show Drawing Tools",
815
814
  accelerator: "Shift+T",
816
815
  onSelect: () => chartActionsRef.current.layout.toggleToolbar(),
817
816
  });
@@ -860,7 +859,7 @@ export function useCompositeChartKeyboard({
860
859
  levelsEditable,
861
860
  toolsActive,
862
861
  pinState,
863
- toolbarHidden,
862
+ toolbarPinned,
864
863
  legendCollapsible,
865
864
  legendCollapsed,
866
865
  panelsResizable,
@@ -122,7 +122,9 @@ export class KittyImageManager {
122
122
  this.lastPlacementKeys = placements.map(serializePlacement);
123
123
  }
124
124
 
125
+ /** Deletes the image on screen, once: a chart hidden or covered every frame writes nothing more. */
125
126
  clear() {
127
+ if (this.activeSlot === null) return;
126
128
  writeRendererRaw(
127
129
  this.renderer,
128
130
  `${encodeKittyDeleteImage(this.imageIds[0])}${encodeKittyDeleteImage(this.imageIds[1])}`,