@opentui/core 0.5.9 → 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-b0662dgp.js";
44
+ } from "./chunk-bun-9gqvxy8c.js";
45
45
 
46
46
  // src/Renderable.ts
47
47
  import { EventEmitter } from "events";
@@ -6786,6 +6786,7 @@ registerEnvVar({
6786
6786
  type: "boolean",
6787
6787
  default: false
6788
6788
  });
6789
+ var KITTY_IMAGE_TRANSPORTS = ["raw", "zlib", "file"];
6789
6790
  var DEFAULT_FOOTER_HEIGHT = 12;
6790
6791
  var MAX_SCROLLBACK_SURFACE_HEIGHT_PASSES = 4;
6791
6792
  var TRANSPARENT_RGBA = RGBA.fromValues(0, 0, 0, 0);
@@ -6931,6 +6932,7 @@ class ScrollbackSnapshotRenderContext extends EventEmitter5 {
6931
6932
  updateSelection(_currentRenderable, _x, _y, _options) {}
6932
6933
  }
6933
6934
  var DEFAULT_FORWARDED_ENV_KEYS = [
6935
+ "TMPDIR",
6934
6936
  "SSH_CONNECTION",
6935
6937
  "SSH_CLIENT",
6936
6938
  "SSH_TTY",
@@ -7144,6 +7146,7 @@ class CliRenderer extends EventEmitter5 {
7144
7146
  minTargetFrameTime = 1000 / this._maxFps;
7145
7147
  immediateRerenderRequested = false;
7146
7148
  updateScheduled = false;
7149
+ updateGeneration = 0;
7147
7150
  liveRequestCounter = 0;
7148
7151
  _controlState = "idle" /* IDLE */;
7149
7152
  frameCallbacks = [];
@@ -7166,6 +7169,8 @@ class CliRenderer extends EventEmitter5 {
7166
7169
  animationRequest = new Map;
7167
7170
  resizeTimeoutId = null;
7168
7171
  capabilityTimeoutId = null;
7172
+ kittyTransportTimer = null;
7173
+ kittyTransportMode;
7169
7174
  terminalKeepAliveTimer = null;
7170
7175
  xtVersionWaiters = new Set;
7171
7176
  splitStartupSeedTimeoutId = null;
@@ -7296,8 +7301,7 @@ Captured external output:
7296
7301
  _detachFeed = null;
7297
7302
  _detachFeedError = null;
7298
7303
  feedIdleRenderScheduled = false;
7299
- ordinaryFrameWaitingForFeed = false;
7300
- ordinaryFrameWaitControlState = null;
7304
+ feedIdleWaitPending = false;
7301
7305
  get controlState() {
7302
7306
  return this._controlState;
7303
7307
  }
@@ -7313,6 +7317,10 @@ Captured external output:
7313
7317
  const { screenMode, footerHeight, externalOutputMode } = resolveModes(config);
7314
7318
  const initialGeometry = calculateRenderGeometry(screenMode, width, height, footerHeight);
7315
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");
7316
7324
  if (rendererTracker.streamOwners.get(stdin)) {
7317
7325
  throw new Error("Cannot create CliRenderer: stdin is already used by another CliRenderer");
7318
7326
  }
@@ -7342,6 +7350,7 @@ Captured external output:
7342
7350
  feed?.close();
7343
7351
  throw new Error("Failed to create renderer");
7344
7352
  }
7353
+ lib.setKittyImageTransport(rendererPtr, transportCode);
7345
7354
  if (config.useThread === undefined)
7346
7355
  config.useThread = true;
7347
7356
  if (process.platform === "linux")
@@ -7358,6 +7367,8 @@ Captured external output:
7358
7367
  });
7359
7368
  });
7360
7369
  this._detachFeedError = feed.onError((code) => {
7370
+ if (this.kittyTransportTimer !== null)
7371
+ this.kittyOutputErrorHandler();
7361
7372
  console.error(`[CliRenderer] NativeSpanFeed error: code=${code}`);
7362
7373
  });
