@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.
@@ -40,7 +40,7 @@ import {
40
40
  toArrayBuffer,
41
41
  treeSitterToTextChunks,
42
42
  yoga_default
43
- } from "./chunk-node-zcz10bhr.js";
43
+ } from "./chunk-node-f647ts9q.js";
44
44
 
45
45
  // src/Renderable.ts
46
46
  import { EventEmitter } from "events";
@@ -6785,6 +6785,7 @@ registerEnvVar({
6785
6785
  type: "boolean",
6786
6786
  default: false
6787
6787
  });
6788
+ var KITTY_IMAGE_TRANSPORTS = ["raw", "zlib", "file"];
6788
6789
  var DEFAULT_FOOTER_HEIGHT = 12;
6789
6790
  var MAX_SCROLLBACK_SURFACE_HEIGHT_PASSES = 4;
6790
6791
  var TRANSPARENT_RGBA = RGBA.fromValues(0, 0, 0, 0);
@@ -6930,6 +6931,7 @@ class ScrollbackSnapshotRenderContext extends EventEmitter5 {
6930
6931
  updateSelection(_currentRenderable, _x, _y, _options) {}
6931
6932
  }
6932
6933
  var DEFAULT_FORWARDED_ENV_KEYS = [
6934
+ "TMPDIR",
6933
6935
  "SSH_CONNECTION",
6934
6936
  "SSH_CLIENT",
6935
6937
  "SSH_TTY",
@@ -7143,6 +7145,7 @@ class CliRenderer extends EventEmitter5 {
7143
7145
  minTargetFrameTime = 1000 / this._maxFps;
7144
7146
  immediateRerenderRequested = false;
7145
7147
  updateScheduled = false;
7148
+ updateGeneration = 0;
7146
7149
  liveRequestCounter = 0;
7147
7150
  _controlState = "idle" /* IDLE */;
7148
7151
  frameCallbacks = [];
@@ -7165,6 +7168,8 @@ class CliRenderer extends EventEmitter5 {
7165
7168
  animationRequest = new Map;
7166
7169
  resizeTimeoutId = null;
7167
7170
  capabilityTimeoutId = null;
7171
+ kittyTransportTimer = null;
7172
+ kittyTransportMode;
7168
7173
  terminalKeepAliveTimer = null;
7169
7174
  xtVersionWaiters = new Set;
7170
7175
  splitStartupSeedTimeoutId = null;
@@ -7295,8 +7300,7 @@ Captured external output:
7295
7300
  _detachFeed = null;
7296
7301
  _detachFeedError = null;
7297
7302
  feedIdleRenderScheduled = false;
7298
- ordinaryFrameWaitingForFeed = false;
7299
- ordinaryFrameWaitControlState = null;
7303
+ feedIdleWaitPending = false;
7300
7304
  get controlState() {
7301
7305
  return this._controlState;
7302
7306
  }
@@ -7312,6 +7316,10 @@ Captured external output:
7312
7316
  const { screenMode, footerHeight, externalOutputMode } = resolveModes(config);
7313
7317
  const initialGeometry = calculateRenderGeometry(screenMode, width, height, footerHeight);
7314
7318
  const remoteMode = config.remote ?? (useFeedOutput ? true : undefined);
7319
+ this.kittyTransportMode = config.kittyImageTransport ?? "raw";
7320
+ const transportCode = KITTY_IMAGE_TRANSPORTS.indexOf(this.kittyTransportMode);
7321
+ if (transportCode < 0)
7322
+ throw new TypeError("Invalid kittyImageTransport");
7315
7323
  if (rendererTracker.streamOwners.get(stdin)) {
7316
7324
  throw new Error("Cannot create CliRenderer: stdin is already used by another CliRenderer");
7317
7325
  }
@@ -7341,6 +7349,7 @@ Captured external output:
7341
7349
  feed?.close();
7342
7350
  throw new Error("Failed to create renderer");
7343
7351
  }
7352
+ lib.setKittyImageTransport(rendererPtr, transportCode);
7344
7353
  if (config.useThread === undefined)
7345
7354
  config.useThread = true;
7346
7355
  if (process.platform === "linux")
@@ -7357,6 +7366,8 @@ Captured external output:
7357
7366
  });
