@navios/commander-tui 1.5.1 → 1.6.0

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/lib/index.mjs CHANGED
@@ -4305,7 +4305,7 @@ const ScreenOptionsSchema = object({
4305
4305
  icon: string().optional(),
4306
4306
  badgeCount: number().optional(),
4307
4307
  hidden: boolean().optional().default(false),
4308
- static: boolean().optional().default(false)
4308
+ static: boolean().optional().default(true)
4309
4309
  });
4310
4310
 
4311
4311
  //#endregion
@@ -6268,6 +6268,7 @@ var ScreenInstance = class extends EventEmitter {
6268
6268
  version = 0;
6269
6269
  promptQueue = [];
6270
6270
  activePrompt = null;
6271
+ promptVersion = 0;
6271
6272
  constructor(id, options) {
6272
6273
  super();
6273
6274
  this.id = id;
@@ -6283,6 +6284,12 @@ var ScreenInstance = class extends EventEmitter {
6283
6284
  getVersion() {
6284
6285
  return this.version;
6285
6286
  }
6287
+ incrementPromptVersion() {
6288
+ this.promptVersion++;
6289
+ }
6290
+ getPromptVersion() {
6291
+ return this.promptVersion;
6292
+ }
6286
6293
  /**
6287
6294
  * Internal: Set the manager reference
6288
6295
  */ _setManager(manager) {
@@ -6466,9 +6473,16 @@ var ScreenInstance = class extends EventEmitter {
6466
6473
  resolve(getPromptDefaultValue(prompt));
6467
6474
  }
6468
6475
  /**
6469
- * Get the currently active prompt (for rendering)
6476
+ * Get the currently active prompt (for rendering).
6477
+ * Returns a shallow clone to ensure React detects changes when prompt state mutates.
6470
6478
  */ getActivePrompt() {
6471
- return this.activePrompt?.data ?? null;
6479
+ if (!this.activePrompt?.data) return null;
6480
+ const prompt = this.activePrompt.data;
6481
+ if (prompt.type === "multiChoice") return {
6482
+ ...prompt,
6483
+ selectedIndices: new Set(prompt.selectedIndices)
6484
+ };
6485
+ return { ...prompt };
6472
6486
  }
6473
6487
  /**
6474
6488
  * Check if this screen has an active prompt
@@ -6487,6 +6501,7 @@ var ScreenInstance = class extends EventEmitter {
6487
6501
  const maxIndex = prompt.choices.length - 1;
6488
6502
  prompt.focusedIndex = Math.max(0, Math.min(index, maxIndex));
6489
6503
  } else if (prompt.type === "confirm") prompt.selectedValue = index === 0;
6504
+ this.incrementPromptVersion();
6490
6505
  this.emit("prompt:updated");
6491
6506
  }
6492
6507
  /**
@@ -6514,6 +6529,7 @@ var ScreenInstance = class extends EventEmitter {
6514
6529
  const prompt = this.activePrompt.data;
6515
6530
  if (prompt.type === "confirm") {
6516
6531
  prompt.selectedValue = true;
6532
+ this.incrementPromptVersion();
6517
6533
  this.emit("prompt:updated");
6518
6534
  }
6519
6535
  }
@@ -6522,6 +6538,7 @@ var ScreenInstance = class extends EventEmitter {
6522
6538
  const prompt = this.activePrompt.data;
6523
6539
  if (prompt.type === "confirm") {
6524
6540
  prompt.selectedValue = false;
6541
+ this.incrementPromptVersion();
6525
6542
  this.emit("prompt:updated");
6526
6543
  }
6527
6544
  }
@@ -6534,6 +6551,7 @@ var ScreenInstance = class extends EventEmitter {
6534
6551
  const p = prompt;
6535
6552
  if (p.selectedIndices.has(p.focusedIndex)) p.selectedIndices.delete(p.focusedIndex);
6536
6553
  else if (p.selectedIndices.size < p.maxSelect) p.selectedIndices.add(p.focusedIndex);
6554
+ this.incrementPromptVersion();
6537
6555
  this.emit("prompt:updated");
6538
6556
  }
6539
6557
  }
@@ -6546,6 +6564,7 @@ var ScreenInstance = class extends EventEmitter {
6546
6564
  if (prompt.type === "choice") {
6547
6565
  if (prompt.choices[prompt.selectedIndex]?.input) {
6548
6566
  prompt.inputMode = true;
6567
+ this.incrementPromptVersion();
6549
6568
  this.emit("prompt:updated");
6550
6569
  return true;
6551
6570
  }
@@ -6559,6 +6578,7 @@ var ScreenInstance = class extends EventEmitter {
6559
6578
  const prompt = this.activePrompt.data;
6560
6579
  if (prompt.type === "choice" && prompt.inputMode) {
6561
6580
  prompt.inputMode = false;
6581
+ this.incrementPromptVersion();
6562
6582
  this.emit("prompt:updated");
6563
6583
  }
6564
6584
  }
@@ -6578,9 +6598,11 @@ var ScreenInstance = class extends EventEmitter {
6578
6598
  const prompt = this.activePrompt.data;
6579
6599
  if (prompt.type === "choice" && prompt.inputMode) {
6580
6600
  prompt.inputValue = value;
6601
+ this.incrementPromptVersion();
6581
6602
  this.emit("prompt:updated");
6582
6603
  } else if (prompt.type === "input") {
6583
6604
  prompt.value = value;
6605
+ this.incrementPromptVersion();
6584
6606
  this.emit("prompt:updated");
6585
6607
  }
6586
6608
  }
@@ -6591,9 +6613,11 @@ var ScreenInstance = class extends EventEmitter {
6591
6613
  const prompt = this.activePrompt.data;
6592
6614
  if (prompt.type === "choice" && prompt.inputMode) {
6593
6615
  prompt.inputValue += char;
6616
+ this.incrementPromptVersion();
6594
6617
  this.emit("prompt:updated");
6595
6618
  } else if (prompt.type === "input") {
6596
6619
  prompt.value += char;
6620
+ this.incrementPromptVersion();
6597
6621
  this.emit("prompt:updated");
6598
6622
  }
6599
6623
  }
@@ -6604,9 +6628,11 @@ var ScreenInstance = class extends EventEmitter {
6604
6628
  const prompt = this.activePrompt.data;
6605
6629
  if (prompt.type === "choice" && prompt.inputMode) {
6606
6630
  prompt.inputValue = prompt.inputValue.slice(0, -1);
6631
+ this.incrementPromptVersion();
6607
6632
  this.emit("prompt:updated");
6608
6633
  } else if (prompt.type === "input") {
6609
6634
  prompt.value = prompt.value.slice(0, -1);
6635
+ this.incrementPromptVersion();
6610
6636
  this.emit("prompt:updated");
6611
6637
  }
6612
6638
  }
@@ -6652,6 +6678,7 @@ var ScreenInstance = class extends EventEmitter {
6652
6678
  this.activePrompt = null;
6653
6679
  this.activateNextPrompt();
6654
6680
  this.incrementVersion();
6681
+ this.incrementPromptVersion();
6655
6682
  this.emit("prompt:resolved");
6656
6683
  }
6657
6684
  /**
@@ -6661,6 +6688,7 @@ var ScreenInstance = class extends EventEmitter {
6661
6688
  this.activePrompt = this.promptQueue.shift();
6662
6689
  this.manager?.onScreenPromptActivated(this);
6663
6690
  this.incrementVersion();
6691
+ this.incrementPromptVersion();
6664
6692
  this.emit("prompt:activated");
6665
6693
  }
6666
6694
  }
@@ -6994,7 +7022,10 @@ var ScreenManagerInstance = class extends (_EventEmitter = EventEmitter) {
6994
7022
  screen._setPrintFn(printMessagesToStdout);
6995
7023
  this.screens.set(id, screen);
6996
7024
  this.screenOrder.push(id);
6997
- if (!this.activeScreenId && !screen.isHidden()) this.activeScreenId = id;
7025
+ if (!this.activeScreenId && !screen.isHidden()) {
7026
+ this.activeScreenId = id;
7027
+ this.emit("activeScreen:changed", id);
7028
+ }
6998
7029
  this.checkAutoClose();
6999
7030
  this.emit("screen:added", id);
7000
7031
  return screen;
@@ -7111,13 +7142,13 @@ var ScreenManagerInstance = class extends (_EventEmitter = EventEmitter) {
7111
7142
  */ getGlobalLogLevels() {
7112
7143
  return this.globalLogLevels ? Array.from(this.globalLogLevels) : null;
7113
7144
  }
7114
- onServiceDestroy() {
7115
- this.unbind();
7145
+ async onServiceDestroy() {
7146
+ await this.unbind();
7116
7147
  }
7117
7148
  /**
7118
7149
  * Stop TUI rendering and cleanup
7119
7150
  * Flushes screens to stdout/stderr based on mode
7120
- */ unbind() {
7151
+ */ async unbind() {
7121
7152
  if (this.mode === RenderMode.UNBOUND) {
7122
7153
  this.flushRemainingScreens();
7123
7154
  return;
@@ -7128,7 +7159,7 @@ var ScreenManagerInstance = class extends (_EventEmitter = EventEmitter) {
7128
7159
  this.autoCloseTimer = null;
7129
7160
  }
7130
7161
  if (previousMode === RenderMode.TUI_ACTIVE) {
7131
- if (this.root) this.root.unmount();
7162
+ if (this.root) await this.root.unmount();
7132
7163
  if (this.renderer) {
7133
7164
  if ("disableMouse" in this.renderer) this.renderer.disableMouse();
7134
7165
  this.renderer.destroy();
@@ -7638,10 +7669,7 @@ var ScreenLoggerInstance = class {
7638
7669
  ({c: [_ScreenLoggerInstance, _initClass$1]} = _apply_decs_2203_r$1(this, [], [_dec$1]));
7639
7670
  }
7640
7671
  constructor(options) {
7641
- this.screen = inject(Screen, typeof options.screen === "string" ? {
7642
- name: options.screen,
7643
- static: true
7644
- } : options.screen);
7672
+ this.screen = inject(Screen, typeof options.screen === "string" ? { name: options.screen } : options.screen);
7645
7673
  this.context = options.context;
7646
7674
  this.enabledLevels = new Set(options.enabledLevels);
7647
7675
  }