@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.
@@ -40,7 +40,7 @@ import {
40
40
  toArrayBuffer,
41
41
  treeSitterToTextChunks,
42
42
  yoga_default
43
- } from "./chunk-node-mfda59vq.js";
43
+ } from "./chunk-node-f647ts9q.js";
44
44
 
45
45
  // src/Renderable.ts
46
46
  import { EventEmitter } from "events";
@@ -1149,8 +1149,8 @@ class Renderable extends BaseRenderable {
1149
1149
  y: scissorRect.y,
1150
1150
  width: scissorRect.width,
1151
1151
  height: scissorRect.height,
1152
- screenX: this._screenX,
1153
- screenY: this._screenY
1152
+ screenX: this.buffered ? this._screenX : scissorRect.x,
1153
+ screenY: this.buffered ? this._screenY : scissorRect.y
1154
1154
  });
1155
1155
  }
1156
1156
  if (!this._hasVisibleChildFilter()) {
@@ -1868,6 +1868,14 @@ class EditBuffer extends EventEmitter2 {
1868
1868
  this.guard();
1869
1869
  return this.lib.textBufferGetLineCount(this.textBufferPtr);
1870
1870
  }
1871
+ setTabWidth(width) {
1872
+ this.guard();
1873
+ this.lib.editBufferSetTabWidth(this.bufferPtr, width);
1874
+ }
1875
+ getTabWidth() {
1876
+ this.guard();
1877
+ return this.lib.textBufferGetTabWidth(this.textBufferPtr);
1878
+ }
1871
1879
  getText() {
1872
1880
  this.guard();
1873
1881
  const maxSize = 1024 * 1024;
@@ -6777,6 +6785,7 @@ registerEnvVar({
6777
6785
  type: "boolean",
6778
6786
  default: false
6779
6787
  });
6788
+ var KITTY_IMAGE_TRANSPORTS = ["raw", "zlib", "file"];
6780
6789
  var DEFAULT_FOOTER_HEIGHT = 12;
6781
6790
  var MAX_SCROLLBACK_SURFACE_HEIGHT_PASSES = 4;
6782
6791
  var TRANSPARENT_RGBA = RGBA.fromValues(0, 0, 0, 0);
@@ -6922,6 +6931,7 @@ class ScrollbackSnapshotRenderContext extends EventEmitter5 {
6922
6931
  updateSelection(_currentRenderable, _x, _y, _options) {}
6923
6932
  }
6924
6933
  var DEFAULT_FORWARDED_ENV_KEYS = [
6934
+ "TMPDIR",
6925
6935
  "SSH_CONNECTION",
6926
6936
  "SSH_CLIENT",
6927
6937
  "SSH_TTY",
@@ -7135,6 +7145,7 @@ class CliRenderer extends EventEmitter5 {
7135
7145
  minTargetFrameTime = 1000 / this._maxFps;
7136
7146
  immediateRerenderRequested = false;
7137
7147
  updateScheduled = false;
7148
+ updateGeneration = 0;
7138
7149
  liveRequestCounter = 0;
7139
7150
  _controlState = "idle" /* IDLE */;
7140
7151
  frameCallbacks = [];
@@ -7157,6 +7168,8 @@ class CliRenderer extends EventEmitter5 {
7157
7168
  animationRequest = new Map;
7158
7169
  resizeTimeoutId = null;
7159
7170
  capabilityTimeoutId = null;
7171
+ kittyTransportTimer = null;
7172
+ kittyTransportMode;
7160
7173
  terminalKeepAliveTimer = null;
7161
7174
  xtVersionWaiters = new Set;
7162
7175
  splitStartupSeedTimeoutId = null;
@@ -7194,9 +7207,10 @@ class CliRenderer extends EventEmitter5 {
7194
7207
  realStdoutWrite;
7195
7208
  _useConsole = true;
7196
7209
  sigwinchHandler = (() => {
7197
- const width = this.stdout.columns || 80;
7198
- const height = this.stdout.rows || 24;
7199
- this.handleResize(width, height);
7210
+ const width = this.stdout.columns;
7211
+ const height = this.stdout.rows;
7212
+ if (width > 0 && height > 0)
7213
+ this.handleResize(width, height);
7200
7214
  }).bind(this);
7201
7215
  _capabilities = null;
7202
7216
  _latestPointer = { x: 0, y: 0 };
@@ -7286,8 +7300,7 @@ Captured external output:
7286
7300
  _detachFeed = null;
7287
7301
  _detachFeedError = null;
7288
7302
  feedIdleRenderScheduled = false;
7289
- ordinaryFrameWaitingForFeed = false;
7290
- ordinaryFrameWaitControlState = null;
7303
+ feedIdleWaitPending = false;
7291
7304
  get controlState() {
7292
7305
  return this._controlState;
7293
7306
  }
@@ -7303,6 +7316,10 @@ Captured external output:
7303
7316
  const { screenMode, footerHeight, externalOutputMode } = resolveModes(config);
7304
7317
  const initialGeometry = calculateRenderGeometry(screenMode, width, height, footerHeight);
7305
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");
7306
7323
  if (rendererTracker.streamOwners.get(stdin)) {
7307
7324
  throw new Error("Cannot create CliRenderer: stdin is already used by another CliRenderer");
7308
7325
  }
@@ -7332,6 +7349,7 @@ Captured external output:
7332
7349
  feed?.close();
7333
7350
  throw new Error("Failed to create renderer");
7334
7351
  }
7352
+ lib.setKittyImageTransport(rendererPtr, transportCode);
7335
7353
  if (config.useThread === undefined)
7336
7354
  config.useThread = true;
7337
7355
  if (process.platform === "linux")
@@ -7348,6 +7366,8 @@ Captured external output:
7348
7366
  });
7349
7367
  });
7350
7368
  this._detachFeedError = feed.onError((code) => {
7369
+ if (this.kittyTransportTimer !== null)
7370
+ this.kittyOutputErrorHandler();
7351
7371
  console.error(`[CliRenderer] NativeSpanFeed error: code=${code}`);
7352
7372
  });
7353
7373
  }