7358
7367
  });
7359
7368
  this._detachFeedError = feed.onError((code) => {
7369
+ if (this.kittyTransportTimer !== null)
7370
+ this.kittyOutputErrorHandler();
7360
7371
  console.error(`[CliRenderer] NativeSpanFeed error: code=${code}`);
7361
7372
  });
7362
7373
  }
@@ -7481,7 +7492,8 @@ Captured external output:
7481
7492
  return id;
7482
7493
  };
7483
7494
  global.cancelAnimationFrame = (handle) => {
7484
- this.animationRequest.delete(handle);
7495
+ if (this.animationRequest.delete(handle))
7496
+ this.dropLive();
7485
7497
  };
7486
7498
  const window = global.window;
7487
7499
  if (!window) {
@@ -7634,27 +7646,33 @@ Captured external output:
7634
7646
  }
7635
7647
  scheduleRenderAfterFeedIdle() {
7636
7648
  const feed = this._feed;
7637
- if (!feed || this.feedIdleRenderScheduled || this._isDestroyed)
7649
+ if (!feed || this._isDestroyed || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */)
7638
7650
  return;
7639
7651
  this.feedIdleRenderScheduled = true;
7652
+ if (this.feedIdleWaitPending)
7653
+ return;
7654
+ this.feedIdleWaitPending = true;
7640
7655
  feed.idle().then(() => {
7641
- this.feedIdleRenderScheduled = false;
7642
- const ordinaryFrameWasWaiting = this.ordinaryFrameWaitingForFeed;
7643
- const ordinaryFrameWaitControlState = this.ordinaryFrameWaitControlState;
7644
- this.ordinaryFrameWaitingForFeed = false;
7645
- this.ordinaryFrameWaitControlState = null;
7646
- 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 */)) {
7647
- this.resolveIdleIfNeeded();
7656
+ this.feedIdleWaitPending = false;
7657
+ if (!this.feedIdleRenderScheduled)
7658
+ return;
7659
+ if (feed.isBackpressured()) {
7660
+ this.scheduleRenderAfterFeedIdle();
7648
7661
  return;
7649
7662
  }
7663
+ this.feedIdleRenderScheduled = false;
7650
7664
  this.scheduleRenderTimer();
7651
7665
  this.resolveIdleIfNeeded();
7652
7666
  });
7653
7667
  }
7668
+ cancelRenderAfterFeedIdle() {
7669
+ if (!this.feedIdleRenderScheduled)
7670
+ return;
7671
+ this.feedIdleRenderScheduled = false;
7672
+ this.immediateRerenderRequested = false;
7673
+ }
7654
7674
  handleNativeRenderRejection(status) {
7655
7675
  if (status === NATIVE_RENDER_STATUS_SKIPPED && this._feed) {
7656
- this.ordinaryFrameWaitingForFeed = true;
7657
- this.ordinaryFrameWaitControlState = this._controlState;
7658
7676
  this.scheduleRenderAfterFeedIdle();
7659
7677
  return "retryable-skip";
7660
7678
  }
@@ -7696,39 +7714,38 @@ Captured external output:
7696
7714
  return;
7697
7715
  }
7698
7716
  if (this._isRunning) {
7699
- if (!this.rendering && !this.renderTimeout && !this.ordinaryFrameWaitingForFeed) {
7717
+ if (!this.rendering && !this.renderTimeout) {
7700
7718
  this.scheduleRenderTimer();
7701
7719
  }
7702
7720
  return;
7703
7721
  }
7704
- if (this.ordinaryFrameWaitingForFeed) {
7705
- return;
7706
- }
7707
7722
  if (this.rendering) {
7708
7723
  this.immediateRerenderRequested = true;
7709
7724
  return;
7710
7725
  }
7711
7726
  if (!this.updateScheduled && !this.renderTimeout) {
7712
7727
  this.updateScheduled = true;
7728
+ const generation = ++this.updateGeneration;
7713
7729
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
7714
7730
  const elapsed = this.getElapsedMs(now, this.lastTime);
7715
7731
  const delay = Math.max(this.minTargetFrameTime - elapsed, 0);
7716
7732
  if (delay === 0) {
7717
- process.nextTick(() => this.activateFrame());
7733
+ process.nextTick(() => this.activateFrame(generation));
7718
7734
  return;
7719
7735
  }
7720
- this.clock.setTimeout(() => this.activateFrame(), delay);
7736
+ this.clock.setTimeout(() => this.activateFrame(generation), delay);
7721
7737
  }
7722
7738
  }
