@narumitw/pi-btw 0.56.0 → 0.56.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-btw",
3
- "version": "0.56.0",
3
+ "version": "0.56.2",
4
4
  "description": "Pi extension that adds a /btw side-question command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -300,9 +300,11 @@ class BtwFullscreenHost<T> implements Component {
300
300
  private disposed = false;
301
301
  private finished = false;
302
302
  private parentStopped = false;
303
- private parentRestarted = false;
303
+ private parentRestoreAttempted = false;
304
304
  private fullscreenCreated = false;
305
305
  private fullscreenStopped = false;
306
+ private parentRestoreQueued = false;
307
+ private parentRestorePromise: Promise<void> | undefined;
306
308
  private cleanupError: unknown;
307
309
 
308
310
  constructor(
@@ -356,7 +358,11 @@ class BtwFullscreenHost<T> implements Component {
356
358
  try {
357
359
  this.hardCancelActiveCustom?.();
358
360
  } finally {
359
- this.restoreParent();
361
+ // ProcessTerminal.stop() destroys its active input buffer. Keep cancellation
362
+ // synchronous, then drain input before the physical Windows terminal handoff.
363
+ // Pi has no public input injection, so do not replay bytes already coalesced
364
+ // behind the hard-cancel key.
365
+ this.queueParentRestore();
360
366
  }
361
367
  return { consume: true };
362
368
  });
@@ -370,15 +376,35 @@ class BtwFullscreenHost<T> implements Component {
370
376
  } catch (error) {
371
377
  this.cleanupError ??= error;
372
378
  }
373
- this.restoreParent();
379
+ if (this.parentRestorePromise) await this.parentRestorePromise;
380
+ else this.restoreParent();
374
381
  if (this.cleanupError !== undefined) outcome = { kind: "failed", error: this.cleanupError };
375
382
  this.finished = true;
376
383
  this.done(outcome);
377
384
  }
378
385
 
386
+ private queueParentRestore(): void {
387
+ if (this.parentRestoreQueued || this.parentRestoreAttempted) return;
388
+ this.parentRestoreQueued = true;
389
+ this.parentRestorePromise = Promise.resolve().then(async () => {
390
+ try {
391
+ await this.fullscreen?.terminal.drainInput?.();
392
+ } catch (error) {
393
+ this.cleanupError ??= error;
394
+ }
395
+ this.parentRestoreQueued = false;
396
+ this.restoreParent();
397
+ });
398
+ }
399
+
379
400
  private restoreParent(): void {
380
- this.removeHardCancelListener?.();
401
+ const removeHardCancelListener = this.removeHardCancelListener;
381
402
  this.removeHardCancelListener = undefined;
403
+ try {
404
+ removeHardCancelListener?.();
405
+ } catch (error) {
406
+ this.cleanupError ??= error;
407
+ }
382
408
  if (this.fullscreenCreated && !this.fullscreenStopped) {
383
409
  this.fullscreenStopped = true;
384
410
  try {
@@ -387,7 +413,7 @@ class BtwFullscreenHost<T> implements Component {
387
413
  this.cleanupError ??= error;
388
414
  }
389
415
  }
390
- if (!this.parentStopped || this.parentRestarted) return;
416
+ if (!this.parentStopped || this.parentRestoreAttempted) return;
391
417
  const parentOverlay = this.parentOverlay;
392
418
  this.parentOverlay = undefined;
393
419
  try {
@@ -396,8 +422,8 @@ class BtwFullscreenHost<T> implements Component {
396
422
  this.cleanupError ??= error;
397
423
  }
398
424
  try {
425
+ this.parentRestoreAttempted = true;
399
426
  this.parent.start();
400
- this.parentRestarted = true;
401
427
  this.parent.renderNow(false);
402
428
  } catch (error) {
403
429
  this.cleanupError ??= error;