@@ -7472,7 +7492,8 @@ Captured external output:
7472
7492
  return id;
7473
7493
  };
7474
7494
  global.cancelAnimationFrame = (handle) => {
7475
- this.animationRequest.delete(handle);
7495
+ if (this.animationRequest.delete(handle))
7496
+ this.dropLive();
7476
7497
  };
7477
7498
  const window = global.window;
7478
7499
  if (!window) {
@@ -7625,27 +7646,33 @@ Captured external output:
7625
7646
  }
7626
7647
  scheduleRenderAfterFeedIdle() {
7627
7648
  const feed = this._feed;
7628
- if (!feed || this.feedIdleRenderScheduled || this._isDestroyed)
7649
+ if (!feed || this._isDestroyed || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */)
7629
7650
  return;
7630
7651
  this.feedIdleRenderScheduled = true;
7652
+ if (this.feedIdleWaitPending)
7653
+ return;
7654
+ this.feedIdleWaitPending = true;
7631
7655
  feed.idle().then(() => {
7632
- this.feedIdleRenderScheduled = false;
7633
- const ordinaryFrameWasWaiting = this.ordinaryFrameWaitingForFeed;
7634
- const ordinaryFrameWaitControlState = this.ordinaryFrameWaitControlState;
7635
- this.ordinaryFrameWaitingForFeed = false;
7636
- this.ordinaryFrameWaitControlState = null;
7637
- 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 */)) {
7638
- this.resolveIdleIfNeeded();
7656
+ this.feedIdleWaitPending = false;
7657
+ if (!this.feedIdleRenderScheduled)
7658
+ return;
7659
+ if (feed.isBackpressured()) {
7660
+ this.scheduleRenderAfterFeedIdle();
7639
7661
  return;
7640
7662
  }
7663
+ this.feedIdleRenderScheduled = false;
7641
7664
  this.scheduleRenderTimer();
7642
7665
  this.resolveIdleIfNeeded();
7643
7666
  });
7644
7667
  }
7668
+ cancelRenderAfterFeedIdle() {
7669
+ if (!this.feedIdleRenderScheduled)
7670
+ return;
7671
+ this.feedIdleRenderScheduled = false;
7672
+ this.immediateRerenderRequested = false;
7673
+ }
7645
7674
  handleNativeRenderRejection(status) {
7646
7675
  if (status === NATIVE_RENDER_STATUS_SKIPPED && this._feed) {
7647
- this.ordinaryFrameWaitingForFeed = true;
7648
- this.ordinaryFrameWaitControlState = this._controlState;
7649
7676
  this.scheduleRenderAfterFeedIdle();
7650
7677
  return "retryable-skip";
7651
7678
  }
@@ -7687,39 +7714,38 @@ Captured external output:
7687
7714
  return;
7688
7715
  }