7723
- async activateFrame() {
7724
- if (!this.updateScheduled) {
7739
+ async activateFrame(generation) {
7740
+ if (generation !== this.updateGeneration || !this.updateScheduled) {
7725
7741
  this.resolveIdleIfNeeded();
7726
7742
  return;
7727
7743
  }
7728
7744
  try {
7729
7745
  await this.loop();
7730
7746
  } finally {
7731
- this.updateScheduled = false;
7747
+ if (generation === this.updateGeneration)
7748
+ this.updateScheduled = false;
7732
7749
  this.resolveIdleIfNeeded();
7733
7750
  }
7734
7751
  }
@@ -7947,6 +7964,50 @@ Captured external output:
7947
7964
  get capabilities() {
7948
7965
  return this._capabilities;
7949
7966
  }
7967
+ get kittyImageTransport() {
7968
+ return this.kittyTransportMode;
7969
+ }
7970
+ set kittyImageTransport(mode) {
7971
+ const code = KITTY_IMAGE_TRANSPORTS.indexOf(mode);
7972
+ if (code < 0)
7973
+ throw new TypeError("Invalid kittyImageTransport");
7974
+ if (this._isDestroyed || mode === this.kittyTransportMode)
7975
+ return;
7976
+ this.kittyTransportMode = mode;
7977
+ this.startKittyTransportPolling();
7978
+ this.lib.setKittyImageTransport(this.rendererPtr, code);
7979
+ this.requestRender();
7980
+ }
7981
+ startKittyTransportPolling() {
7982
+ if (!this._terminalIsSetup || this.kittyTransportMode !== "file" || this.kittyTransportTimer !== null)
7983
+ return;
7984
+ this.stdout.on("error", this.kittyOutputErrorHandler);
7985
+ this.kittyTransportTimer = this.clock.setInterval(() => {
7986
+ if (!this._isDestroyed && this.lib.pollKittyImageTransport(this.rendererPtr))
7987
+ this.requestRender();
7988
+ }, 1000);
7989
+ }
7990
+ get kittyImageTransportStatus() {
7991
+ const [mode, effective, fileState, fallback, pendingFiles, pendingBytes] = this.lib.getKittyImageTransport(this.rendererPtr);
7992
+ return {
7993
+ requested: KITTY_IMAGE_TRANSPORTS[mode],
7994
+ effective: ["raw", "zlib", "png", "file"][effective],
7995
+ fileState: ["disabled", "probing", "ready", "unsupported", "timeout", "io-error", "cancelled"][fileState],
7996
+ fallback: ["none", "not-ready", "unavailable", "budget", "busy", "preparation", "compression"][fallback],
7997
+ pendingFiles,
7998
+ pendingBytes
7999
+ };
8000
+ }
8001
+ cancelKittyImageTransport() {
8002
+ if (this._isDestroyed)
8003
+ return;
8004
+ this.lib.cancelKittyImageTransport(this.rendererPtr, false);
8005
+ this.requestRender();
8006
+ }
8007
+ kittyOutputErrorHandler = () => {
8008
+ if (!this._isDestroyed)
8009
+ this.lib.cancelKittyImageTransport(this.rendererPtr, true);
8010
+ };
7950
8011
  triggerNotification(message, title) {
7951
8012
  if (this._isDestroyed)
7952
8013
  return false;
@@ -8508,7 +8569,7 @@ Captured external output:
8508
8569
  const forceCommit = forceFooterRepaint && index === lastCommitIndex;
8509
8570
  const beginFrame = index === 0;
8510
8571
  const finalizeFrame = index === lastCommitIndex;
8511
- const nativeResult = this.lib.commitSplitFooterSnapshot(this.rendererPtr, commit.snapshot, commit.rowColumns, commit.startOnNewLine, commit.trailingNewline, this.getSplitPinnedRenderOffset(), forceCommit, beginFrame, finalizeFrame);
8572
+ const nativeResult = this.lib.commitSplitFooterSnapshot(this.rendererPtr, commit.snapshot, commit.rowColumns, commit.startOnNewLine, commit.trailingNewline, this.getSplitPinnedRenderOffset(), forceCommit, beginFrame, finalizeFrame, drainAll);
8512
8573
  if (nativeResult.status === NATIVE_RENDER_STATUS_SKIPPED) {
8513
8574
  nativeBackpressured = true;
8514
8575
  break;
@@ -8849,6 +8910,7 @@ Captured external output:
8849
8910
  explicitWidthCprActive: true,
8850
8911
  startupCursorCprActive
8851
8912
  });
8913
+ this.startKittyTransportPolling();
8852
8914
  this.lib.setupTerminal(this.rendererPtr, this._screenMode === "alternate-screen");
8853
8915
  this._capabilities = this.lib.getTerminalCapabilities(this.rendererPtr);
8854
8916
  if (this.debugOverlay.enabled) {
@@ -9014,6 +9076,14 @@ Captured external output:
9014
9076
  });
9015
9077
  }