7363
7374
  }
@@ -7482,7 +7493,8 @@ Captured external output:
7482
7493
  return id;
7483
7494
  };
7484
7495
  global.cancelAnimationFrame = (handle) => {
7485
- this.animationRequest.delete(handle);
7496
+ if (this.animationRequest.delete(handle))
7497
+ this.dropLive();
7486
7498
  };
7487
7499
  const window = global.window;
7488
7500
  if (!window) {
@@ -7635,27 +7647,33 @@ Captured external output:
7635
7647
  }
7636
7648
  scheduleRenderAfterFeedIdle() {
7637
7649
  const feed = this._feed;
7638
- if (!feed || this.feedIdleRenderScheduled || this._isDestroyed)
7650
+ if (!feed || this._isDestroyed || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */)
7639
7651
  return;
7640
7652
  this.feedIdleRenderScheduled = true;
7653
+ if (this.feedIdleWaitPending)
7654
+ return;
7655
+ this.feedIdleWaitPending = true;
7641
7656
  feed.idle().then(() => {
7642
- this.feedIdleRenderScheduled = false;
7643
- const ordinaryFrameWasWaiting = this.ordinaryFrameWaitingForFeed;
7644
- const ordinaryFrameWaitControlState = this.ordinaryFrameWaitControlState;
7645
- this.ordinaryFrameWaitingForFeed = false;
7646
- this.ordinaryFrameWaitControlState = null;
7647
- 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 */)) {
7648
- this.resolveIdleIfNeeded();
7657
+ this.feedIdleWaitPending = false;
7658
+ if (!this.feedIdleRenderScheduled)
7659
+ return;
7660
+ if (feed.isBackpressured()) {
7661
+ this.scheduleRenderAfterFeedIdle();
7649
7662
  return;
7650
7663
  }
7664
+ this.feedIdleRenderScheduled = false;
7651
7665
  this.scheduleRenderTimer();
7652
7666
  this.resolveIdleIfNeeded();
7653
7667
  });
7654
7668
  }
7669
+ cancelRenderAfterFeedIdle() {
7670
+ if (!this.feedIdleRenderScheduled)
7671
+ return;
7672
+ this.feedIdleRenderScheduled = false;
7673
+ this.immediateRerenderRequested = false;
7674
+ }
7655
7675
  handleNativeRenderRejection(status) {
7656
7676
  if (status === NATIVE_RENDER_STATUS_SKIPPED && this._feed) {
7657
- this.ordinaryFrameWaitingForFeed = true;
7658
- this.ordinaryFrameWaitControlState = this._controlState;
7659
7677
  this.scheduleRenderAfterFeedIdle();
7660
7678
  return "retryable-skip";
7661
7679
  }
@@ -7697,39 +7715,38 @@ Captured external output:
7697
7715
  return;
7698
7716
  }
7699
7717
  if (this._isRunning) {
7700
- if (!this.rendering && !this.renderTimeout && !this.ordinaryFrameWaitingForFeed) {
7718
+ if (!this.rendering && !this.renderTimeout) {
7701
7719
  this.scheduleRenderTimer();
7702
7720
  }
7703
7721
  return;
7704
7722
  }
7705
- if (this.ordinaryFrameWaitingForFeed) {
7706
- return;
7707
- }
7708
7723
  if (this.rendering) {
7709
7724
  this.immediateRerenderRequested = true;
7710
7725
  return;
7711
7726
  }
7712
7727
  if (!this.updateScheduled && !this.renderTimeout) {
7713
7728
  this.updateScheduled = true;
7729
+ const generation = ++this.updateGeneration;
7714
7730
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
7715
7731
  const elapsed = this.getElapsedMs(now, this.lastTime);
7716
7732
  const delay = Math.max(this.minTargetFrameTime - elapsed, 0);
7717
7733
  if (delay === 0) {
7718
- process.nextTick(() => this.activateFrame());
7734
+ process.nextTick(() => this.activateFrame(generation));
7719
7735
  return;
7720
7736
  }
7721
- this.clock.setTimeout(() => this.activateFrame(), delay);
7737
+ this.clock.setTimeout(() => this.activateFrame(generation), delay);
7722
7738
  }
7723
7739
  }