7689
7716
  if (this._isRunning) {
7690
- if (!this.rendering && !this.renderTimeout && !this.ordinaryFrameWaitingForFeed) {
7717
+ if (!this.rendering && !this.renderTimeout) {
7691
7718
  this.scheduleRenderTimer();
7692
7719
  }
7693
7720
  return;
7694
7721
  }
7695
- if (this.ordinaryFrameWaitingForFeed) {
7696
- return;
7697
- }
7698
7722
  if (this.rendering) {
7699
7723
  this.immediateRerenderRequested = true;
7700
7724
  return;
7701
7725
  }
7702
7726
  if (!this.updateScheduled && !this.renderTimeout) {
7703
7727
  this.updateScheduled = true;
7728
+ const generation = ++this.updateGeneration;
7704
7729
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
7705
7730
  const elapsed = this.getElapsedMs(now, this.lastTime);
7706
7731
  const delay = Math.max(this.minTargetFrameTime - elapsed, 0);
7707
7732
  if (delay === 0) {
7708
- process.nextTick(() => this.activateFrame());
7733
+ process.nextTick(() => this.activateFrame(generation));
7709
7734
  return;
7710
7735
  }
7711
- this.clock.setTimeout(() => this.activateFrame(), delay);
7736
+ this.clock.setTimeout(() => this.activateFrame(generation), delay);
7712
7737
  }
7713
7738
  }
7714
- async activateFrame() {
7715
- if (!this.updateScheduled) {
7739
+ async activateFrame(generation) {
7740
+ if (generation !== this.updateGeneration || !this.updateScheduled) {
7716
7741
  this.resolveIdleIfNeeded();
7717
7742
  return;
7718
7743
  }
7719
7744
  try {
7720
7745
  await this.loop();
7721
7746
  } finally {
7722
- this.updateScheduled = false;
7747
+ if (generation === this.updateGeneration)
7748
+ this.updateScheduled = false;
7723
7749
  this.resolveIdleIfNeeded();
7724
7750
  }
7725
7751
  }
@@ -7938,6 +7964,50 @@ Captured external output:
7938
7964
  get capabilities() {
7939
7965
  return this._capabilities;
7940
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
+ };
7941
8011
  triggerNotification(message, title) {
7942
8012
  if (this._isDestroyed)
7943
8013
  return false;
@@ -8499,7 +8569,7 @@ Captured external output:
8499
8569
  const forceCommit = forceFooterRepaint && index === lastCommitIndex;
8500
8570
  const beginFrame = index === 0;
8501
8571
  const finalizeFrame = index === lastCommitIndex;
8502
- 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);
8503
8573
  if (nativeResult.status === NATIVE_RENDER_STATUS_SKIPPED) {
8504
8574
  nativeBackpressured = true;
8505
8575
  break;
@@ -8840,6 +8910,7 @@ Captured external output:
8840
8910
  explicitWidthCprActive: true,
8841
8911
  startupCursorCprActive
8842
8912
  });
8913
+ this.startKittyTransportPolling();
8843
8914
  this.lib.setupTerminal(this.rendererPtr, this._screenMode === "alternate-screen");
8844
8915
  this._capabilities = this.lib.getTerminalCapabilities(this.rendererPtr);
8845
8916
  if (this.debugOverlay.enabled) {
@@ -9005,6 +9076,14 @@ Captured external output:
9005
9076
  });
9006
9077
  }
9007
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
+ }
9008
9087
  if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
9009
9088
  if (event.type === "response" && isPixelResolutionResponse(event.sequence)) {
9010
9089
  this.dispatchSequenceHandlers(event.sequence);
@@ -9503,13 +9582,21 @@ Captured external output:
9503
9582
  if (this._controlState === "idle" /* IDLE */ && this.liveRequestCounter > 0) {
9504
9583
  this._controlState = "auto_started" /* AUTO_STARTED */;
9505
9584
  this.internalStart();
9585
+ } else if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */ && this._previousControlState === "idle" /* IDLE */) {
9586
+ this._previousControlState = "auto_started" /* AUTO_STARTED */;
9506
9587
  }
9507
9588
  }
9508
9589
  dropLive() {
9509
- 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
+ }
9510
9596
  if (this._controlState === "auto_started" /* AUTO_STARTED */ && this.liveRequestCounter === 0) {
9511
9597
  this._controlState = "idle" /* IDLE */;
9512
- this.internalPause();
9598
+ this._isRunning = false;
9599
+ this.resolveIdleIfNeeded();
9513
9600
  }
9514
9601
  }