9016
9078
  handleStdinEvent(event) {
9079
+ if (event.type === "response" && event.sequence.startsWith("\x1B_G")) {
9080
+ const result = this.lib.processKittyImageReply(this.rendererPtr, event.sequence);
9081
+ if (result !== 0) {
9082
+ if (result === 2)
9083
+ this.requestRender();
9084
+ return;
9085
+ }
9086
+ }
9017
9087
  if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
9018
9088
  if (event.type === "response" && isPixelResolutionResponse(event.sequence)) {
9019
9089
  this.dispatchSequenceHandlers(event.sequence);
@@ -9512,13 +9582,21 @@ Captured external output:
9512
9582
  if (this._controlState === "idle" /* IDLE */ && this.liveRequestCounter > 0) {
9513
9583
  this._controlState = "auto_started" /* AUTO_STARTED */;
9514
9584
  this.internalStart();
9585
+ } else if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */ && this._previousControlState === "idle" /* IDLE */) {
9586
+ this._previousControlState = "auto_started" /* AUTO_STARTED */;
9515
9587
  }
9516
9588
  }
9517
9589
  dropLive() {
9518
- this.liveRequestCounter = Math.max(0, this.liveRequestCounter - 1);
9590
+ if (this.liveRequestCounter === 0)
9591
+ return;
9592
+ this.liveRequestCounter--;
9593
+ if (this.liveRequestCounter === 0 && this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */ && this._previousControlState === "auto_started" /* AUTO_STARTED */) {
9594
+ this._previousControlState = "idle" /* IDLE */;
9595
+ }
9519
9596
  if (this._controlState === "auto_started" /* AUTO_STARTED */ && this.liveRequestCounter === 0) {
9520
9597
  this._controlState = "idle" /* IDLE */;
9521
- this.internalPause();
9598
+ this._isRunning = false;
9599
+ this.resolveIdleIfNeeded();
9522
9600
  }
9523
9601
  }