7724
- async activateFrame() {
7725
- if (!this.updateScheduled) {
7740
+ async activateFrame(generation) {
7741
+ if (generation !== this.updateGeneration || !this.updateScheduled) {
7726
7742
  this.resolveIdleIfNeeded();
7727
7743
  return;
7728
7744
  }
7729
7745
  try {
7730
7746
  await this.loop();
7731
7747
  } finally {
7732
- this.updateScheduled = false;
7748
+ if (generation === this.updateGeneration)
7749
+ this.updateScheduled = false;
7733
7750
  this.resolveIdleIfNeeded();
7734
7751
  }
7735
7752
  }
@@ -7948,6 +7965,50 @@ Captured external output:
7948
7965
  get capabilities() {
7949
7966
  return this._capabilities;
7950
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
+ };
7951
8012
  triggerNotification(message, title) {
7952
8013
  if (this._isDestroyed)
7953
8014
  return false;
@@ -8509,7 +8570,7 @@ Captured external output:
8509
8570
  const forceCommit = forceFooterRepaint && index === lastCommitIndex;
8510
8571
  const beginFrame = index === 0;
8511
8572
  const finalizeFrame = index === lastCommitIndex;
8512
- 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);
8513
8574
  if (nativeResult.status === NATIVE_RENDER_STATUS_SKIPPED) {
8514
8575
  nativeBackpressured = true;
8515
8576
  break;
@@ -8850,6 +8911,7 @@ Captured external output:
8850
8911
  explicitWidthCprActive: true,
8851
8912
  startupCursorCprActive
8852
8913
  });
8914
+ this.startKittyTransportPolling();
8853
8915
  this.lib.setupTerminal(this.rendererPtr, this._screenMode === "alternate-screen");
8854
8916
  this._capabilities = this.lib.getTerminalCapabilities(this.rendererPtr);
8855
8917
  if (this.debugOverlay.enabled) {
@@ -9015,6 +9077,14 @@ Captured external output:
9015
9077
  });
9016
9078
  }
9017
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
+ }
9018
9088
  if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
9019
9089
  if (event.type === "response" && isPixelResolutionResponse(event.sequence)) {
9020
9090
  this.dispatchSequenceHandlers(event.sequence);
@@ -9513,13 +9583,21 @@ Captured external output:
9513
9583
  if (this._controlState === "idle" /* IDLE */ && this.liveRequestCounter > 0) {
9514
9584
  this._controlState = "auto_started" /* AUTO_STARTED */;
9515
9585
  this.internalStart();
9586
+ } else if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */ && this._previousControlState === "idle" /* IDLE */) {
9587
+ this._previousControlState = "auto_started" /* AUTO_STARTED */;
9516
9588
  }
9517
9589
  }
9518
9590
  dropLive() {
9519
- 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
+ }
9520
9597
  if (this._controlState === "auto_started" /* AUTO_STARTED */ && this.liveRequestCounter === 0) {
9521
9598
  this._controlState = "idle" /* IDLE */;
9522
- this.internalPause();
9599
+ this._isRunning = false;
9600
+ this.resolveIdleIfNeeded();
9523
9601
  }
9524
9602
  }
