@valyrianjs/terminal 0.2.3 → 0.2.4

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.
package/src/session.ts CHANGED
@@ -52,7 +52,7 @@ interface ResolvedRuntimeOptions {
52
52
  stdout?: TerminalOutputStream;
53
53
  alternateScreen: boolean;
54
54
  hideCursor: boolean;
55
- mouseReporting: boolean;
55
+ mouseInput: boolean;
56
56
  writesAnsi: boolean;
57
57
  }
58
58
 
@@ -88,6 +88,7 @@ const KNOWN_TERMINAL_KEY_SEQUENCES = [
88
88
  const ESCAPE = "\u001b";
89
89
  const CSI_PREFIX = "\u001b[";
90
90
  const DOUBLE_PRESS_INTERVAL_MS = 500;
91
+ const MODAL_OVERLAY_HITBOX_ID = "\u0000valyrian-overlay-modal-shield";
91
92
 
92
93
  function isBracketedPasteStartPrefix(value: string) {
93
94
  return value.length > 0 && value.length < BRACKETED_PASTE_START.length && BRACKETED_PASTE_START.startsWith(value);
@@ -148,6 +149,21 @@ function isValidTerminalDimension(value: number | undefined): value is number {
148
149
  return Number.isInteger(value) && Number(value) >= 1;
149
150
  }
150
151
 
152
+ function isModalOverlayShieldHitbox(hitbox: TerminalHitbox | null | undefined) {
153
+ return hitbox?.id === MODAL_OVERLAY_HITBOX_ID;
154
+ }
155
+
156
+ function hitboxIsAboveModalShield(hitboxes: TerminalHitbox[], id: string) {
157
+ const shieldIndex = hitboxes.findIndex((box) => isModalOverlayShieldHitbox(box));
158
+ if (shieldIndex < 0) {
159
+ return true;
160
+ }
161
+
162
+ const hitboxIndex = hitboxes.findIndex((box) => box.id === id);
163
+ return hitboxIndex >= 0 && hitboxIndex < shieldIndex;
164
+ }
165
+
166
+
151
167
  function getProcessStdin(): TerminalInputStream | undefined {
152
168
  const candidate = globalThis.process?.stdin as TerminalInputStream | undefined;
153
169
  return candidate && typeof candidate.on === "function" ? candidate : undefined;
@@ -177,7 +193,7 @@ function resolveRuntimeOptions(options: TerminalMountOptions): ResolvedRuntimeOp
177
193
  stdout,
178
194
  alternateScreen: options.alternateScreen ?? ownsInteractiveTTY,
179
195
  hideCursor: options.hideCursor ?? ownsInteractiveTTY,
180
- mouseReporting: ownsInteractiveTTY,
196
+ mouseInput: ownsInteractiveTTY,
181
197
  writesAnsi: runtime === "app" && Boolean(stdout)
182
198
  };
183
199
  }
@@ -339,7 +355,7 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
339
355
  if (runtimeOptions.hideCursor) {
340
356
  writes.push(ANSI_HIDE_CURSOR);
341
357
  }
342
- if (runtimeOptions.mouseReporting) {
358
+ if (runtimeOptions.mouseInput) {
343
359
  writes.push(ANSI_ENABLE_MOUSE_REPORTING);
344
360
  }
345
361
  if (writes.length > 0) {
@@ -352,7 +368,7 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
352
368
  return;
353
369
  }
354
370
  const writes: string[] = [];
355
- if (runtimeOptions.mouseReporting) {
371
+ if (runtimeOptions.mouseInput) {
356
372
  writes.push(ANSI_DISABLE_MOUSE_REPORTING);
357
373
  }
358
374
  if (runtimeOptions.hideCursor) {
@@ -863,11 +879,19 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
863
879
 
864
880
  function hoverAt(x: number, y: number) {
865
881
  const hitbox = resolvePointerTarget(currentHitboxes, x, y);
866
- if (!hitbox) {
867
- if (pointerCaptureId) {
882
+ if (!hitbox || isModalOverlayShieldHitbox(hitbox)) {
883
+ if (pointerCaptureId && (!hitbox || hitboxIsAboveModalShield(currentHitboxes, pointerCaptureId))) {
868
884
  setSemanticHoverFromHitbox(pointerCaptureId, x, y);
869
885
  return rerender();
870
886
  }
887
+ if (pointerCaptureId) {
888
+ const capturedHitbox = currentHitboxes.find((box) => box.id === pointerCaptureId);
889
+ const capturedNode = findFocusableById(currentTree, pointerCaptureId);
890
+ const capturedRow = capturedHitbox && capturedNode
891
+ ? sourceRowFromHitbox(capturedNode, capturedHitbox, y)
892
+ : hoveredRowForNode(capturedNode);
893
+ setPointerCapture(null, "drag", capturedRow, x, y);
894
+ }
871
895
  clearSemanticHover(undefined, x, y);
872
896
  return rerender();
873
897
  }
@@ -969,7 +993,7 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
969
993
 
970
994
  function wheelAt(x: number, y: number, direction: -1 | 1) {
971
995
  const hitbox = resolvePointerTarget(currentHitboxes, x, y);
972
- if (!hitbox) {
996
+ if (!hitbox || isModalOverlayShieldHitbox(hitbox)) {
973
997
  return currentOutput;
974
998
  }
975
999
 
@@ -1237,7 +1261,7 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
1237
1261
  },
1238
1262
  focusAt(x: number, y: number) {
1239
1263
  const hitbox = resolvePointerTarget(currentHitboxes, x, y);
1240
- if (!hitbox) {
1264
+ if (!hitbox || isModalOverlayShieldHitbox(hitbox)) {
1241
1265
  clearSemanticHover(undefined, x, y);
1242
1266
  return false;
1243
1267
  }
@@ -1297,7 +1321,7 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
1297
1321
  },
1298
1322
  clickAt(x: number, y: number) {
1299
1323
  const hitbox = resolvePointerTarget(currentHitboxes, x, y);
1300
- if (!hitbox) {
1324
+ if (!hitbox || isModalOverlayShieldHitbox(hitbox)) {
1301
1325
  clearSemanticHover(undefined, x, y);
1302
1326
  return currentOutput;
1303
1327
  }
@@ -1512,7 +1536,7 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
1512
1536
 
1513
1537
  function contextPressAt(x: number, y: number) {
1514
1538
  const hitbox = resolvePointerTarget(currentHitboxes, x, y);
1515
- if (!hitbox) {
1539
+ if (!hitbox || isModalOverlayShieldHitbox(hitbox)) {
1516
1540
  clearSemanticHover(undefined, x, y);
1517
1541
  return currentOutput;
1518
1542
  }
@@ -1584,7 +1608,12 @@ export function mountTerminal(input: any, options: TerminalMountOptions = {}): T
1584
1608
  }
1585
1609
  } else if (parsed.action === "drag") {
1586
1610
  if (mouseSelectionId) {
1587
- setCursorFromHitbox(mouseSelectionId, parsed.x, true);
1611
+ if (!hitboxIsAboveModalShield(currentHitboxes, mouseSelectionId)) {
1612
+ mouseSelectionId = null;
1613
+ hoverAt(parsed.x, parsed.y);
1614
+ } else {
1615
+ setCursorFromHitbox(mouseSelectionId, parsed.x, true);
1616
+ }
1588
1617
  } else {
1589
1618
  hoverAt(parsed.x, parsed.y);
1590
1619
  }
package/src/theme.ts CHANGED
@@ -80,7 +80,7 @@ export const defaultTerminalTheme: TerminalTheme = {
80
80
  list: { base: { color: "#d8dee9" }, selected: { color: "#ffffff", background: "#2e3440" }, current: { color: "#ffffff", background: "#3b4252" }, hover: { color: "#ffffff", background: "#2b3137" }, empty: { color: "#777777" }, expanded: { color: "#b48ead" }, collapsed: { color: "#81a1c1" } },
81
81
  scroll: { base: { color: "#d8dee9" }, hover: { color: "#dddddd" } },
82
82
  log: { base: { color: "#d8dee9" }, empty: { color: "#777777" }, error: { color: "#bf616a" }, warning: { color: "#ebcb8b" }, success: { color: "#a3be8c" }, muted: { color: "#777777" } },
83
- overlay: { base: { background: "#111111" }, dragging: { color: "#b48ead" }, dropTarget: { background: "#243b53" }, capturing: { color: "#d08770" } },
83
+ overlay: { base: { background: "#111111" }, backdrop: { background: "#000000" }, dragging: { color: "#b48ead" }, dropTarget: { background: "#243b53" }, capturing: { color: "#d08770" } },
84
84
  pane: {
85
85
  header: { background: "#3a3a3a", color: "#ffffff" },
86
86
  transcript: { background: "#303030", color: "#dddddd" },
@@ -107,6 +107,9 @@ export const defaultTerminalTheme: TerminalTheme = {
107
107
  focus: {
108
108
  background: "#1f2328"
109
109
  },
110
+ "editor.focus": {
111
+ background: "#161b22"
112
+ },
110
113
  "current-row": reverseVideoToken,
111
114
  hover: {
112
115
  ansiOpen: "\u001b[4m",
package/src/types.ts CHANGED
@@ -505,6 +505,7 @@ export interface TerminalOverlayMarginAxes {
505
505
  export interface TerminalOverlayProps extends TerminalFocusableProps, TerminalStyleProps {
506
506
  margin: TerminalOverlayMarginValue | TerminalOverlayMarginAxes;
507
507
  trapFocus?: boolean;
508
+ backdrop?: boolean | TerminalStyleValue;
508
509
  }
509
510
 
510
511
  export interface TerminalFocusScopeProps {