@opentui/core 0.5.8 → 0.5.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.
@@ -41,7 +41,7 @@ import {
41
41
  toArrayBuffer,
42
42
  treeSitterToTextChunks,
43
43
  yoga_default
44
- } from "./chunk-bun-2956gvaq.js";
44
+ } from "./chunk-bun-9gqvxy8c.js";
45
45
 
46
46
  // src/Renderable.ts
47
47
  import { EventEmitter } from "events";
@@ -1150,8 +1150,8 @@ class Renderable extends BaseRenderable {
1150
1150
  y: scissorRect.y,
1151
1151
  width: scissorRect.width,
1152
1152
  height: scissorRect.height,
1153
- screenX: this._screenX,
1154
- screenY: this._screenY
1153
+ screenX: this.buffered ? this._screenX : scissorRect.x,
1154
+ screenY: this.buffered ? this._screenY : scissorRect.y
1155
1155
  });
1156
1156
  }
1157
1157
  if (!this._hasVisibleChildFilter()) {
@@ -1869,6 +1869,14 @@ class EditBuffer extends EventEmitter2 {
1869
1869
  this.guard();
1870
1870
  return this.lib.textBufferGetLineCount(this.textBufferPtr);
1871
1871
  }
1872
+ setTabWidth(width) {
1873
+ this.guard();
1874
+ this.lib.editBufferSetTabWidth(this.bufferPtr, width);
1875
+ }
1876
+ getTabWidth() {
1877
+ this.guard();
1878
+ return this.lib.textBufferGetTabWidth(this.textBufferPtr);
1879
+ }
1872
1880
  getText() {
1873
1881
  this.guard();
1874
1882
  const maxSize = 1024 * 1024;
@@ -6778,6 +6786,7 @@ registerEnvVar({
6778
6786
  type: "boolean",
6779
6787
  default: false
6780
6788
  });
6789
+ var KITTY_IMAGE_TRANSPORTS = ["raw", "zlib", "file"];
6781
6790
  var DEFAULT_FOOTER_HEIGHT = 12;
6782
6791
  var MAX_SCROLLBACK_SURFACE_HEIGHT_PASSES = 4;
6783
6792
  var TRANSPARENT_RGBA = RGBA.fromValues(0, 0, 0, 0);
@@ -6923,6 +6932,7 @@ class ScrollbackSnapshotRenderContext extends EventEmitter5 {
6923
6932
  updateSelection(_currentRenderable, _x, _y, _options) {}
6924
6933
  }
6925
6934
  var DEFAULT_FORWARDED_ENV_KEYS = [
6935
+ "TMPDIR",
6926
6936
  "SSH_CONNECTION",
6927
6937
  "SSH_CLIENT",
6928
6938
  "SSH_TTY",
@@ -7136,6 +7146,7 @@ class CliRenderer extends EventEmitter5 {
7136
7146
  minTargetFrameTime = 1000 / this._maxFps;
7137
7147
  immediateRerenderRequested = false;
7138
7148
  updateScheduled = false;
7149
+ updateGeneration = 0;
7139
7150
  liveRequestCounter = 0;
7140
7151
  _controlState = "idle" /* IDLE */;
7141
7152
  frameCallbacks = [];
@@ -7158,6 +7169,8 @@ class CliRenderer extends EventEmitter5 {
7158
7169
  animationRequest = new Map;
7159
7170
  resizeTimeoutId = null;
7160
7171
  capabilityTimeoutId = null;
7172
+ kittyTransportTimer = null;
7173
+ kittyTransportMode;
7161
7174
  terminalKeepAliveTimer = null;
7162
7175
  xtVersionWaiters = new Set;
7163
7176
  splitStartupSeedTimeoutId = null;
@@ -7195,9 +7208,10 @@ class CliRenderer extends EventEmitter5 {
7195
7208
  realStdoutWrite;
7196
7209
  _useConsole = true;
7197
7210
  sigwinchHandler = (() => {
7198
- const width = this.stdout.columns || 80;
7199
- const height = this.stdout.rows || 24;
7200
- this.handleResize(width, height);
7211
+ const width = this.stdout.columns;
7212
+ const height = this.stdout.rows;
7213
+ if (width > 0 && height > 0)
7214
+ this.handleResize(width, height);
7201
7215
  }).bind(this);
7202
7216
  _capabilities = null;
7203
7217
  _latestPointer = { x: 0, y: 0 };
@@ -7287,8 +7301,7 @@ Captured external output:
7287
7301
  _detachFeed = null;
7288
7302
  _detachFeedError = null;
7289
7303
  feedIdleRenderScheduled = false;
7290
- ordinaryFrameWaitingForFeed = false;
7291
- ordinaryFrameWaitControlState = null;
7304
+ feedIdleWaitPending = false;
7292
7305
  get controlState() {
7293
7306
  return this._controlState;
7294
7307
  }
@@ -7304,6 +7317,10 @@ Captured external output:
7304
7317
  const { screenMode, footerHeight, externalOutputMode } = resolveModes(config);
7305
7318
  const initialGeometry = calculateRenderGeometry(screenMode, width, height, footerHeight);
7306
7319
  const remoteMode = config.remote ?? (useFeedOutput ? true : undefined);
7320
+ this.kittyTransportMode = config.kittyImageTransport ?? "raw";
7321
+ const transportCode = KITTY_IMAGE_TRANSPORTS.indexOf(this.kittyTransportMode);
7322
+ if (transportCode < 0)
7323
+ throw new TypeError("Invalid kittyImageTransport");
7307
7324
  if (rendererTracker.streamOwners.get(stdin)) {
7308
7325
  throw new Error("Cannot create CliRenderer: stdin is already used by another CliRenderer");
7309
7326
  }
@@ -7333,6 +7350,7 @@ Captured external output:
7333
7350
  feed?.close();
7334
7351
  throw new Error("Failed to create renderer");
7335
7352
  }
7353
+ lib.setKittyImageTransport(rendererPtr, transportCode);
7336
7354
  if (config.useThread === undefined)
7337
7355
  config.useThread = true;
7338
7356
  if (process.platform === "linux")
@@ -7349,6 +7367,8 @@ Captured external output:
7349
7367
  });
7350
7368
  });
7351
7369
  this._detachFeedError = feed.onError((code) => {
7370
+ if (this.kittyTransportTimer !== null)
7371
+ this.kittyOutputErrorHandler();
7352
7372
  console.error(`[CliRenderer] NativeSpanFeed error: code=${code}`);
7353
7373
  });
7354
7374
  }
