brsh 2.8.0 → 3.0.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.
Files changed (45) hide show
  1. package/.github/workflows/release.yml +3 -1
  2. package/CHANGELOG.md +32 -0
  3. package/bin/brsh-shell.js +16 -131
  4. package/bin/exportFileSystem.js +4 -0
  5. package/bin/zsh-server.js +261 -0
  6. package/dist/brsh.css +1 -1
  7. package/dist/shell.es.js +943 -499
  8. package/dist/shell.es.js.map +1 -1
  9. package/dist/shell.min.js +31 -16
  10. package/dist/shell.min.js.map +1 -1
  11. package/dist/terminal.cjs.js +77 -100
  12. package/dist/terminal.cjs.js.map +1 -1
  13. package/dist/terminal.es.js +1382 -603
  14. package/dist/terminal.es.js.map +1 -1
  15. package/dist/terminal.min.js +77 -100
  16. package/dist/terminal.min.js.map +1 -1
  17. package/dist/wbt.es.js +1863 -752
  18. package/dist/wbt.es.js.map +1 -1
  19. package/dist/wbt.min.js +8 -6
  20. package/dist/wbt.min.js.map +1 -1
  21. package/index.js +472 -0
  22. package/lib/BaseFileSystem.js +40 -0
  23. package/lib/BinaryContainer.js +1 -1
  24. package/lib/Command.js +30 -0
  25. package/lib/FileSystem.js +1 -38
  26. package/lib/InteractiveCommand.js +28 -0
  27. package/lib/NodeFileSystem.js +4 -2
  28. package/lib/ReplCommand.js +15 -0
  29. package/lib/Terminal.js +769 -510
  30. package/lib/TtyStream.js +181 -0
  31. package/lib/WasmCommand.js +168 -18
  32. package/lib/builtins/cat.js +2 -2
  33. package/lib/builtins/grep.js +2 -2
  34. package/lib/local/clear.js +3 -0
  35. package/lib/terminal/DomRenderer.js +325 -0
  36. package/lib/terminal/PtyBridge.js +169 -0
  37. package/lib/terminal/ScreenBuffer.js +594 -0
  38. package/lib/terminal/VtParser.js +728 -0
  39. package/lib/wbt/index.js +270 -14
  40. package/lib/wbt/packages/wllama.js +12 -2
  41. package/lib/wbt/registry.js +11 -2
  42. package/package.json +4 -2
  43. package/styles/terminal.css +33 -4
  44. package/test/terminal.test.js +762 -40
  45. package/test/wbt.test.js +24 -5
@@ -41,10 +41,38 @@ class InteractiveCommand extends Command {
41
41
  * @returns {{ cols: number, rows: number }}
42
42
  */
43
43
  get terminalSize() {
44
+ if (this.stdout && this.stdout.columns && this.stdout.rows) {
45
+ const cols = parseInt(this.context && this.context.getVar && this.context.getVar('COLUMNS'), 10) || this.stdout.columns || 80;
46
+ const rows = parseInt(this.context && this.context.getVar && this.context.getVar('LINES'), 10) || this.stdout.rows || 24;
47
+ return { cols, rows };
48
+ }
44
49
  const cols = parseInt(this.context.getVar('COLUMNS'), 10) || 80;
45
50
  const rows = parseInt(this.context.getVar('LINES'), 10) || 24;
46
51
  return { cols, rows };
47
52
  }
53
+
54
+ _enterAltScreen() {
55
+ if (this._inAltScreen) return;
56
+ this._inAltScreen = true;
57
+ if (this.stdinStream) this.stdinStream.setRawMode(true);
58
+ if (this.stdout) this.stdout.write('\x1b[?1049h\x1b[2J\x1b[H');
59
+ }
60
+
61
+ _exitAltScreen() {
62
+ if (!this._inAltScreen) return;
63
+ this._inAltScreen = false;
64
+ if (this.stdinStream) this.stdinStream.setRawMode(false);
65
+ if (this.stdout) this.stdout.write('\x1b[?1049l\x1b[?25h');
66
+ }
67
+
68
+ runCommand() {
69
+ if (this.interactive) {
70
+ this._enterAltScreen();
71
+ }
72
+ return super.runCommand().finally(() => {
73
+ this._exitAltScreen();
74
+ });
75
+ }
48
76
  }
49
77
 
50
78
  module.exports = InteractiveCommand;
@@ -140,8 +140,10 @@ class NodeFileSystem extends BaseFileSystem {
140
140
  if (this._virtualFiles[abs] !== undefined) {
141
141
  return;
142
142
  }
143
- nodeFs.chmodSync(abs, mode);
144
- this._triggerChange();
143
+ try {
144
+ nodeFs.chmodSync(abs, mode);
145
+ this._triggerChange();
146
+ } catch (e) { /* ignore chmod errors on virtualized paths */ }
145
147
  }
146
148
 
147
149
  getSize(path) {
@@ -76,6 +76,9 @@ class ReplCommand extends InteractiveCommand {
76
76
  this._dynamicReplOpts = opts;
77
77
  this._dynamicReplBuffer = '';
78
78
  this._dynamicReplMultiline = false;
79
+ if (typeof this._enterAltScreen === 'function') {
80
+ this._enterAltScreen();
81
+ }
79
82
  return this._launchInteractiveReplLoop();
80
83
  }
81
84
 
@@ -244,6 +247,18 @@ class ReplCommand extends InteractiveCommand {
244
247
  return;
245
248
  }
246
249
 
250
+ if (key === '^W') {
251
+ let pos = this._replCursor;
252
+ while (pos > 0 && this._replInput[pos - 1] === ' ') pos--;
253
+ while (pos > 0 && this._replInput[pos - 1] !== ' ') pos--;
254
+ this._replInput =
255
+ this._replInput.slice(0, pos) +
256
+ this._replInput.slice(this._replCursor);
257
+ this._replCursor = pos;
258
+ this._renderRepl();
259
+ return;
260
+ }
261
+
247
262
  if (key === 'Delete') {
248
263
  if (this._replCursor < this._replInput.length) {
249
264
  this._replInput =