9524
9602
  start() {
@@ -9532,6 +9610,7 @@ Captured external output:
9532
9610
  if (!this._isRunning && !this._isDestroyed) {
9533
9611
  this._isRunning = true;
9534
9612
  this.updateScheduled = false;
9613
+ this.updateGeneration++;
9535
9614
  if (this.memorySnapshotInterval > 0) {
9536
9615
  this.startMemorySnapshotTimer();
9537
9616
  }
@@ -9546,6 +9625,7 @@ Captured external output:
9546
9625
  this._previousControlState = this._controlState;
9547
9626
  this._controlState = "explicit_suspended" /* EXPLICIT_SUSPENDED */;
9548
9627
  this.updateScheduled = false;
9628
+ this.updateGeneration++;
9549
9629
  this.internalPause();
9550
9630
  if (this._terminalIsSetup) {
9551
9631
  this.clearSplitStartupCursorSeed();
@@ -9623,6 +9703,7 @@ Captured external output:
9623
9703
  }
9624
9704
  internalPause() {
9625
9705
  this._isRunning = false;
9706
+ this.cancelRenderAfterFeedIdle();
9626
9707
  if (this.renderTimeout) {
9627
9708
  this.clock.clearTimeout(this.renderTimeout);
9628
9709
  this.renderTimeout = null;
@@ -9636,20 +9717,14 @@ Captured external output:
9636
9717
  this.internalStop();
9637
9718
  }
9638
9719
  internalStop() {
9639
- if (this.isRunning && !this._isDestroyed) {
9640
- this._isRunning = false;
9641
- if (this.memorySnapshotTimer) {
9642
- this.clock.clearInterval(this.memorySnapshotTimer);
9643
- this.memorySnapshotTimer = null;
9644
- }
9645
- if (this.renderTimeout) {
9646
- this.clock.clearTimeout(this.renderTimeout);
9647
- this.renderTimeout = null;
9648
- }
9649
- if (!this.rendering) {
9650
- this.resolveIdleIfNeeded();
9651
- }
9720
+ this.updateScheduled = false;
9721
+ this.updateGeneration++;
9722
+ this.immediateRerenderRequested = false;
9723
+ if (this.memorySnapshotTimer) {
9724
+ this.clock.clearInterval(this.memorySnapshotTimer);
9725
+ this.memorySnapshotTimer = null;
9652
9726
  }
9727
+ this.internalPause();
9653
9728
  }
9654
9729
  destroy() {
9655
9730
  if (this._isDestroyed)
@@ -9667,6 +9742,13 @@ Captured external output:
9667
9742
  if (this._destroyCleanupPrepared)
9668
9743
  return;
9669
9744
  this._destroyCleanupPrepared = true;
9745
+ this.cancelRenderAfterFeedIdle();
9746
+ if (this.kittyTransportTimer !== null) {
9747
+ this.clock.clearInterval(this.kittyTransportTimer);
9748
+ this.kittyTransportTimer = null;
9749
+ this.stdout.off("error", this.kittyOutputErrorHandler);
9750
+ this.lib.cancelKittyImageTransport(this.rendererPtr, false);
9751
+ }
9670
9752
  if (this._usesProcessStdout) {
9671
9753
  process.removeListener("SIGWINCH", this.sigwinchHandler);
9672
9754
  }
@@ -9846,6 +9928,11 @@ Captured external output:
9846
9928
  this.rendering = true;
9847
9929
  let renderFailed = false;
9848
9930
  try {
9931
+ if (this._feed?.isBackpressured()) {
9932
+ this.handleNativeRenderRejection(NATIVE_RENDER_STATUS_SKIPPED);
9933
+ this.immediateRerenderRequested = false;
9934
+ return;
9935
+ }
9849
9936
  this._frameId++;
9850
9937
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
9851
9938
  const elapsed = this.getElapsedMs(now, this.lastTime);
@@ -9928,7 +10015,7 @@ Captured external output:
9928
10015
  this.renderTimeout = null;
9929
10016
  }
9930
10017
  } else if (nativeStatus === "backpressured") {
9931
- if (!startedWhileRunning || this._isRunning || this.immediateRerenderRequested) {
10018
+ if (!startedWhileRunning || this._isRunning || this.immediateRerenderRequested || this._controlState === "idle" /* IDLE */) {
9932
10019
  this.scheduleRenderAfterBackpressure();
9933
10020
  }
9934
10021
  } else if (nativeStatus === "retryable-skip") {
@@ -10320,5 +10407,5 @@ Captured external output:
10320
10407
 
10321
10408
  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 };
10322
10409
 
10323
- //# debugId=D42CCC457901BBBF64756E2164756E21
10324
- //# sourceMappingURL=chunk-node-dcyj0dm5.js.map
10410
+ //# debugId=E69D7F0A21FC1D2B64756E2164756E21
10411
+ //# sourceMappingURL=chunk-node-6bg8r2m7.js.map