@opentui/core 0.8.0 → 0.8.1

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.
@@ -64,7 +64,7 @@ import {
64
64
  PositionType2,
65
65
  Unit2,
66
66
  Wrap2
67
- } from "./chunk-node-y0w0hq5m.js";
67
+ } from "./chunk-node-m8mjyx7h.js";
68
68
 
69
69
  // src/lib/border.ts
70
70
  var VALID_BORDER_STYLES = ["single", "double", "rounded", "heavy"];
@@ -3222,9 +3222,6 @@ function renderFontToFrameBuffer2(buffer, {
3222
3222
  return { width: 0, height: 0 };
3223
3223
  }
3224
3224
  const colors = Array.isArray(color) ? color : [color];
3225
- if (y < 0 || y + fontDef.lines > height) {
3226
- return { width: 0, height: fontDef.lines };
3227
- }
3228
3225
  let currentX = x;
3229
3226
  const startX = x;
3230
3227
  for (let i = 0;i < text.length; i++) {
@@ -9920,6 +9917,12 @@ class OptimizedBuffer2 {
9920
9917
  this.drawText(afterText, x + end, y, fg, bg, attributes);
9921
9918
  }
9922
9919
  }
9920
+ drawTextFit(text, x, y, maxWidth, fg, bg, ellipsis = false) {
9921
+ this.guard();
9922
+ if (maxWidth < 1)
9923
+ return;
9924
+ this.drawChecked({ operation: "text", text, x, y, maxWidth, ellipsis, foreground: fg, background: bg });
9925
+ }
9923
9926
  fillRect(x, y, width, height, bg) {
9924
9927
  this.guard();
9925
9928
  if (width <= 0 || height <= 0)
@@ -14748,7 +14751,7 @@ class CodeRenderable2 extends TextBufferRenderable2 {
14748
14751
  if (this._content === value)
14749
14752
  return;
14750
14753
  this.runMutation(() => {
14751
- if (this._streaming && this._filetype && !this._drawUnstyledText) {
14754
+ if (this._hadInitialContent && this._shouldRenderTextBuffer && this._filetype && !this._drawUnstyledText) {
14752
14755
  this._content = value;
14753
14756
  this.invalidateHighlights();
14754
14757
  this.requestRender();
@@ -14920,7 +14923,8 @@ class CodeRenderable2 extends TextBufferRenderable2 {
14920
14923
  const isInitialContent = this._streaming && !this._hadInitialContent;
14921
14924
  const shouldDrawUnstyledNow = this._streaming ? isInitialContent && this._drawUnstyledText : this._drawUnstyledText;
14922
14925
  if (this._streaming && !isInitialContent) {
14923
- this.setShouldRenderTextBuffer(true);
14926
+ if (this._drawUnstyledText)
14927
+ this.setShouldRenderTextBuffer(true);
14924
14928
  } else if (shouldDrawUnstyledNow) {
14925
14929
  if (this._initialStyledText) {
14926
14930
  this.textBuffer.setStyledText(this._initialStyledText);
@@ -15826,6 +15830,18 @@ function resolveImageRenderProtocol2(requested, capabilities, hasResolution) {
15826
15830
  return "sixel";
15827
15831
  return "blocks";
15828
15832
  }
15833
+ function checkCrop2(crop, width = Infinity, height = Infinity) {
15834
+ const { left, top, width: cropWidth, height: cropHeight } = crop;
15835
+ const u32 = (value, min) => Number.isInteger(value) && value >= min && value <= 4294967295;
15836
+ if (!u32(left, 0) || !u32(top, 0) || !u32(cropWidth, 1) || !u32(cropHeight, 1))
15837
+ throw new RangeError("crop needs u32 left and top and a positive u32 width and height");
15838
+ if (left + cropWidth > width || top + cropHeight > height)
15839
+ throw new RangeError(`crop ${cropWidth}x${cropHeight} at ${left},${top} lies outside the ${width}x${height} source`);
15840
+ return { left, top, width: cropWidth, height: cropHeight };
15841
+ }
15842
+ function sameCrop2(a, b) {
15843
+ return a === b || !!a && !!b && a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height;
15844
+ }
15829
15845
  function pixelResolution(ctx) {
15830
15846
  const terminalWidth = ctx.terminalWidth ?? 0;
15831
15847
  const terminalHeight = ctx.terminalHeight ?? 0;
@@ -15847,6 +15863,7 @@ class ImageRenderable2 extends Renderable2 {
15847
15863
  onLoad;
15848
15864
  onError;
15849
15865
  _fit;
15866
+ _crop;
15850
15867
  _protocol;
15851
15868
  loadPromise = null;
15852
15869
  constructor(ctx, options) {
@@ -15859,6 +15876,7 @@ class ImageRenderable2 extends Renderable2 {
15859
15876
  this.setNativeSceneImage();
15860
15877
  if (options.source !== undefined)
15861
15878
  this.source = options.source;
15879
+ this.crop = options.crop;
15862
15880
  } catch (error) {
15863
15881
  this.abortConstruction(error, () => this.destroySelf());
15864
15882
  }
@@ -15922,6 +15940,19 @@ class ImageRenderable2 extends Renderable2 {
15922
15940
  this._fit = next;
15923
15941
  this.requestRender();
15924
15942
  }
15943
+ get crop() {
15944
+ return this._crop && { ...this._crop };
15945
+ }
15946
+ set crop(value) {
15947
+ if (sameCrop2(this._crop, value ?? undefined) || this.isDestroyed)
15948
+ return;
15949
+ const next = this.acceptCrop(value ?? undefined, this._loadController ? null : this._image);
15950
+ if (next === null)
15951
+ return;
15952
+ this._ctx.nativeScene.setCrop(this, next);
15953
+ this._crop = next;
15954
+ this.requestRender();
15955
+ }
15925
15956
  get protocol() {
15926
15957
  return this._protocol;
15927
15958
  }
@@ -15944,7 +15975,7 @@ class ImageRenderable2 extends Renderable2 {
15944
15975
  const cellHeight = resolution.height / this._ctx.terminalHeight;
15945
15976
  return cellWidth > 0 && cellHeight > 0 ? cellHeight / cellWidth : 2;
15946
15977
  }
15947
- getFittedSize(targetWidth, targetHeight, cellAspectRatio = this.cellAspectRatio, sourceWidth = this._image?.width ?? 0, sourceHeight = this._image?.height ?? 0) {
15978
+ getFittedSize(targetWidth, targetHeight, cellAspectRatio = this.cellAspectRatio, sourceWidth = this.region()?.width ?? 0, sourceHeight = this.region()?.height ?? 0) {
15948
15979
  if (sourceWidth <= 0 || sourceHeight <= 0 || targetWidth <= 0 || targetHeight <= 0)
15949
15980
  return { width: 0, height: 0 };
15950
15981
  if (this._fit === "fill")
@@ -15993,19 +16024,17 @@ class ImageRenderable2 extends Renderable2 {
15993
16024
  const resolution = pixelResolution(this._ctx);
15994
16025
  const pixelWidth = resolution ? Math.max(1, Math.round(fitted.width * resolution.width / this._ctx.terminalWidth)) : 0;
15995
16026
  const pixelHeight = resolution ? Math.max(1, Math.round(fitted.height * resolution.height / this._ctx.terminalHeight)) : 0;
15996
- let sourceX = 0;
15997
- let sourceY = 0;
15998
- let sourceWidth = this._image.width;
15999
- let sourceHeight = this._image.height;
16027
+ const region = this.region();
16028
+ let { left: sourceX, top: sourceY, width: sourceWidth, height: sourceHeight } = region;
16000
16029
  if (this._fit === "cover") {
16001
16030
  const targetAspect = width / (height * this.cellAspectRatio);
16002
16031
  const sourceAspect = sourceWidth / sourceHeight;
16003
16032
  if (sourceAspect > targetAspect) {
16004
16033
  sourceWidth = Math.max(1, Math.round(sourceHeight * targetAspect));
16005
- sourceX = Math.floor((this._image.width - sourceWidth) / 2);
16034
+ sourceX += Math.floor((region.width - sourceWidth) / 2);
16006
16035
  } else {
16007
16036
  sourceHeight = Math.max(1, Math.round(sourceWidth / targetAspect));
16008
- sourceY = Math.floor((this._image.height - sourceHeight) / 2);
16037
+ sourceY += Math.floor((region.height - sourceHeight) / 2);
16009
16038
  }
16010
16039
  }
16011
16040
  buffer.drawImage(this._image, x, y, fitted.width, fitted.height, pixelWidth, pixelHeight, sourceX, sourceY, sourceWidth, sourceHeight, this._protocol);
@@ -16038,9 +16067,27 @@ class ImageRenderable2 extends Renderable2 {
16038
16067
  this.runCleanup((run) => {
16039
16068
  run(() => previous?.dispose());
16040
16069
  run(() => this.requestRender());
16070
+ run(() => this.acceptCrop(this._crop, image));
16041
16071
  run(() => this.onLoad?.(image));
16042
16072
  });
16043
16073
  }
16074
+ region() {
16075
+ const image = this._image;
16076
+ if (!image)
16077
+ return null;
16078
+ const crop = this._crop;
16079
+ if (crop && crop.left + crop.width <= image.width && crop.top + crop.height <= image.height)
16080
+ return crop;
16081
+ return { left: 0, top: 0, width: image.width, height: image.height };
16082
+ }
16083
+ acceptCrop(crop, image) {
16084
+ try {
16085
+ return crop && checkCrop2(crop, image?.width, image?.height);
16086
+ } catch (error) {
16087
+ queueMicrotask(() => this.isDestroyed || this.onError?.(error));
16088
+ return null;
16089
+ }
16090
+ }
16044
16091
  setNativeSceneImage(image = this._image, fit = this._fit, protocol = this._protocol) {
16045
16092
  this._ctx.nativeScene.setImage(this, image, fit, protocol, this.buffered ? this.frameBuffer : null);
16046
16093
  }
@@ -16530,6 +16577,15 @@ var scheduler = {
16530
16577
  }
16531
16578
  };
16532
16579
  var emptyOutput = new Uint8Array(0);
16580
+ var stdoutBudget = 65536;
16581
+ var immediatePolls = 64;
16582
+ var immediateAgeNs = 500000n;
16583
+ registerEnvVar2({
16584
+ name: "OTUI_STDOUT_THREAD",
16585
+ description: "Write terminal stdout from a native thread so slow links never block the JS thread; false keeps it on the JS thread.",
16586
+ type: "boolean",
16587
+ default: true
16588
+ });
16533
16589
 
16534
16590
  class ReadySessions {
16535
16591
  host;
@@ -16698,13 +16754,18 @@ class NativeSession2 {
16698
16754
  closeWait = completion();
16699
16755
  idleWait = null;
16700
16756
  presentationWait = null;
16757
+ imageUploadsPending = 0;
16701
16758
  transition = null;
16702
16759
  scheduled = null;
16703
16760
  output = null;
16761
+ stdoutPost = null;
16762
+ stdoutWriter;
16704
16763
  blocked = false;
16705
16764
  sinkErrorSeen = false;
16706
16765
  detached = false;
16707
16766
  closeDeadlineNs = null;
16767
+ closeCapNs = null;
16768
+ closeLate = null;
16708
16769
  closeRequested = false;
16709
16770
  closeInterruption = null;
16710
16771
  stopped = false;
@@ -16737,6 +16798,7 @@ class NativeSession2 {
16737
16798
  this.sinkWrite = sink.write;
16738
16799
  this.outputBufferSize = size;
16739
16800
  this.buffer = sink === process.stdout && process.stdout.fd === 1 ? null : new Uint8Array(size);
16801
+ this.stdoutWriter = this.buffer === null && env2.OTUI_STDOUT_THREAD !== false;
16740
16802
  this.scheduler = sessionScheduler(options.scheduler ?? scheduler, (error) => {
16741
16803
  if (this.stopped) {
16742
16804
  if (this.canDetach())
@@ -16794,6 +16856,9 @@ class NativeSession2 {
16794
16856
  get error() {
16795
16857
  return this._error;
16796
16858
  }
16859
+ get open() {
16860
+ return !this._error && !this.closeRequested && !this.exiting;
16861
+ }
16797
16862
  usesOutput(sink) {
16798
16863
  return this.sink === sink;
16799
16864
  }
@@ -16853,8 +16918,11 @@ class NativeSession2 {
16853
16918
  this.checkOpen();
16854
16919
  if (this.presentationWait)
16855
16920
  return this.presentationWait.promise;
16856
- if (!this.lib.sessionGetRendererState(this.context, this.session).framePending)
16921
+ const state = this.lib.sessionGetRendererState(this.context, this.session);
16922
+ if (!state.framePending) {
16923
+ this.imageUploadsPending = state.imageUploadsPending;
16857
16924
  return Promise.resolve();
16925
+ }
16858
16926
  const wait = this.presentationWait = completion();
16859
16927
  this.schedule();
16860
16928
  return wait.promise;
@@ -16954,6 +17022,7 @@ class NativeSession2 {
16954
17022
  try {
16955
17023
  this.closeRequested = true;
16956
17024
  this.closeDeadlineNs ??= this.scheduler.now() + this.closeTimeoutNs;
17025
+ this.closeCapNs ??= this.scheduler.now() + 10n * this.closeTimeoutNs;
16957
17026
  if (this.transition) {
16958
17027
  this.closeInterruption = new Error("NativeSession terminal transition interrupted by close");
16959
17028
  this.transition.wait.reject(this.closeInterruption);
@@ -16974,10 +17043,11 @@ class NativeSession2 {
16974
17043
  armCloseTimeout() {
16975
17044
  this.checkOpen();
16976
17045
  this.closeDeadlineNs ??= this.scheduler.now() + this.closeTimeoutNs;
17046
+ this.closeCapNs ??= this.scheduler.now() + 10n * this.closeTimeoutNs;
16977
17047
  this.schedule();
16978
17048
  }
16979
17049
  isCloseInterruption(error) {
16980
- return this.closeInterruption !== null && error === this.closeInterruption;
17050
+ return error != null && (error === this.closeInterruption || error === this.closeLate);
16981
17051
  }
16982
17052
  dispose() {
16983
17053
  this.lib.getYogaHost().assertMutable();
@@ -16997,6 +17067,10 @@ class NativeSession2 {
16997
17067
  this.lib.sessionCompleteOutput(this.context, this.session, this.output.ticket, true);
16998
17068
  this.output = null;
16999
17069
  }
17070
+ let viaWriter = this.stdoutWriter && (this.lib.sessionPostStdout(this.context, this.session, 0, true).written > 0 || !this.stdoutPost);
17071
+ this.stdoutPost = null;
17072
+ if (this.closeCapNs !== null)
17073
+ this.lib.sessionDropOutput(this.context, this.session);
17000
17074
  for (;; ) {
17001
17075
  const status = this.lib.sessionPumpExit(this.context, this.session);
17002
17076
  if (status === 4 /* Closed */)
@@ -17005,6 +17079,11 @@ class NativeSession2 {
17005
17079
  continue;
17006
17080
  if (status !== 2 /* OutputPending */)
17007
17081
  throw new Error("Unexpected native exit pump status");
17082
+ if (viaWriter) {
17083
+ if (this.exitThroughWriter())
17084
+ continue;
17085
+ viaWriter = false;
17086
+ }
17008
17087
  if (this.lib.sessionDrainStdout(this.context, this.session) === 0)
17009
17088
  return false;
17010
17089
  }
@@ -17013,12 +17092,23 @@ class NativeSession2 {
17013
17092
  return false;
17014
17093
  }
17015
17094
  }
17095
+ exitThroughWriter() {
17096
+ try {
17097
+ if (!this.lib.sessionPostStdout(this.context, this.session, stdoutBudget, false).inFlight)
17098
+ return false;
17099
+ } catch (error) {
17100
+ if (error instanceof NativeError2 && error.status === -24 /* UnsupportedResource */)
17101
+ return false;
17102
+ throw error;
17103
+ }
17104
+ return this.lib.sessionPostStdout(this.context, this.session, 0, true).written > 0;
17105
+ }
17016
17106
  checkOpen() {
17017
17107
  this.lib.getYogaHost().assertMutable();
17018
17108
  if (this._error)
17019
17109
  throw this._error;
17020
17110
  if (this.stopped || this.closeRequested)
17021
- throw new Error("NativeSession is closing or disposed");
17111
+ throw this.closeLate ?? new Error("NativeSession is closing or disposed");
17022
17112
  this.owner?.checkOpen();
17023
17113
  }
17024
17114
  changeTerminal(kind, options) {
@@ -17115,19 +17205,40 @@ class NativeSession2 {
17115
17205
  if (this._error)
17116
17206
  throw this._error;
17117
17207
  const now = this.scheduler.now();
17118
- const expired = this.closeDeadlineNs !== null && now >= this.closeDeadlineNs;
17208
+ const expired = !this.stdoutPost && this.closeDeadlineNs !== null && now >= this.closeDeadlineNs;
17209
+ const capped = !this.closeLate && this.closeCapNs !== null && now >= this.closeCapNs;
17119
17210
  if (this.output?.completed) {
17120
17211
  if (this.output.ticket)
17121
17212
  this.lib.sessionCompleteOutput(this.context, this.session, this.output.ticket, true);
17122
17213
  this.output = null;
17123
17214
  this.completePresentation();
17124
17215
  }
17125
- const result = this.output ? null : this.lib.sessionPump(this.context, this.session, now, 1);
17126
- if (expired && result?.status !== 4 /* Closed */) {
17127
- throw new Error("NativeSession graceful close timed out; output cancelled without restoration");
17216
+ const start = !capped && this.sink.writableLength === 0 && this.sink.writableCorked === 0;
17217
+ if (this.stdoutPost)
17218
+ this.postStdout(now, start);
17219
+ if (this.stdoutPost)
17220
+ deadlineNs = this.pollDeadline(now);
17221
+ const result = this.output || this.stdoutPost ? null : this.lib.sessionPump(this.context, this.session, now, 1);
17222
+ if ((expired || capped) && result?.status !== 4 /* Closed */) {
17223
+ if (this.closeLate) {
17224
+ throw new Error("NativeSession graceful close timed out; output cancelled without restoration");
17225
+ }
17226
+ this.closeLate = new Error("NativeSession graceful close ran late; queued output was dropped");
17227
+ this.closeRequested = true;
17228
+ this.lib.sessionDropOutput(this.context, this.session);
17229
+ this.presentationWait?.reject(this.closeLate);
17230
+ this.presentationWait = null;
17231
+ this.closeDeadlineNs = now + this.closeTimeoutNs;
17232
+ this.schedule();
17233
+ return;
17128
17234
  }
17129
- if (!result)
17235
+ if (!result) {
17236
+ if (deadlineNs === 0n) {
17237
+ deadlineNs = null;
17238
+ this.schedule();
17239
+ }
17130
17240
  return;
17241
+ }
17131
17242
  switch (result.status) {
17132
17243
  case 0 /* Idle */:
17133
17244
  if (this.transition) {
@@ -17154,14 +17265,15 @@ class NativeSession2 {
17154
17265
  deadlineNs = result.deadlineNs;
17155
17266
  break;
17156
17267
  case 4 /* Closed */:
17157
- this.finish(null);
17268
+ this.finish(this.closeLate);
17158
17269
  break;
17159
17270
  }
17160
17271
  } catch (error) {
17161
17272
  this.finish(asError(error));
17162
17273
  } finally {
17163
- if (this.closeDeadlineNs !== null && (deadlineNs === null || this.closeDeadlineNs < deadlineNs)) {
17164
- deadlineNs = this.closeDeadlineNs;
17274
+ for (const closeNs of [this.stdoutPost ? null : this.closeDeadlineNs, this.closeLate ? null : this.closeCapNs]) {
17275
+ if (closeNs !== null && (deadlineNs === null || closeNs < deadlineNs))
17276
+ deadlineNs = closeNs;
17165
17277
  }
17166
17278
  if (deadlineNs !== null)
17167
17279
  this.schedule(deadlineNs);
@@ -17173,10 +17285,25 @@ class NativeSession2 {
17173
17285
  this.writeSink(emptyOutput, null);
17174
17286
  return;
17175
17287
  }
17288
+ if (this.stdoutWriter) {
17289
+ const now = this.scheduler.now();
17290
+ try {
17291
+ this.postStdout(now, true);
17292
+ this.schedule();
17293
+ return;
17294
+ } catch (error) {
17295
+ if (!(error instanceof NativeError2) || error.status !== -24 /* UnsupportedResource */)
17296
+ throw error;
17297
+ this.stdoutWriter = false;
17298
+ }
17299
+ }
17176
17300
  try {
17177
17301
  const written = this.lib.sessionDrainStdout(this.context, this.session);
17302
+ const now = this.scheduler.now();
17303
+ if (written > 0 && this.closeDeadlineNs !== null)
17304
+ this.closeDeadlineNs = now + this.closeTimeoutNs;
17178
17305
  this.completePresentation();
17179
- this.schedule(written === 0 ? this.scheduler.now() + 1000000n : null);
17306
+ this.schedule(written === 0 ? now + 1000000n : null);
17180
17307
  return;
17181
17308
  } catch (error) {
17182
17309
  if (!(error instanceof NativeError2) || error.status !== -24 /* UnsupportedResource */)
@@ -17191,6 +17318,27 @@ class NativeSession2 {
17191
17318
  throw new Error("NativeSession output ticket exceeds its buffer");
17192
17319
  this.writeSink(this.buffer.subarray(0, ticket.byteCount), ticket);
17193
17320
  }
17321
+ postStdout(now, start) {
17322
+ const posted = this.stdoutPost;
17323
+ const { written, inFlight } = this.lib.sessionPostStdout(this.context, this.session, start ? stdoutBudget : 0, false);
17324
+ if (written > 0)
17325
+ this.completePresentation();
17326
+ if (this.closeDeadlineNs !== null)
17327
+ this.closeDeadlineNs = now + this.closeTimeoutNs;
17328
+ if (!inFlight)
17329
+ this.stdoutPost = null;
17330
+ else if (!posted || written > 0)
17331
+ this.stdoutPost = { since: now, polls: 0 };
17332
+ else
17333
+ posted.polls++;
17334
+ }
17335
+ pollDeadline(now) {
17336
+ const post = this.stdoutPost;
17337
+ if (post.polls < immediatePolls && now - post.since < immediateAgeNs)
17338
+ return 0n;
17339
+ const age = (now - post.since) / 8n;
17340
+ return now + (age < 1000000n ? 1000000n : age > 50000000n ? 50000000n : age);
17341
+ }
17194
17342
  writeSink(bytes, ticket) {
17195
17343
  if (this.output)
17196
17344
  throw new Error("NativeSession output is already in flight");
@@ -17217,7 +17365,11 @@ class NativeSession2 {
17217
17365
  }
17218
17366
  }
17219
17367
  completePresentation() {
17220
- if (this.presentationWait && !this.lib.sessionGetRendererState(this.context, this.session).framePending) {
17368
+ if (!this.presentationWait)
17369
+ return;
17370
+ const state = this.lib.sessionGetRendererState(this.context, this.session);
17371
+ if (!state.framePending) {
17372
+ this.imageUploadsPending = state.imageUploadsPending;
17221
17373
  this.presentationWait.resolve();
17222
17374
  this.presentationWait = null;
17223
17375
  }
@@ -17350,6 +17502,8 @@ class Capture extends EventEmitter6 {
17350
17502
  return this.output.length;
17351
17503
  }
17352
17504
  write(stream, data) {
17505
+ if (this.output.length >= 1000)
17506
+ this.output.shift();
17353
17507
  this.output.push({ stream, output: data });
17354
17508
  this.emit("write", stream, data);
17355
17509
  }
@@ -19426,6 +19580,7 @@ class EditBufferRenderable2 extends Renderable2 {
19426
19580
  // src/renderer.ts
19427
19581
  import { appendFileSync, writeFileSync } from "node:fs";
19428
19582
  import { Writable as Writable3 } from "node:stream";
19583
+ import { StringDecoder } from "node:string_decoder";
19429
19584
 
19430
19585
  // src/ansi.ts
19431
19586
  var ANSI = {
@@ -19744,6 +19899,19 @@ class NativeScene {
19744
19899
  const { renderLib: lib, context } = this.driver;
19745
19900
  lib.sceneSetImage(context, renderable._getSceneHandle(this), image?._getContextHandle(lib, context) ?? null, fit, protocol, buffer?._getSceneHandle(this) ?? null);
19746
19901
  }
19902
+ setVideo(renderable, fit, buffer) {
19903
+ this.flushStaged();
19904
+ const { renderLib: lib, context } = this.driver;
19905
+ lib.sceneSetVideo(context, renderable._getSceneHandle(this), fit, buffer?._getSceneHandle(this) ?? null);
19906
+ }
19907
+ setCrop(renderable, crop) {
19908
+ this.flushStaged();
19909
+ this.driver.renderLib.sceneSetCrop(this.driver.context, renderable._getSceneHandle(this), crop);
19910
+ }
19911
+ videoNode(renderable) {
19912
+ this.flushStaged();
19913
+ return { lib: this.driver.renderLib, context: this.driver.context, node: renderable._getSceneHandle(this) };
19914
+ }
19747
19915
  setScroll(renderable, options) {
19748
19916
  this.flushStaged();
19749
19917
  this.driver.renderLib.sceneSetScroll(this.driver.context, renderable._getSceneHandle(this), options);
@@ -20901,6 +21069,9 @@ function snapshotRowWidths(snapshot, rowColumns) {
20901
21069
  return widths;
20902
21070
  });
20903
21071
  }
21072
+ var CAPTURED_STDOUT_MAX_BYTES = 64 * 1024 * 1024;
21073
+ var CAPTURED_STDOUT_HIGH_WATER_BYTES = CAPTURED_STDOUT_MAX_BYTES / 2;
21074
+ var capturedRowBytes = (cells) => 3072 + 48 * cells;
20904
21075
  function runCleanups(cleanups) {
20905
21076
  let failure;
20906
21077
  for (const cleanup of cleanups) {
@@ -20916,9 +21087,13 @@ function runCleanups(cleanups) {
20916
21087
 
20917
21088
  class ExternalOutputQueue {
20918
21089
  maxCells;
21090
+ onDrain;
20919
21091
  commits = [];
20920
- constructor(maxCells) {
21092
+ capturedBytes = 0;
21093
+ drainPending = false;
21094
+ constructor(maxCells, onDrain) {
20921
21095
  this.maxCells = maxCells;
21096
+ this.onDrain = onDrain;
20922
21097
  }
20923
21098
  owns(snapshot) {
20924
21099
  return this.commits.some((commit) => commit.snapshot === snapshot);
@@ -20926,7 +21101,7 @@ class ExternalOutputQueue {
20926
21101
  get size() {
20927
21102
  return this.commits.length;
20928
21103
  }
20929
- writeSnapshots(commits) {
21104
+ writeSnapshots(commits, captured) {
20930
21105
  for (const { rowColumns, snapshot } of commits) {
20931
21106
  if (!Number.isInteger(rowColumns) || rowColumns < 0 || rowColumns > snapshot.width) {
20932
21107
  throw new RangeError("Scrollback commit rowColumns must be an integer from 0 to the snapshot width");
@@ -20935,15 +21110,91 @@ class ExternalOutputQueue {
20935
21110
  throw new Error("Scrollback snapshot exceeds the Session output capacity");
20936
21111
  }
20937
21112
  }
20938
- const entries = commits.map((commit) => ({
20939
- ...commit,
20940
- cells: commit.snapshot.width * commit.snapshot.height,
20941
- rowWidths: snapshotRowWidths(commit.snapshot, commit.rowColumns)
20942
- }));
20943
- for (const entry of entries)
21113
+ const entries = commits.map((commit) => this.entry(commit, captured, 0));
21114
+ for (const entry of entries) {
20944
21115
  this.commits.push(entry);
21116
+ this.capturedBytes += entry.bytes;
21117
+ }
20945
21118
  return entries;
20946
21119
  }
21120
+ entry(commit, captured, dropped) {
21121
+ const cells = commit.snapshot.width * commit.snapshot.height;
21122
+ const rowWidths = snapshotRowWidths(commit.snapshot, commit.rowColumns);
21123
+ return { ...commit, cells, rowWidths, bytes: captured ? capturedRowBytes(cells) : 0, dropped };
21124
+ }
21125
+ writable() {
21126
+ if (this.capturedBytes >= CAPTURED_STDOUT_HIGH_WATER_BYTES)
21127
+ this.drainPending = true;
21128
+ return !this.drainPending;
21129
+ }
21130
+ takeDrain(force = false) {
21131
+ if (!this.drainPending || !force && this.capturedBytes >= CAPTURED_STDOUT_HIGH_WATER_BYTES)
21132
+ return false;
21133
+ this.drainPending = false;
21134
+ return true;
21135
+ }
21136
+ collapse(limits, marker) {
21137
+ if (this.capturedBytes <= CAPTURED_STDOUT_MAX_BYTES && limits.trimmed === 0)
21138
+ return null;
21139
+ const kept = [];
21140
+ const removed = new Set;
21141
+ const runs = [];
21142
+ let bytes = this.capturedBytes;
21143
+ let open = false;
21144
+ let partial = false;
21145
+ let boundary = -1;
21146
+ const endRow = () => {
21147
+ if (partial)
21148
+ runs.at(-1).rows += 1;
21149
+ partial = false;
21150
+ };
21151
+ const close = () => {
21152
+ endRow();
21153
+ open = false;
21154
+ };
21155
+ for (const [index, commit] of this.commits.entries()) {
21156
+ if (index === limits.boundary) {
21157
+ close();
21158
+ boundary = kept.length + runs.length;
21159
+ }
21160
+ if (index === limits.incoming && limits.trimmed > 0) {
21161
+ if (!open)
21162
+ runs.push({ index: kept.length, rows: 0 });
21163
+ runs.at(-1).rows += limits.trimmed;
21164
+ open = true;
21165
+ partial = false;
21166
+ }
21167
+ if (index < limits.start || commit.bytes === 0 || bytes <= CAPTURED_STDOUT_HIGH_WATER_BYTES && !partial) {
21168
+ if (commit.bytes === 0)
21169
+ endRow();
21170
+ else
21171
+ close();
21172
+ kept.push(commit);
21173
+ continue;
21174
+ }
21175
+ if (!open)
21176
+ runs.push({ index: kept.length, rows: 0 });
21177
+ open = true;
21178
+ partial = !commit.endsRow;
21179
+ runs.at(-1).rows += commit.dropped || (commit.endsRow ? 1 : 0);
21180
+ removed.add(commit.snapshot);
21181
+ bytes -= commit.bytes;
21182
+ }
21183
+ close();
21184
+ if (runs.length === 0)
21185
+ return null;
21186
+ const markers = runs.map((run) => marker(run.rows));
21187
+ for (let run = runs.length - 1;run >= 0; run--) {
21188
+ const entry = this.entry(markers[run], true, runs[run].rows);
21189
+ kept.splice(runs[run].index, 0, entry);
21190
+ this.capturedBytes += entry.bytes;
21191
+ }
21192
+ const gone = this.commits.filter((commit) => removed.has(commit.snapshot));
21193
+ this.commits = kept;
21194
+ this.drainPending = true;
21195
+ this.release(gone, false);
21196
+ return { markers, removed, boundary: boundary < 0 ? kept.length : boundary };
21197
+ }
20947
21198
  batch(limit) {
20948
21199
  if (!(limit >= 1))
20949
21200
  throw new RangeError("ExternalOutputQueue.batch requires a limit of at least 1");
@@ -20966,8 +21217,15 @@ class ExternalOutputQueue {
20966
21217
  return output;
20967
21218
  }
20968
21219
  drop(count) {
20969
- for (const commit of this.commits.splice(0, count))
21220
+ this.release(this.commits.splice(0, count));
21221
+ }
21222
+ release(removed, drain = true) {
21223
+ for (const commit of removed) {
21224
+ this.capturedBytes -= commit.bytes;
20970
21225
  commit.snapshot.destroy();
21226
+ }
21227
+ if (drain && this.drainPending && this.capturedBytes < CAPTURED_STDOUT_HIGH_WATER_BYTES)
21228
+ this.onDrain();
20971
21229
  }
20972
21230
  clear() {
20973
21231
  this.drop(this.commits.length);
@@ -21246,6 +21504,7 @@ var CliRenderEvents2;
21246
21504
  CliRenderEvents["RESIZE"] = "resize";
21247
21505
  CliRenderEvents["FRAME"] = "frame";
21248
21506
  CliRenderEvents["RENDER_ERROR"] = "render:error";
21507
+ CliRenderEvents["FRAME_DROPPED"] = "frame:dropped";
21249
21508
  CliRenderEvents["HANDLER_ERROR"] = "handler:error";
21250
21509
  CliRenderEvents["EXTERNAL_OUTPUT"] = "external_output";
21251
21510
  CliRenderEvents["FOCUS"] = "focus";
@@ -21402,11 +21661,15 @@ class CliRenderer2 extends EventEmitter8 {
21402
21661
  pendingSplitFooterTransition = null;
21403
21662
  forceFullRepaintRequested = false;
21404
21663
  maxSplitCommitsPerFrame = 8;
21664
+ splitCommitLimit = this.maxSplitCommitsPerFrame;
21665
+ droppedFrames = 0;
21666
+ dropRetried = false;
21405
21667
  _terminalWidth = 0;
21406
21668
  _terminalHeight = 0;
21407
21669
  _terminalIsSetup = false;
21408
21670
  externalOutputQueue;
21409
21671
  pendingExternalOutputMode = null;
21672
+ stdoutDecoder = new StringDecoder("utf8");
21410
21673
  realStdoutWrite;
21411
21674
  _useConsole = true;
21412
21675
  sigwinchHandler = (() => {
@@ -21579,7 +21842,7 @@ Captured external output:
21579
21842
  }
21580
21843
  });
21581
21844
  this.nativeSession = driver;
21582
- this.externalOutputQueue = new ExternalOutputQueue(Number(driver.maxWriteBytes / 24n));
21845
+ this.externalOutputQueue = new ExternalOutputQueue(Number(driver.maxWriteBytes / 24n), () => process.nextTick(() => !this._isDestroyed && this.externalOutputQueue.takeDrain() && this.stdout.emit("drain")));
21583
21846
  this.nativeDestroyWait = Promise.withResolvers();
21584
21847
  this.nativeClosed = this.nativeSession.closed.finally(() => this.nativeDestroyWait.promise).finally(() => {
21585
21848
  if (this.nativeSession.error && !this.nativeSession.disposed)
@@ -22071,6 +22334,9 @@ Captured external output:
22071
22334
  this.applyExternalOutputMode(mode);
22072
22335
  return;
22073
22336
  }
22337
+ if (mode === "passthrough" && !this.rendering && !this.pendingNativeMode && this.externalOutputQueue.size === 0) {
22338
+ this.flushStdoutDecoder();
22339
+ }
22074
22340
  if (this.rendering || this.pendingNativeMode || this.externalOutputQueue.size > 0) {
22075
22341
  this.pendingExternalOutputMode = mode;
22076
22342
  this.requestRender();
@@ -22127,6 +22393,11 @@ Captured external output:
22127
22393
  if (pendingMode === null || this.externalOutputQueue.size > 0 && !(pendingMode === "capture-stdout" && this._screenMode === "split-footer")) {
22128
22394
  return;
22129
22395
  }
22396
+ if (pendingMode === "passthrough") {
22397
+ this.flushStdoutDecoder();
22398
+ if (this.externalOutputQueue.size > 0)
22399
+ return;
22400
+ }
22130
22401
  const previousMode = this._externalOutputMode;
22131
22402
  this.pendingExternalOutputMode = null;
22132
22403
  if (previousMode === pendingMode) {
@@ -22189,7 +22460,7 @@ Captured external output:
22189
22460
  return this.nativeSession.triggerNotification(message, title);
22190
22461
  }
22191
22462
  setProgramStatus(status) {
22192
- if (this._isDestroyed)
22463
+ if (!this.nativeSession.open)
22193
22464
  return false;
22194
22465
  return this.nativeSession.setProgramStatus(status);
22195
22466
  }
@@ -22547,6 +22818,7 @@ Captured external output:
22547
22818
  if (!this._terminalIsSetup || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
22548
22819
  throw new Error("resetSplitFooterForReplay requires an active terminal");
22549
22820
  }
22821
+ this.flushStdoutDecoder();
22550
22822
  if (this.rendering || this.externalOutputQueue.size > 0) {
22551
22823
  this.pendingNativeReplay = { options, remaining: this.externalOutputQueue.size };
22552
22824
  this.requestRender();
@@ -22634,24 +22906,27 @@ Captured external output:
22634
22906
  }
22635
22907
  ]);
22636
22908
  }
22637
- enqueueSplitCommits(commits) {
22909
+ enqueueSplitCommits(commits, captured = false) {
22638
22910
  for (const commit of commits)
22639
22911
  commit.nativeSnapshot = commit.snapshot._getSceneHandle(this.nativeScene);
22640
22912
  const width = Math.max(this.width, 1);
22641
22913
  let column = this.getPendingSplitTailColumn();
22642
- for (const entry of this.externalOutputQueue.writeSnapshots(commits)) {
22914
+ for (const entry of this.externalOutputQueue.writeSnapshots(commits, captured)) {
22643
22915
  column = this.getSplitTailColumnAfterCommit(entry, column, width);
22644
22916
  }
22645
22917
  this.queuedSplitTail = { column, width };
22646
22918
  this.requestRender();
22919
+ if (!captured)
22920
+ this.emitExternalOutput(commits);
22921
+ }
22922
+ emitExternalOutput(commits) {
22647
22923
  if (this.listenerCount("external_output" /* EXTERNAL_OUTPUT */) > 0) {
22648
22924
  for (const commit of commits)
22649
22925
  this.emit("external_output" /* EXTERNAL_OUTPUT */, commit);
22650
22926
  }
22651
22927
  }
22652
- splitStdoutRows(text) {
22928
+ splitStdoutRows(text, tailColumn) {
22653
22929
  const width = Math.max(1, this.width);
22654
- const tailColumn = this.getPendingSplitTailColumn();
22655
22930
  const rows = [];
22656
22931
  let rowStart = 0;
22657
22932
  let line = "";
@@ -22666,7 +22941,7 @@ Captured external output:
22666
22941
  if (segment === `
22667
22942
  ` || segment === `\r
22668
22943
  `) {
22669
- rows.push({ line, cells, trailingNewline: true });
22944
+ rows.push({ line, cells, trailingNewline: true, endsRow: true });
22670
22945
  rowStart = rows.length;
22671
22946
  line = "";
22672
22947
  cells = 0;
@@ -22678,7 +22953,7 @@ Captured external output:
22678
22953
  const graphemeCells = stringWidth(grapheme);
22679
22954
  if (column > 0 && column + graphemeCells > width) {
22680
22955
  const padding = Math.max(0, width - column);
22681
- rows.push({ line: line + " ".repeat(padding), cells: cells + padding, trailingNewline: false });
22956
+ rows.push({ line: line + " ".repeat(padding), cells: cells + padding, trailingNewline: false, endsRow: true });
22682
22957
  line = "";
22683
22958
  cells = 0;
22684
22959
  }
@@ -22686,12 +22961,12 @@ Captured external output:
22686
22961
  cells += graphemeCells;
22687
22962
  }
22688
22963
  if (line.length > 0) {
22689
- rows.push({ line, cells, trailingNewline: false });
22964
+ const column = (rows.length === 0 && tailColumn < width ? tailColumn : 0) + cells;
22965
+ rows.push({ line, cells, trailingNewline: false, endsRow: column >= width });
22690
22966
  }
22691
22967
  return rows;
22692
22968
  }
22693
- createStdoutSnapshotCommits(text) {
22694
- const rows = this.splitStdoutRows(text);
22969
+ createStdoutSnapshotCommits(rows) {
22695
22970
  if (rows.length === 0) {
22696
22971
  return [];
22697
22972
  }
@@ -22708,7 +22983,7 @@ Captured external output:
22708
22983
  height: 1
22709
22984
  });
22710
22985
  snapshotRoot.add(snapshotRenderable);
22711
- for (const { line, cells, trailingNewline } of rows) {
22986
+ for (const { line, cells, trailingNewline, endsRow } of rows) {
22712
22987
  const snapshotWidth = Math.max(1, cells);
22713
22988
  snapshotContext.width = snapshotWidth;
22714
22989
  snapshotRoot.resize(snapshotWidth, 1);
@@ -22718,7 +22993,7 @@ Captured external output:
22718
22993
  id: "captured-stdout-snapshot",
22719
22994
  owner: this.nativeScene
22720
22995
  });
22721
- commits.push({ snapshot, rowColumns: cells, startOnNewLine: false, trailingNewline });
22996
+ commits.push({ snapshot, rowColumns: cells, startOnNewLine: false, trailingNewline, endsRow });
22722
22997
  snapshotContext.renderSnapshot(snapshotRoot, snapshot);
22723
22998
  }
22724
22999
  return commits;
@@ -22730,27 +23005,62 @@ Captured external output:
22730
23005
  runCleanups([() => snapshotRoot?.destroyRecursively(), () => snapshotContext.destroy()]);
22731
23006
  }
22732
23007
  }
23008
+ flushStdoutDecoder() {
23009
+ const text = this.stdoutDecoder.end();
23010
+ if (text && this.nativeSession.open)
23011
+ this.interceptStdoutWrite(text);
23012
+ }
22733
23013
  interceptStdoutWrite = (chunk, encoding, callback) => {
22734
23014
  const resolvedCallback = typeof encoding === "function" ? encoding : callback;
22735
- const resolvedEncoding = typeof encoding === "string" ? encoding : undefined;
22736
- const text = typeof chunk === "string" ? chunk : chunk?.toString(resolvedEncoding) ?? "";
23015
+ let writable = true;
22737
23016
  if (this._externalOutputMode === "capture-stdout" && this._screenMode === "split-footer" && this._splitHeight > 0) {
22738
- const commits = this.createStdoutSnapshotCommits(text);
23017
+ const bytes = ArrayBuffer.isView(chunk) ? new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength) : Buffer.from(String(chunk ?? ""), Buffer.isEncoding(encoding) ? encoding : undefined);
23018
+ const text = this.stdoutDecoder.write(bytes);
23019
+ const queue = this.externalOutputQueue;
23020
+ const rows = this.splitStdoutRows(text, this.getPendingSplitTailColumn());
23021
+ let added = rows.reduce((sum, row) => sum + capturedRowBytes(Math.max(1, row.cells)), 0);
23022
+ let trimmed = 0;
23023
+ if (queue.capturedBytes + added > CAPTURED_STDOUT_MAX_BYTES) {
23024
+ while (added > CAPTURED_STDOUT_HIGH_WATER_BYTES)
23025
+ added -= capturedRowBytes(Math.max(1, rows[trimmed++].cells));
23026
+ }
23027
+ const commits = this.createStdoutSnapshotCommits(rows.slice(trimmed));
22739
23028
  try {
22740
- this.enqueueSplitCommits(commits);
23029
+ this.enqueueSplitCommits(commits, true);
22741
23030
  } catch (error) {
22742
23031
  for (const commit of commits) {
22743
- if (!this.externalOutputQueue.owns(commit.snapshot))
23032
+ if (!queue.owns(commit.snapshot))
22744
23033
  commit.snapshot.destroy();
22745
23034
  }
22746
23035
  throw error;
22747
23036
  }
23037
+ const limits = {
23038
+ start: this.nativeSplitAcceptedCount,
23039
+ boundary: this.pendingNativeReplay?.remaining ?? Infinity,
23040
+ incoming: queue.size - commits.length,
23041
+ trimmed
23042
+ };
23043
+ const collapsed = queue.collapse(limits, (rows2) => this.createDroppedRowCommit(rows2));
23044
+ if (collapsed) {
23045
+ this.queuedSplitTail = null;
23046
+ if (this.pendingNativeReplay)
23047
+ this.pendingNativeReplay.remaining = collapsed.boundary;
23048
+ }
23049
+ this.emitExternalOutput(collapsed?.markers ?? []);
23050
+ this.emitExternalOutput(commits.filter((commit) => !collapsed?.removed.has(commit.snapshot)));
23051
+ writable = queue.writable();
22748
23052
  }
22749
23053
  if (typeof resolvedCallback === "function") {
22750
23054
  process.nextTick(resolvedCallback);
22751
23055
  }
22752
- return true;
23056
+ return writable;
22753
23057
  };
23058
+ createDroppedRowCommit(rows) {
23059
+ const text = `[${rows} lines dropped]`.slice(0, Math.max(1, this.width));
23060
+ const [commit] = this.createStdoutSnapshotCommits(this.splitStdoutRows(text, 0));
23061
+ commit.nativeSnapshot = commit.snapshot._getSceneHandle(this.nativeScene);
23062
+ return { ...commit, startOnNewLine: true, trailingNewline: true, endsRow: true };
23063
+ }
22754
23064
  getSplitPinnedRenderOffset() {
22755
23065
  return this._screenMode === "split-footer" ? Math.max(this._terminalHeight - this._splitHeight, 0) : 0;
22756
23066
  }
@@ -24075,6 +24385,7 @@ Captured external output:
24075
24385
  if (!this._terminalIsSetup || this.nativeTerminalTransition) {
24076
24386
  throw new Error("Native scene suspension requires completed terminal setup and no pending transition");
24077
24387
  }
24388
+ this.flushStdoutDecoder();
24078
24389
  const flushNativeSplit = this.externalOutputQueue.size > 0 || this.pendingNativeReplay;
24079
24390
  if (flushNativeSplit)
24080
24391
  this.lib.getYogaHost().assertMutable();
@@ -24241,10 +24552,14 @@ Captured external output:
24241
24552
  this.nativeSession.close();
24242
24553
  } catch (error) {
24243
24554
  this.externalOutputQueue.clear();
24244
- this.nativeSession.dispose();
24245
- console.error("Native split output cancelled during close:", error);
24555
+ if (!this.nativeSession.isCloseInterruption(error)) {
24556
+ this.nativeSession.dispose();
24557
+ console.error("Native split output cancelled during close:", error);
24558
+ }
24246
24559
  }
24247
24560
  });
24561
+ const drain = () => this.externalOutputQueue.takeDrain(true) && this.stdout.emit("drain");
24562
+ this.nativeClosed.then(drain, drain);
24248
24563
  this.finalizeDestroy();
24249
24564
  }
24250
24565
  cleanupBeforeDestroy() {
@@ -24307,6 +24622,7 @@ Captured external output:
24307
24622
  } catch (e) {
24308
24623
  console.error("Error pausing stdin during destroy:", e);
24309
24624
  }
24625
+ this.flushStdoutDecoder();
24310
24626
  this.externalOutputMode = "passthrough";
24311
24627
  }
24312
24628
  finalizeDestroy() {
@@ -24562,6 +24878,10 @@ Captured external output:
24562
24878
  } else {
24563
24879
  this.clearFrameTimer();
24564
24880
  }
24881
+ } else if (nativeStatus === "dropped" && (this._isRunning || this.immediateRerenderRequested)) {
24882
+ const immediate = this.immediateRerenderRequested;
24883
+ this.immediateRerenderRequested = false;
24884
+ this.scheduleFrame(immediate ? this.minTargetFrameTime : this.targetFrameTime);
24565
24885
  } else {
24566
24886
  this.immediateRerenderRequested = false;
24567
24887
  this.clearFrameTimer();
@@ -24569,7 +24889,7 @@ Captured external output:
24569
24889
  }
24570
24890
  } catch (error) {
24571
24891
  renderFailed = true;
24572
- if (this.canRender) {
24892
+ if (this.canRender && !this.nativeSession.isCloseInterruption(error)) {
24573
24893
  const renderError = error instanceof Error ? error : new Error(String(error));
24574
24894
  const event = { error: renderError, renderable: this.root.takeCurrentRenderable() };
24575
24895
  const handled = this.emit("render:error" /* RENDER_ERROR */, event);
@@ -24626,10 +24946,40 @@ Captured external output:
24626
24946
  this.ordinaryFrameWaitControlState = this._controlState;
24627
24947
  this.loop();
24628
24948
  }
24949
+ handleDroppedFrame(commits) {
24950
+ const state = this.lib.sessionGetRendererState(this.nativeSession.context, this.nativeSession.session);
24951
+ if (state.droppedFrameBytes === 0)
24952
+ return false;
24953
+ const counted = state.droppedFrames !== this.droppedFrames;
24954
+ this.droppedFrames = state.droppedFrames;
24955
+ if (commits && commits.length > 1) {
24956
+ this.splitCommitLimit = 1;
24957
+ return true;
24958
+ }
24959
+ if (!commits?.length) {
24960
+ if (!counted && !this.dropRetried)
24961
+ this.requestRender();
24962
+ this.dropRetried = true;
24963
+ }
24964
+ if (commits?.length === 1) {
24965
+ this.externalOutputQueue.drop(1);
24966
+ this.queuedSplitTail = null;
24967
+ if (this.pendingNativeReplay)
24968
+ this.pendingNativeReplay.remaining -= 1;
24969
+ }
24970
+ if (counted) {
24971
+ const event = {
24972
+ bytes: state.droppedFrameBytes,
24973
+ limit: Number(this.nativeSession.maxAtomicWriteBytes)
24974
+ };
24975
+ this.emit("frame:dropped" /* FRAME_DROPPED */, event);
24976
+ }
24977
+ return true;
24978
+ }
24629
24979
  async presentNativeScene() {
24630
24980
  if (this.isSplitCursorSeedFrameBlocked())
24631
24981
  return "blocked";
24632
- const commits = this._splitHeight > 0 && this._externalOutputMode === "capture-stdout" ? this.pendingNativeReplay?.remaining === 0 ? [] : this.externalOutputQueue.batch(Math.min(this.maxSplitCommitsPerFrame, this.pendingNativeReplay?.remaining ?? Infinity)) : null;
24982
+ const commits = this._splitHeight > 0 && this._externalOutputMode === "capture-stdout" ? this.pendingNativeReplay?.remaining === 0 ? [] : this.externalOutputQueue.batch(Math.min(this.splitCommitLimit, this.pendingNativeReplay?.remaining ?? Infinity)) : null;
24633
24983
  const split = commits === null ? null : this.nativeScene.commitSplit(commits.map((commit) => ({ ...commit, snapshot: commit.nativeSnapshot })), this.getSplitPinnedRenderOffset(), this.forceFullRepaintRequested);
24634
24984
  const status = split?.status ?? this.nativeScene.commit(this.forceFullRepaintRequested);
24635
24985
  if (commits && (status === 1 /* Pending */ || status === 0 /* Presented */)) {
@@ -24646,6 +24996,11 @@ Captured external output:
24646
24996
  this.scheduleRenderAfterOutputIdle();
24647
24997
  return "retryable-skip";
24648
24998
  case 3 /* Failed */:
24999
+ if (this.handleDroppedFrame(commits)) {
25000
+ if (commits?.length)
25001
+ this.requestRender();
25002
+ return "dropped";
25003
+ }
24649
25004
  console.error("[CliRenderer] Native frame render failed; waiting for the next render request to force repaint");
24650
25005
  return "failed";
24651
25006
  default:
@@ -24661,6 +25016,9 @@ Captured external output:
24661
25016
  this.applyPendingExternalOutputModeIfReady();
24662
25017
  }
24663
25018
  this.forceFullRepaintRequested = false;
25019
+ this.dropRetried = false;
25020
+ if (status === 1 /* Pending */ && this.nativeSession.imageUploadsPending)
25021
+ this.requestRender();
24664
25022
  return "rendered";
24665
25023
  }
24666
25024
  completeNativeSplitCommits(commits) {
@@ -24672,6 +25030,7 @@ Captured external output:
24672
25030
  this.externalOutputQueue.drop(commits.length);
24673
25031
  if (this.pendingNativeReplay)
24674
25032
  this.pendingNativeReplay.remaining -= commits.length;
25033
+ this.splitCommitLimit = this.maxSplitCommitsPerFrame;
24675
25034
  this.nativeSplitAcceptedCount = 0;
24676
25035
  this.pendingSplitFooterTransition = null;
24677
25036
  }
@@ -24694,19 +25053,26 @@ Captured external output:
24694
25053
  continue;
24695
25054
  }
24696
25055
  }
25056
+ remaining = Math.min(remaining, this.externalOutputQueue.size);
24697
25057
  if (remaining === 0)
24698
25058
  break;
24699
- const commits = this.externalOutputQueue.batch(Math.min(remaining, this.maxSplitCommitsPerFrame, this.pendingNativeReplay?.remaining ?? Infinity));
25059
+ const commits = this.externalOutputQueue.batch(Math.min(remaining, this.splitCommitLimit, this.pendingNativeReplay?.remaining ?? Infinity));
24700
25060
  if (this.lib.sessionGetRendererState(driver.context, driver.session).framePending) {
24701
25061
  throw new Error("Native split output flush requires no pending frame presentation");
24702
25062
  }
24703
25063
  const result = driver.renderSplit(null, commits.map((commit) => ({ ...commit, snapshot: commit.nativeSnapshot })), this.getSplitPinnedRenderOffset(), false);
24704
- if (result.status === 3 /* Failed */)
24705
- throw new Error("Native split output frame failed");
25064
+ if (result.status === 3 /* Failed */) {
25065
+ if (!this.handleDroppedFrame(commits))
25066
+ throw new Error("Native split output frame failed");
25067
+ if (commits.length === 1)
25068
+ remaining -= 1;
25069
+ continue;
25070
+ }
24706
25071
  if (result.status === 2 /* Skipped */) {
24707
25072
  await driver.idle();
24708
25073
  continue;
24709
25074
  }
25075
+ this.nativeSplitAcceptedCount = commits.length;
24710
25076
  await driver.whenPresented();
24711
25077
  remaining -= commits.length;
24712
25078
  this.completeNativeSplitCommits(commits);
@@ -25089,7 +25455,7 @@ Captured external output:
25089
25455
  }
25090
25456
  }
25091
25457
 
25092
- export { isValidBorderStyle2, parseBorderStyle2, BorderChars2, getBorderFromSides2, getBorderSides2, borderCharsToArray2, BorderCharArrays2, KeyEvent2, PasteEvent2, KeyHandler2, InternalKeyHandler2, fonts2, measureText2, getCharacterPositions2, coordinateToCharacterIndex2, renderFontToFrameBuffer2, hastToStyledText2, SystemClock2, nonAlphanumericKeys2, terminalNamedSingleStrokeKeys2, parseKeypress2, LinearScrollAccel2, MacOSScrollAccel2, parseAlign2, parseAlignItems2, parseBoxSizing2, parseDimension2, parseDirection2, parseDisplay2, parseEdge2, parseFlexDirection2, parseGutter2, parseJustify2, parseLogLevel2, parseMeasureMode2, parseOverflow2, parsePositionType2, parseUnit2, parseWrap2, MouseParser2, Selection2, convertGlobalToLocalSelection2, ASCIIFontSelectionHelper2, StdinParser2, addDefaultParsers2, TreeSitterClient2, treeSitterToTextChunks2, treeSitterToStyledText2, DataPathsManager2, getDataPaths2, extensionToFiletype2, basenameToFiletype2, extToFiletype2, pathToFiletype2, infoStringToFiletype2, getTreeSitterClient2, destroyTreeSitterClient2, ExtmarksController2, createExtmarksController2, TerminalPalette2, createTerminalPalette2, normalizeTerminalPalette2, buildTerminalPaletteSignature2, decodePasteBytes2, stripAnsiSequences2, createHostClipboard2, createClipboard2, ClipboardTarget2, createRendererClipboardAdapter2, normalizeMarkdownLinkTarget, detectLinks2, acquireSessionBufferLease2, ResourceContext2, OptimizedBuffer2, h2, isVNode2, maybeMakeRenderable2, wrapWithDelegates2, instantiate2, delegate2, LayoutEvents2, RenderableEvents2, isRenderable2, BaseRenderable2, Renderable2, RootRenderable2, TextBuffer2, TextBufferView2, EditBuffer2, measureEditText2, EditorView2, Timeline2, engine2, getTimelineEngine2, createTimeline2, ANSI, BoxRenderable2, wheelDirection, scrollOnce, TextBufferRenderable2, CodeRenderable2, ImageLoadError2, ImageError2, imageInfo2, NativeImage2, NativeImagePool2, resolveImageRenderProtocol2, ImageRenderable2, isTextNodeRenderable2, TextNodeRenderable2, RootTextNodeRenderable2, TextRenderable2, NativeSession2, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture2, ConsolePosition2, TerminalConsole2, EditBufferRenderableEvents2, isEditBufferRenderable2, EditBufferRenderable2, buildKittyKeyboardFlags2, MouseEvent2, MouseButton2, createCliRenderer2, CliRenderEvents2, RendererControlState2, CliRenderer2 };
25458
+ export { isValidBorderStyle2, parseBorderStyle2, BorderChars2, getBorderFromSides2, getBorderSides2, borderCharsToArray2, BorderCharArrays2, KeyEvent2, PasteEvent2, KeyHandler2, InternalKeyHandler2, fonts2, measureText2, getCharacterPositions2, coordinateToCharacterIndex2, renderFontToFrameBuffer2, hastToStyledText2, SystemClock2, nonAlphanumericKeys2, terminalNamedSingleStrokeKeys2, parseKeypress2, LinearScrollAccel2, MacOSScrollAccel2, parseAlign2, parseAlignItems2, parseBoxSizing2, parseDimension2, parseDirection2, parseDisplay2, parseEdge2, parseFlexDirection2, parseGutter2, parseJustify2, parseLogLevel2, parseMeasureMode2, parseOverflow2, parsePositionType2, parseUnit2, parseWrap2, MouseParser2, Selection2, convertGlobalToLocalSelection2, ASCIIFontSelectionHelper2, StdinParser2, addDefaultParsers2, TreeSitterClient2, treeSitterToTextChunks2, treeSitterToStyledText2, DataPathsManager2, getDataPaths2, extensionToFiletype2, basenameToFiletype2, extToFiletype2, pathToFiletype2, infoStringToFiletype2, getTreeSitterClient2, destroyTreeSitterClient2, ExtmarksController2, createExtmarksController2, TerminalPalette2, createTerminalPalette2, normalizeTerminalPalette2, buildTerminalPaletteSignature2, decodePasteBytes2, stripAnsiSequences2, createHostClipboard2, createClipboard2, ClipboardTarget2, createRendererClipboardAdapter2, normalizeMarkdownLinkTarget, detectLinks2, acquireSessionBufferLease2, ResourceContext2, OptimizedBuffer2, h2, isVNode2, maybeMakeRenderable2, wrapWithDelegates2, instantiate2, delegate2, LayoutEvents2, RenderableEvents2, isRenderable2, BaseRenderable2, Renderable2, RootRenderable2, TextBuffer2, TextBufferView2, EditBuffer2, measureEditText2, EditorView2, Timeline2, engine2, getTimelineEngine2, createTimeline2, ANSI, BoxRenderable2, wheelDirection, scrollOnce, TextBufferRenderable2, CodeRenderable2, ImageLoadError2, ImageError2, imageInfo2, NativeImage2, NativeImagePool2, resolveImageRenderProtocol2, checkCrop2, sameCrop2, ImageRenderable2, isTextNodeRenderable2, TextNodeRenderable2, RootTextNodeRenderable2, TextRenderable2, NativeSession2, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture2, ConsolePosition2, TerminalConsole2, EditBufferRenderableEvents2, isEditBufferRenderable2, EditBufferRenderable2, buildKittyKeyboardFlags2, MouseEvent2, MouseButton2, createCliRenderer2, CliRenderEvents2, RendererControlState2, CliRenderer2 };
25093
25459
 
25094
- //# debugId=F010F97393855BC764756E2164756E21
25095
- //# sourceMappingURL=chunk-node-q5ccgbk5.js.map
25460
+ //# debugId=DCAF80DF886EB5E364756E2164756E21
25461
+ //# sourceMappingURL=chunk-node-tpjmjvn7.js.map