9515
9602
  start() {
@@ -9523,6 +9610,7 @@ Captured external output:
9523
9610
  if (!this._isRunning && !this._isDestroyed) {
9524
9611
  this._isRunning = true;
9525
9612
  this.updateScheduled = false;
9613
+ this.updateGeneration++;
9526
9614
  if (this.memorySnapshotInterval > 0) {
9527
9615
  this.startMemorySnapshotTimer();
9528
9616
  }
@@ -9537,6 +9625,7 @@ Captured external output:
9537
9625
  this._previousControlState = this._controlState;
9538
9626
  this._controlState = "explicit_suspended" /* EXPLICIT_SUSPENDED */;
9539
9627
  this.updateScheduled = false;
9628
+ this.updateGeneration++;
9540
9629
  this.internalPause();
9541
9630
  if (this._terminalIsSetup) {
9542
9631
  this.clearSplitStartupCursorSeed();
@@ -9614,6 +9703,7 @@ Captured external output:
9614
9703
  }
9615
9704
  internalPause() {
9616
9705
  this._isRunning = false;
9706
+ this.cancelRenderAfterFeedIdle();
9617
9707
  if (this.renderTimeout) {
9618
9708
  this.clock.clearTimeout(this.renderTimeout);
9619
9709
  this.renderTimeout = null;
@@ -9627,20 +9717,14 @@ Captured external output:
9627
9717
  this.internalStop();
9628
9718
  }
9629
9719
  internalStop() {
9630
- if (this.isRunning && !this._isDestroyed) {
9631
- this._isRunning = false;
9632
- if (this.memorySnapshotTimer) {
9633
- this.clock.clearInterval(this.memorySnapshotTimer);
9634
- this.memorySnapshotTimer = null;
9635
- }
9636
- if (this.renderTimeout) {
9637
- this.clock.clearTimeout(this.renderTimeout);
9638
- this.renderTimeout = null;
9639
- }
9640
- if (!this.rendering) {
9641
- this.resolveIdleIfNeeded();
9642
- }
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;
9643
9726
  }
9727
+ this.internalPause();
9644
9728
  }
9645
9729
  destroy() {
9646
9730
  if (this._isDestroyed)
@@ -9658,6 +9742,13 @@ Captured external output:
9658
9742
  if (this._destroyCleanupPrepared)
9659
9743
  return;
9660
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
+ }
9661
9752
  if (this._usesProcessStdout) {
9662
9753
  process.removeListener("SIGWINCH", this.sigwinchHandler);
9663
9754
  }
@@ -9829,6 +9920,7 @@ Captured external output:
9829
9920
  async loop() {
9830
9921
  if (this.rendering || this._isDestroyed)
9831
9922
  return;
9923
+ const startedWhileRunning = this._isRunning;
9832
9924
  if (this.renderTimeout) {
9833
9925
  this.clock.clearTimeout(this.renderTimeout);
9834
9926
  this.renderTimeout = null;
@@ -9836,6 +9928,11 @@ Captured external output:
9836
9928
  this.rendering = true;
9837
9929
  let renderFailed = false;
9838
9930
  try {
9931
+ if (this._feed?.isBackpressured()) {
9932
+ this.handleNativeRenderRejection(NATIVE_RENDER_STATUS_SKIPPED);
9933
+ this.immediateRerenderRequested = false;
9934
+ return;
9935
+ }
9839
9936
  this._frameId++;
9840
9937
  const now = this.normalizeClockTime(this.clock.now(), this.lastTime);
9841
9938
  const elapsed = this.getElapsedMs(now, this.lastTime);
@@ -9918,7 +10015,9 @@ Captured external output:
9918
10015
  this.renderTimeout = null;
9919
10016
  }
9920
10017
  } else if (nativeStatus === "backpressured") {
9921
- this.scheduleRenderAfterBackpressure();
10018
+ if (!startedWhileRunning || this._isRunning || this.immediateRerenderRequested || this._controlState === "idle" /* IDLE */) {
10019
+ this.scheduleRenderAfterBackpressure();
10020
+ }
9922
10021
  } else if (nativeStatus === "retryable-skip") {
9923
10022
  this.immediateRerenderRequested = false;
9924
10023
  this.renderTimeout = null;
@@ -10308,5 +10407,5 @@ Captured external output:
10308
10407
 
10309
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 };
10310
10409
 
10311
- //# debugId=DFE44A27128A73E264756E2164756E21
10312
- //# sourceMappingURL=chunk-node-kr27pp2p.js.map
10410
+ //# debugId=E69D7F0A21FC1D2B64756E2164756E21
10411
+ //# sourceMappingURL=chunk-node-6bg8r2m7.js.map