@@ -7473,7 +7493,8 @@ Captured external output:
7473
7493
  return id;
7474
7494
  };
7475
7495
  global.cancelAnimationFrame = (handle) => {
7476
- this.animationRequest.delete(handle);
7496
+ if (this.animationRequest.delete(handle))
7497
+ this.dropLive();
7477
7498
  };
7478
7499
  const window = global.window;
7479
7500
  if (!window) {
@@ -7626,27 +7647,33 @@ Captured external output:
7626
7647
  }
7627
7648
  scheduleRenderAfterFeedIdle() {
7628
7649
  const feed = this._feed;
7629
- if (!feed || this.feedIdleRenderScheduled || this._isDestroyed)
7650
+ if (!feed || this._isDestroyed || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */)
7630
7651
  return;
7631
7652
  this.feedIdleRenderScheduled = true;
7653
+ if (this.feedIdleWaitPending)
7654
+ return;
7655
+ this.feedIdleWaitPending = true;
7632
7656
  feed.idle().then(() => {
7633
- this.feedIdleRenderScheduled = false;
7634
- const ordinaryFrameWasWaiting = this.ordinaryFrameWaitingForFeed;
7635
- const ordinaryFrameWaitControlState = this.ordinaryFrameWaitControlState;
7636
- this.ordinaryFrameWaitingForFeed = false;
7637
- this.ordinaryFrameWaitControlState = null;
7638
- if (this._isDestroyed || ordinaryFrameWasWaiting && this._controlState !== ordinaryFrameWaitControlState && (this._controlState === "explicit_paused" /* EXPLICIT_PAUSED */ || this._controlState === "explicit_stopped" /* EXPLICIT_STOPPED */ || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */)) {
7639
- this.resolveIdleIfNeeded();
7657
+ this.feedIdleWaitPending = false;
7658
+ if (!this.feedIdleRenderScheduled)
7659
+ return;
7660
+ if (feed.isBackpressured()) {
7661
+ this.scheduleRenderAfterFeedIdle();
7640
7662
  return;
7641
7663
  }
7664
+ this.feedIdleRenderScheduled = false;
7642
7665
  this.scheduleRenderTimer();
7643
7666
  this.resolveIdleIfNeeded();
7644
7667
  });
7645
7668
  }
7669
+ cancelRenderAfterFeedIdle() {
7670
+ if (!this.feedIdleRenderScheduled)
7671
+ return;
7672
+ this.feedIdleRenderScheduled = false;
7673
+ this.immediateRerenderRequested = false;
7674
+ }
7646
7675
  handleNativeRenderRejection(status) {
7647
7676
  if (status === NATIVE_RENDER_STATUS_SKIPPED && this._feed) {
7648
- this.ordinaryFrameWaitingForFeed = true;
7649
- this.ordinaryFrameWaitControlState = this._controlState;
7650
7677
  this.scheduleRenderAfterFeedIdle();
7651
7678
  return "retryable-skip";
7652
7679
  }
@@ -7688,39 +7715,38 @@ Captured external output:
7688
7715
  return;
7689
7716
  }
7690
7717
  if (this._isRunning) {
7691
- if (!this.rendering && !this.renderTimeout && !this.ordinaryFrameWaitingForFeed) {
7718
+ if (!this.rendering && !this.renderTimeout) {
7692
7719
  this.scheduleRenderTimer();
7693
7720
  }
7694
7721
  return;
7695
7722
  }
7696
- if (this.ordinaryFrameWaitingForFeed) {
7697
- return;
7698
- }
7699
7723
  if (this.rendering) {
7700
7724
  this.immediateRerenderRequested = true;
7701
7725
  return;
7702
7726
  }
7703
7727
  if (!this.updateScheduled && !this.renderTimeout) {
7704
7728
  this.updateScheduled = true;
7729
+ const generation = ++this.updateGeneration;
7705
7730
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
7706
7731
  const elapsed = this.getElapsedMs(now, this.lastTime);
7707
7732
  const delay = Math.max(this.minTargetFrameTime - elapsed, 0);
7708
7733
  if (delay === 0) {
7709
- process.nextTick(() => this.activateFrame());
7734
+ process.nextTick(() => this.activateFrame(generation));
7710
7735
  return;
7711
7736
  }
7712
- this.clock.setTimeout(() => this.activateFrame(), delay);
7737
+ this.clock.setTimeout(() => this.activateFrame(generation), delay);
7713
7738
  }
7714
7739
  }
7715
- async activateFrame() {
7716
- if (!this.updateScheduled) {
7740
+ async activateFrame(generation) {
7741
+ if (generation !== this.updateGeneration || !this.updateScheduled) {
7717
7742
  this.resolveIdleIfNeeded();
7718
7743
  return;
7719
7744
  }
7720
7745
  try {
7721
7746
  await this.loop();
7722
7747
  } finally {
7723
- this.updateScheduled = false;
7748
+ if (generation === this.updateGeneration)
7749
+ this.updateScheduled = false;
7724
7750
  this.resolveIdleIfNeeded();
7725
7751
  }
7726
7752
  }
@@ -7939,6 +7965,50 @@ Captured external output:
7939
7965
  get capabilities() {
7940
7966
  return this._capabilities;
7941
7967
  }
7968
+ get kittyImageTransport() {
7969
+ return this.kittyTransportMode;
7970
+ }
7971
+ set kittyImageTransport(mode) {
7972
+ const code = KITTY_IMAGE_TRANSPORTS.indexOf(mode);
7973
+ if (code < 0)
7974
+ throw new TypeError("Invalid kittyImageTransport");
7975
+ if (this._isDestroyed || mode === this.kittyTransportMode)
7976
+ return;
7977
+ this.kittyTransportMode = mode;
7978
+ this.startKittyTransportPolling();
7979
+ this.lib.setKittyImageTransport(this.rendererPtr, code);
7980
+ this.requestRender();
7981
+ }
7982
+ startKittyTransportPolling() {
7983
+ if (!this._terminalIsSetup || this.kittyTransportMode !== "file" || this.kittyTransportTimer !== null)
7984
+ return;
7985
+ this.stdout.on("error", this.kittyOutputErrorHandler);
7986
+ this.kittyTransportTimer = this.clock.setInterval(() => {
7987
+ if (!this._isDestroyed && this.lib.pollKittyImageTransport(this.rendererPtr))
7988
+ this.requestRender();
7989
+ }, 1000);
7990
+ }
7991
+ get kittyImageTransportStatus() {
7992
+ const [mode, effective, fileState, fallback, pendingFiles, pendingBytes] = this.lib.getKittyImageTransport(this.rendererPtr);
7993
+ return {
7994
+ requested: KITTY_IMAGE_TRANSPORTS[mode],
7995
+ effective: ["raw", "zlib", "png", "file"][effective],
7996
+ fileState: ["disabled", "probing", "ready", "unsupported", "timeout", "io-error", "cancelled"][fileState],
7997
+ fallback: ["none", "not-ready", "unavailable", "budget", "busy", "preparation", "compression"][fallback],
7998
+ pendingFiles,
7999
+ pendingBytes
8000
+ };
8001
+ }
8002
+ cancelKittyImageTransport() {
8003
+ if (this._isDestroyed)
8004
+ return;
8005
+ this.lib.cancelKittyImageTransport(this.rendererPtr, false);
8006
+ this.requestRender();
8007
+ }
8008
+ kittyOutputErrorHandler = () => {
8009
+ if (!this._isDestroyed)
8010
+ this.lib.cancelKittyImageTransport(this.rendererPtr, true);
8011
+ };
7942
8012
  triggerNotification(message, title) {
7943
8013
  if (this._isDestroyed)
7944
8014
  return false;
@@ -8500,7 +8570,7 @@ Captured external output:
8500
8570
  const forceCommit = forceFooterRepaint && index === lastCommitIndex;
8501
8571
  const beginFrame = index === 0;
8502
8572
  const finalizeFrame = index === lastCommitIndex;
8503
- const nativeResult = this.lib.commitSplitFooterSnapshot(this.rendererPtr, commit.snapshot, commit.rowColumns, commit.startOnNewLine, commit.trailingNewline, this.getSplitPinnedRenderOffset(), forceCommit, beginFrame, finalizeFrame);
8573
+ const nativeResult = this.lib.commitSplitFooterSnapshot(this.rendererPtr, commit.snapshot, commit.rowColumns, commit.startOnNewLine, commit.trailingNewline, this.getSplitPinnedRenderOffset(), forceCommit, beginFrame, finalizeFrame, drainAll);
8504
8574
  if (nativeResult.status === NATIVE_RENDER_STATUS_SKIPPED) {
8505
8575
  nativeBackpressured = true;
8506
8576
  break;
@@ -8841,6 +8911,7 @@ Captured external output:
8841
8911
  explicitWidthCprActive: true,
8842
8912
  startupCursorCprActive
8843
8913
  });
8914
+ this.startKittyTransportPolling();
8844
8915
  this.lib.setupTerminal(this.rendererPtr, this._screenMode === "alternate-screen");
8845
8916
  this._capabilities = this.lib.getTerminalCapabilities(this.rendererPtr);
8846
8917
  if (this.debugOverlay.enabled) {
@@ -9006,6 +9077,14 @@ Captured external output:
9006
9077
  });
9007
9078
  }
9008
9079
  handleStdinEvent(event) {
9080
+ if (event.type === "response" && event.sequence.startsWith("\x1B_G")) {
9081
+ const result = this.lib.processKittyImageReply(this.rendererPtr, event.sequence);
9082
+ if (result !== 0) {
9083
+ if (result === 2)
9084
+ this.requestRender();
9085
+ return;
9086
+ }
9087
+ }
9009
9088
  if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
9010
9089
  if (event.type === "response" && isPixelResolutionResponse(event.sequence)) {
9011
9090
  this.dispatchSequenceHandlers(event.sequence);
@@ -9504,13 +9583,21 @@ Captured external output:
9504
9583
  if (this._controlState === "idle" /* IDLE */ && this.liveRequestCounter > 0) {
9505
9584
  this._controlState = "auto_started" /* AUTO_STARTED */;
9506
9585
  this.internalStart();
9586
+ } else if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */ && this._previousControlState === "idle" /* IDLE */) {
9587
+ this._previousControlState = "auto_started" /* AUTO_STARTED */;
9507
9588
  }
9508
9589
  }
9509
9590
  dropLive() {
9510
- this.liveRequestCounter = Math.max(0, this.liveRequestCounter - 1);
9591
+ if (this.liveRequestCounter === 0)
9592
+ return;
9593
+ this.liveRequestCounter--;
9594
+ if (this.liveRequestCounter === 0 && this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */ && this._previousControlState === "auto_started" /* AUTO_STARTED */) {
9595
+ this._previousControlState = "idle" /* IDLE */;
9596
+ }
9511
9597
  if (this._controlState === "auto_started" /* AUTO_STARTED */ && this.liveRequestCounter === 0) {
9512
9598
  this._controlState = "idle" /* IDLE */;
9513
- this.internalPause();
9599
+ this._isRunning = false;
9600
+ this.resolveIdleIfNeeded();
9514
9601
  }
9515
9602
  }
9516
9603
  start() {
@@ -9524,6 +9611,7 @@ Captured external output:
9524
9611
  if (!this._isRunning && !this._isDestroyed) {
9525
9612
  this._isRunning = true;
9526
9613
  this.updateScheduled = false;
9614
+ this.updateGeneration++;
9527
9615
  if (this.memorySnapshotInterval > 0) {
9528
9616
  this.startMemorySnapshotTimer();
9529
9617
  }
@@ -9538,6 +9626,7 @@ Captured external output:
9538
9626
  this._previousControlState = this._controlState;
9539
9627
  this._controlState = "explicit_suspended" /* EXPLICIT_SUSPENDED */;
9540
9628
  this.updateScheduled = false;
9629
+ this.updateGeneration++;
9541
9630
  this.internalPause();
9542
9631
  if (this._terminalIsSetup) {
9543
9632
  this.clearSplitStartupCursorSeed();
@@ -9615,6 +9704,7 @@ Captured external output:
9615
9704
  }
9616
9705
  internalPause() {
9617
9706
  this._isRunning = false;
9707
+ this.cancelRenderAfterFeedIdle();
9618
9708
  if (this.renderTimeout) {
9619
9709
  this.clock.clearTimeout(this.renderTimeout);
9620
9710
  this.renderTimeout = null;
@@ -9628,20 +9718,14 @@ Captured external output:
9628
9718
  this.internalStop();
9629
9719
  }
9630
9720
  internalStop() {
9631
- if (this.isRunning && !this._isDestroyed) {
9632
- this._isRunning = false;
9633
- if (this.memorySnapshotTimer) {
9634
- this.clock.clearInterval(this.memorySnapshotTimer);
9635
- this.memorySnapshotTimer = null;
9636
- }
9637
- if (this.renderTimeout) {
9638
- this.clock.clearTimeout(this.renderTimeout);
9639
- this.renderTimeout = null;
9640
- }
9641
- if (!this.rendering) {
9642
- this.resolveIdleIfNeeded();
9643
- }
9721
+ this.updateScheduled = false;
9722
+ this.updateGeneration++;
9723
+ this.immediateRerenderRequested = false;
9724
+ if (this.memorySnapshotTimer) {
9725
+ this.clock.clearInterval(this.memorySnapshotTimer);
9726
+ this.memorySnapshotTimer = null;
9644
9727
  }
9728
+ this.internalPause();
9645
9729
  }
9646
9730
  destroy() {
9647
9731
  if (this._isDestroyed)
@@ -9659,6 +9743,13 @@ Captured external output:
9659
9743
  if (this._destroyCleanupPrepared)
9660
9744
  return;
9661
9745
  this._destroyCleanupPrepared = true;
9746
+ this.cancelRenderAfterFeedIdle();
9747
+ if (this.kittyTransportTimer !== null) {
9748
+ this.clock.clearInterval(this.kittyTransportTimer);
9749
+ this.kittyTransportTimer = null;
9750
+ this.stdout.off("error", this.kittyOutputErrorHandler);
9751
+ this.lib.cancelKittyImageTransport(this.rendererPtr, false);
9752
+ }
9662
9753
  if (this._usesProcessStdout) {
9663
9754
  process.removeListener("SIGWINCH", this.sigwinchHandler);
9664
9755
  }
@@ -9830,6 +9921,7 @@ Captured external output:
9830
9921
  async loop() {
9831
9922
  if (this.rendering || this._isDestroyed)
9832
9923
  return;
9924
+ const startedWhileRunning = this._isRunning;
9833
9925
  if (this.renderTimeout) {
9834
9926
  this.clock.clearTimeout(this.renderTimeout);
9835
9927
  this.renderTimeout = null;
@@ -9837,6 +9929,11 @@ Captured external output:
9837
9929
  this.rendering = true;
9838
9930
  let renderFailed = false;
9839
9931
  try {
9932
+ if (this._feed?.isBackpressured()) {
9933
+ this.handleNativeRenderRejection(NATIVE_RENDER_STATUS_SKIPPED);
9934
+ this.immediateRerenderRequested = false;
9935
+ return;
9936
+ }
9840
9937
  this._frameId++;
9841
9938
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
9842
9939
  const elapsed = this.getElapsedMs(now, this.lastTime);
@@ -9919,7 +10016,9 @@ Captured external output:
9919
10016
  this.renderTimeout = null;
9920
10017
  }
9921
10018
  } else if (nativeStatus === "backpressured") {
9922
- this.scheduleRenderAfterBackpressure();
10019
+ if (!startedWhileRunning || this._isRunning || this.immediateRerenderRequested || this._controlState === "idle" /* IDLE */) {
10020
+ this.scheduleRenderAfterBackpressure();
10021
+ }
9923
10022
  } else if (nativeStatus === "retryable-skip") {
9924
10023
  this.immediateRerenderRequested = false;
9925
10024
  this.renderTimeout = null;
@@ -10309,5 +10408,5 @@ Captured external output:
10309
10408
 
10310
10409
  export { h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, TextBufferView, EditBuffer, EditorView, convertThemeToStyles, SyntaxStyle, ANSI, BoxRenderable, TextBufferRenderable, CodeRenderable, isTextNodeRenderable, TextNodeRenderable, RootTextNodeRenderable, TextRenderable, NativeSpanFeed, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, EditBufferRenderableEvents, isEditBufferRenderable, EditBufferRenderable, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
10311
10410
 
10312
- //# debugId=9482A117F731D7E464756E2164756E21
10313
- //# sourceMappingURL=chunk-bun-b3exa82d.js.map
10411
+ //# debugId=2464034E49CDB83B64756E2164756E21
10412
+ //# sourceMappingURL=chunk-bun-bb3k0yt8.js.map