9525
9603
  start() {
@@ -9533,6 +9611,7 @@ Captured external output:
9533
9611
  if (!this._isRunning && !this._isDestroyed) {
9534
9612
  this._isRunning = true;
9535
9613
  this.updateScheduled = false;
9614
+ this.updateGeneration++;
9536
9615
  if (this.memorySnapshotInterval > 0) {
9537
9616
  this.startMemorySnapshotTimer();
9538
9617
  }
@@ -9547,6 +9626,7 @@ Captured external output:
9547
9626
  this._previousControlState = this._controlState;
9548
9627
  this._controlState = "explicit_suspended" /* EXPLICIT_SUSPENDED */;
9549
9628
  this.updateScheduled = false;
9629
+ this.updateGeneration++;
9550
9630
  this.internalPause();
9551
9631
  if (this._terminalIsSetup) {
9552
9632
  this.clearSplitStartupCursorSeed();
@@ -9624,6 +9704,7 @@ Captured external output:
9624
9704
  }
9625
9705
  internalPause() {
9626
9706
  this._isRunning = false;
9707
+ this.cancelRenderAfterFeedIdle();
9627
9708
  if (this.renderTimeout) {
9628
9709
  this.clock.clearTimeout(this.renderTimeout);
9629
9710
  this.renderTimeout = null;
@@ -9637,20 +9718,14 @@ Captured external output:
9637
9718
  this.internalStop();
9638
9719
  }
9639
9720
  internalStop() {
9640
- if (this.isRunning && !this._isDestroyed) {
9641
- this._isRunning = false;
9642
- if (this.memorySnapshotTimer) {
9643
- this.clock.clearInterval(this.memorySnapshotTimer);
9644
- this.memorySnapshotTimer = null;
9645
- }
9646
- if (this.renderTimeout) {
9647
- this.clock.clearTimeout(this.renderTimeout);
9648
- this.renderTimeout = null;
9649
- }
9650
- if (!this.rendering) {
9651
- this.resolveIdleIfNeeded();
9652
- }
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;
9653
9727
  }
9728
+ this.internalPause();
9654
9729
  }
9655
9730
  destroy() {
9656
9731
  if (this._isDestroyed)
@@ -9668,6 +9743,13 @@ Captured external output:
9668
9743
  if (this._destroyCleanupPrepared)
9669
9744
  return;
9670
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
+ }
9671
9753
  if (this._usesProcessStdout) {
9672
9754
  process.removeListener("SIGWINCH", this.sigwinchHandler);
9673
9755
  }
@@ -9847,6 +9929,11 @@ Captured external output:
9847
9929
  this.rendering = true;
9848
9930
  let renderFailed = false;
9849
9931
  try {
9932
+ if (this._feed?.isBackpressured()) {
9933
+ this.handleNativeRenderRejection(NATIVE_RENDER_STATUS_SKIPPED);
9934
+ this.immediateRerenderRequested = false;
9935
+ return;
9936
+ }
9850
9937
  this._frameId++;
9851
9938
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
9852
9939
  const elapsed = this.getElapsedMs(now, this.lastTime);
@@ -9929,7 +10016,7 @@ Captured external output:
9929
10016
  this.renderTimeout = null;
9930
10017
  }
9931
10018
  } else if (nativeStatus === "backpressured") {
9932
- if (!startedWhileRunning || this._isRunning || this.immediateRerenderRequested) {
10019
+ if (!startedWhileRunning || this._isRunning || this.immediateRerenderRequested || this._controlState === "idle" /* IDLE */) {
9933
10020
  this.scheduleRenderAfterBackpressure();
9934
10021
  }
9935
10022
  } else if (nativeStatus === "retryable-skip") {
@@ -10321,5 +10408,5 @@ Captured external output:
10321
10408
 
10322
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 };
10323
10410
 
10324
- //# debugId=3EFDC723C8276A6F64756E2164756E21
10325
- //# sourceMappingURL=chunk-bun-jxfx3h5k.js.map
10411
+ //# debugId=2464034E49CDB83B64756E2164756E21
10412
+ //# sourceMappingURL=chunk-bun-bb3k0yt8.js.map