brsh 3.6.0 → 3.6.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.
@@ -218,7 +218,7 @@ class WasmCommand extends ScriptCommand {
218
218
 
219
219
  const isInteractive = Boolean(
220
220
  this.interactive &&
221
- (this.stdin === undefined || this.stdin === null || this.stdin === this.stdinStream)
221
+ (this.stdin === undefined || this.stdin === null || this.stdin === this.stdinStream || (this.stdin && this.stdin.isTTY))
222
222
  );
223
223
 
224
224
  const writeFd = (fd, text) => {
@@ -293,6 +293,9 @@ class WasmCommand extends ScriptCommand {
293
293
  if (isInteractive && this.stdinStream && typeof this.stdinStream.on === 'function') {
294
294
  this.stdinStream.on('data', onStreamData);
295
295
  }
296
+ if (isInteractive && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on === 'function') {
297
+ this.stdin.on('data', onStreamData);
298
+ }
296
299
 
297
300
  const stdinBytes = (!isInteractive && typeof this.stdin === 'string')
298
301
  ? encoder.encode(this.stdin)
@@ -914,8 +917,9 @@ class WasmCommand extends ScriptCommand {
914
917
  if (isInteractive) {
915
918
  this._exitAltScreen();
916
919
  }
917
- if (isInteractive && onStreamData && this.stdinStream && typeof this.stdinStream.off === 'function') {
918
- this.stdinStream.off('data', onStreamData);
920
+ if (isInteractive && onStreamData) {
921
+ if (this.stdinStream && typeof this.stdinStream.off === 'function') this.stdinStream.off('data', onStreamData);
922
+ if (this.stdin && typeof this.stdin.off === 'function') this.stdin.off('data', onStreamData);
919
923
  }
920
924
  if (onResize) {
921
925
  if (this.stdout && typeof this.stdout.off === 'function') this.stdout.off('resize', onResize);
package/lib/wbt/index.js CHANGED
@@ -60,6 +60,34 @@ class Wbt extends LocalCommand {
60
60
  get name() { return 'wbt'; }
61
61
  get requiresFilesystem() { return true; }
62
62
 
63
+ get interactive() {
64
+ if (this._activeSubCommand && this._activeSubCommand.interactive !== undefined) {
65
+ return Boolean(this._activeSubCommand.interactive);
66
+ }
67
+ if (this.arguments && this.arguments[0] === 'run' && this.arguments[1]) {
68
+ const rawName = this.arguments[1].toLowerCase();
69
+ const pkgMeta = this._getRegistry()[rawName];
70
+ if (pkgMeta && pkgMeta.interactive) {
71
+ const isHelpOrVersion = this.arguments.slice(2).some(a => a === '--help' || a === '-h' || a === '--version' || a === '-V' || a === '-v');
72
+ return !isHelpOrVersion;
73
+ }
74
+ }
75
+ return false;
76
+ }
77
+
78
+ get captureInput() {
79
+ if (this._activeSubCommand && this._activeSubCommand.captureInput !== undefined) {
80
+ return Boolean(this._activeSubCommand.captureInput);
81
+ }
82
+ return this.interactive;
83
+ }
84
+
85
+ onInput(key) {
86
+ if (this._activeSubCommand && typeof this._activeSubCommand.onInput === 'function') {
87
+ this._activeSubCommand.onInput(key);
88
+ }
89
+ }
90
+
63
91
  static get _config() {
64
92
  return this.__wbtConfig || {};
65
93
  }
@@ -970,6 +998,19 @@ class Wbt extends LocalCommand {
970
998
  return;
971
999
  }
972
1000
 
1001
+ if ((pkgMeta.type === 'custom-wasm' || pkgMeta.type === 'wasm') && !pkgMeta.wasmPath) {
1002
+ try {
1003
+ const wasmPath = await this._pullPackageWasm(pkgMeta, true);
1004
+ if (wasmPath) {
1005
+ pkgMeta = Object.assign({}, pkgMeta, { wasmPath });
1006
+ }
1007
+ } catch (err) {
1008
+ this.stdErr = `E: Failed to fetch ${pkgMeta.name}: ${err.message || err}`;
1009
+ this.exitCode = 1;
1010
+ return;
1011
+ }
1012
+ }
1013
+
973
1014
  const entries = this._buildCommandsForPackage(pkgMeta);
974
1015
  // Find matching entry if user specified e.g. `wbt run asrun` or `wbt run wasm2wat`
975
1016
  const matched = entries.find(e => e.bin === rawName.toLowerCase()) || entries[0];
@@ -979,15 +1020,44 @@ class Wbt extends LocalCommand {
979
1020
  if (instance.requiresFilesystem) {
980
1021
  instance.fs = this.context.fs.sandbox();
981
1022
  }
982
- if (this.stdin !== undefined) {
983
- instance.stdin = this.stdin;
1023
+
1024
+ // Pipe I/O and forward interactivity
1025
+ this._activeSubCommand = instance;
1026
+ instance.stdinStream = this.stdinStream;
1027
+ instance.stdin = (this.stdin && !this.stdin.isTTY) ? this.stdin : this.stdinStream;
1028
+
1029
+ const onStdout = (chunk) => {
1030
+ if (this.stdout && typeof this.stdout.write === 'function') this.stdout.write(chunk);
1031
+ };
1032
+ const onStderr = (chunk) => {
1033
+ if (this.stderr && typeof this.stderr.write === 'function') this.stderr.write(chunk);
1034
+ };
1035
+ if (instance.stdout && typeof instance.stdout.on === 'function') {
1036
+ instance.stdout.on('data', onStdout);
1037
+ }
1038
+ if (instance.stderr && typeof instance.stderr.on === 'function') {
1039
+ instance.stderr.on('data', onStderr);
984
1040
  }
985
- const res = await instance.runCommand();
986
- for (const line of res.getStdOutput()) {
987
- if (line.type === 'out') this.stdOut = line.string;
988
- else if (line.type === 'err') this.stdErr = line.string;
1041
+
1042
+ let res;
1043
+ try {
1044
+ res = await instance.runCommand();
1045
+ } finally {
1046
+ this._activeSubCommand = null;
1047
+ if (instance.stdout && typeof instance.stdout.off === 'function') {
1048
+ instance.stdout.off('data', onStdout);
1049
+ }
1050
+ if (instance.stderr && typeof instance.stderr.off === 'function') {
1051
+ instance.stderr.off('data', onStderr);
1052
+ }
1053
+ }
1054
+ if (!instance.interactive && res) {
1055
+ for (const line of res.getStdOutput()) {
1056
+ if (line.type === 'out') this.stdOut = line.string;
1057
+ else if (line.type === 'err') this.stdErr = line.string;
1058
+ }
989
1059
  }
990
- this.exitCode = res.getExitCode();
1060
+ this.exitCode = res ? res.getExitCode() : 0;
991
1061
  }
992
1062
 
993
1063
  _printHelp() {
@@ -171,7 +171,7 @@ const DEFAULT_REGISTRY = {
171
171
  name: 'nano',
172
172
  bin: 'nano',
173
173
  aliases: ['nano-wasm'],
174
- version: '8.0.0',
174
+ version: '8.0.1',
175
175
  description: 'GNU nano 8.0 text editor compiled to WebAssembly (wasm32-wasip1) with ncurses',
176
176
  details: 'GNU nano is a small, user-friendly command-line text editor compiled to WebAssembly with wide-character ncurses 6.5, built-in terminfo fallbacks (xterm-256color, vt100, etc.), dynamic terminal dimensions (TIOCGWINSZ / LINES & COLUMNS), and zero custom imports (standard wasi_snapshot_preview1).',
177
177
  homepage: 'https://github.com/eliotstocker/nano-wasm',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brsh",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "A unix like shell written in javascript",
5
5
  "main": "./dist/shell.min.js",
6
6
  "module": "./dist/shell.es.js",
@@ -1,4 +1,6 @@
1
1
  import { describe, it, expect, beforeEach } from 'vitest';
2
+ import path from 'path';
3
+ import fs from 'fs';
2
4
  import Shell from '../index.js';
3
5
  import Terminal from '../lib/Terminal.js';
4
6
  import Pico from '../demo/pico.js';
@@ -561,6 +563,34 @@ describe('brsh Shell Integration, Line Editing, and Full-Screen Apps', () => {
561
563
  expect(term.screen.isAltScreen).toBe(false);
562
564
  expect(term.getLineText(0)).toContain('brsh:root$ demorepl');
563
565
  });
566
+
567
+ it('runs nano text editor in Terminal alternate screen and restores screen on exit', async () => {
568
+ const FIXTURE_NANO_WASM = path.resolve(import.meta.dirname, 'fixtures/nano.wasm');
569
+ if (!fs.existsSync(FIXTURE_NANO_WASM)) return;
570
+ const bytes = fs.readFileSync(FIXTURE_NANO_WASM);
571
+ const Wbt = (await import('../lib/wbt/index.js')).default.configure({
572
+ fetch: async () => ({
573
+ ok: true,
574
+ status: 200,
575
+ arrayBuffer: async () => bytes.buffer
576
+ })
577
+ });
578
+ shell.context.setCommand(Wbt);
579
+ await shell.onCommand('wbt install nano');
580
+
581
+ const nanoDone = waitForReady(shell);
582
+ shell.onCommand('nano');
583
+ await new Promise(r => setTimeout(r, 80));
584
+
585
+ expect(term.screen.isAltScreen).toBe(true);
586
+ expect(term.getScreenText()).toContain('GNU nano 8.0');
587
+
588
+ // Exit nano with Ctrl+X
589
+ term.sendKey('x', { ctrl: true });
590
+ await nanoDone;
591
+
592
+ expect(term.screen.isAltScreen).toBe(false);
593
+ });
564
594
  });
565
595
 
566
596
  describe('TUI (blessed-style) Application over Virtual TTY & Real zsh PTY Compatibility', () => {
package/test/wbt.test.js CHANGED
@@ -1346,7 +1346,7 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
1346
1346
  it('registers nano and nano-wasm in registry, wbt search, and wbt show', async () => {
1347
1347
  const listRes = await run(shell, 'wbt list');
1348
1348
  expect(listRes.exitCode).toBe(0);
1349
- expect(listRes.output.join('\n')).toContain('nano/wasm 8.0.0');
1349
+ expect(listRes.output.join('\n')).toContain('nano/wasm 8.0.1');
1350
1350
 
1351
1351
  const searchRes = await run(shell, 'wbt search editor');
1352
1352
  expect(searchRes.exitCode).toBe(0);
@@ -1355,7 +1355,7 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
1355
1355
  const showRes = await run(shell, 'wbt show nano');
1356
1356
  expect(showRes.exitCode).toBe(0);
1357
1357
  expect(showRes.output.join('\n')).toContain('Package: nano');
1358
- expect(showRes.output.join('\n')).toContain('Version: 8.0.0');
1358
+ expect(showRes.output.join('\n')).toContain('Version: 8.0.1');
1359
1359
  expect(showRes.output.join('\n')).toContain('Aliases: nano-wasm');
1360
1360
 
1361
1361
  const showAliasRes = await run(shell, 'wbt show nano-wasm');