brsh 2.4.1 → 2.5.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.5.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.4.1...v2.5.0) (2026-05-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * interactive commands + pico demo + filesystem compression ([255ba2b](https://github.com/eliotstocker/Brsh-JS/commit/255ba2b782276c06116ff3118eccff0794b98ec7))
7
+
1
8
  ## [2.4.1](https://github.com/eliotstocker/Brsh-JS/compare/v2.4.0...v2.4.1) (2026-05-24)
2
9
 
3
10
 
package/bin/brsh-shell.js CHANGED
@@ -58,11 +58,28 @@ const shell = new Shell({
58
58
  hostname: require('os').hostname().split('.')[0]
59
59
  });
60
60
 
61
- shell.on('stdOut', line => process.stdout.write(line + '\n'));
62
- shell.on('stdErr', line => process.stderr.write(line + '\n'));
63
-
64
61
  let destroyed = false;
65
62
  let rl;
63
+ let inInteractiveApp = false;
64
+
65
+ // ── Terminal size reporting ───────────────────────────────────────────────────
66
+
67
+ function reportSize() {
68
+ if (process.stdout.isTTY) {
69
+ shell.setTerminalSize(process.stdout.columns || 80, process.stdout.rows || 24);
70
+ }
71
+ }
72
+
73
+ process.stdout.on('resize', () => { if (inInteractiveApp) reportSize(); });
74
+
75
+ shell.on('stdOut', line => {
76
+ if (inInteractiveApp) {
77
+ process.stdout.write(line);
78
+ } else {
79
+ process.stdout.write(line + '\n');
80
+ }
81
+ });
82
+ shell.on('stdErr', line => process.stderr.write(line + '\n'));
66
83
 
67
84
  shell.on('exit', code => {
68
85
  destroyed = true;
@@ -110,7 +127,14 @@ if (!isInteractive) {
110
127
  // ── Interactive mode ──────────────────────────────────────────────────────────
111
128
 
112
129
  shell.on('status', status => {
113
- if (status === Shell.STATUS_READY) ask();
130
+ if (status !== Shell.STATUS_READY) return;
131
+ if (inInteractiveApp) {
132
+ inInteractiveApp = false;
133
+ process.stdin.removeListener('data', rawDataHandler);
134
+ if (process.stdin.isTTY) process.stdin.setRawMode(false);
135
+ rl.resume();
136
+ }
137
+ ask();
114
138
  });
115
139
 
116
140
  function prompt() {
@@ -136,6 +160,9 @@ rl = readline.createInterface({
136
160
  completer
137
161
  });
138
162
 
163
+ // Report initial terminal size so COLUMNS/LINES are correct from the start
164
+ reportSize();
165
+
139
166
  function ask() {
140
167
  rl.question(prompt(), line => {
141
168
  if (line === null) {
@@ -152,9 +179,52 @@ rl.on('close', () => { if (!destroyed) process.exit(0); });
152
179
 
153
180
  // Forward typed lines to commands waiting for input (e.g. `read`)
154
181
  rl.on('line', function(line) {
155
- if (shell.runningCommand && shell.runningCommand.captureInput) {
182
+ if (shell.runningCommand && shell.runningCommand.captureInput && !inInteractiveApp) {
156
183
  for (const char of line) { shell.onInput(char); }
157
184
  shell.onInput('Enter');
158
185
  }
159
186
  });
160
187
 
188
+ // ── Raw key input for interactive full-screen apps ────────────────────────────
189
+
190
+ function parseRawKey(buf) {
191
+ const str = buf.toString('binary');
192
+ if (str.length === 1) {
193
+ const code = str.charCodeAt(0);
194
+ if (code === 0x0d || code === 0x0a) return 'Enter';
195
+ if (code === 0x7f || code === 0x08) return 'Backspace';
196
+ if (code === 0x09) return 'Tab';
197
+ if (code === 0x1b) return 'Escape';
198
+ if (code >= 0x01 && code <= 0x1a) return '^' + String.fromCharCode(code + 0x40);
199
+ return str;
200
+ }
201
+ if (str.startsWith('\x1b[') || str.startsWith('\x1bO')) {
202
+ const seq = str.slice(2);
203
+ const named = {
204
+ A: 'ArrowUp', B: 'ArrowDown', C: 'ArrowRight', D: 'ArrowLeft',
205
+ H: 'Home', F: 'End',
206
+ '1~': 'Home', '3~': 'Delete', '4~': 'End',
207
+ '5~': 'PageUp', '6~': 'PageDown',
208
+ '7~': 'Home', '8~': 'End'
209
+ };
210
+ return named[seq] || null;
211
+ }
212
+ return null;
213
+ }
214
+
215
+ function rawDataHandler(buf) {
216
+ const key = parseRawKey(buf);
217
+ if (key !== null) shell.onInput(key);
218
+ }
219
+
220
+ shell.on('interactive', () => {
221
+ inInteractiveApp = true;
222
+ reportSize();
223
+ rl.pause();
224
+ if (process.stdin.isTTY) {
225
+ process.stdin.setRawMode(true);
226
+ process.stdin.resume();
227
+ }
228
+ process.stdin.on('data', rawDataHandler);
229
+ });
230
+
@@ -4,6 +4,7 @@
4
4
  const esbuild = require('esbuild');
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
+ const zlib = require('zlib');
7
8
  const cla = require('command-line-args');
8
9
  const tmp = require('tmp');
9
10
  const { polyfillNode } = require('esbuild-plugin-polyfill-node');
@@ -38,6 +39,11 @@ try {
38
39
  name: 'hyperlinks',
39
40
  alias: 'h',
40
41
  type: Boolean
42
+ },
43
+ {
44
+ name: 'compress',
45
+ alias: 'c',
46
+ type: Boolean
41
47
  }
42
48
  ]);
43
49
  } catch(e) {
@@ -70,11 +76,57 @@ try {
70
76
  process.exit(1);
71
77
  }
72
78
  const { filesystem, permissions } = struct;
73
- const fsJson = JSON.stringify(filesystem, null, options.pretty ? 2 : null);
74
- const permJson = JSON.stringify(permissions, null, options.pretty ? 2 : null);
75
- const fsJS = fsJson.replace(/"(require\('.*?'\))"/gm, '$1');
76
79
 
77
- let JS = `module.exports = { filesystem: ${fsJS}, permissions: ${permJson} }`;
80
+ /**
81
+ * Recursively splits a filesystem tree into two trees:
82
+ * code – entries whose value is a require() placeholder (bundled by esbuild)
83
+ * data – entries whose value is a plain string/null (text / binary content)
84
+ */
85
+ function splitFilesystem(node) {
86
+ const code = {};
87
+ const data = {};
88
+ for (const [key, value] of Object.entries(node)) {
89
+ if (value !== null && typeof value === 'object') {
90
+ const [subCode, subData] = splitFilesystem(value);
91
+ if (Object.keys(subCode).length > 0) code[key] = subCode;
92
+ if (Object.keys(subData).length > 0) data[key] = subData;
93
+ } else if (typeof value === 'string' && value.startsWith("require('")) {
94
+ code[key] = value;
95
+ } else {
96
+ data[key] = value;
97
+ }
98
+ }
99
+ return [code, data];
100
+ }
101
+
102
+ let JS;
103
+
104
+ if (options.compress) {
105
+ const [codeFilesystem, dataFilesystem] = splitFilesystem(filesystem);
106
+
107
+ // Compress the data portion (text/binary file contents + permissions)
108
+ const dataPayload = JSON.stringify({ filesystem: dataFilesystem, permissions });
109
+ const compressed = zlib.gzipSync(Buffer.from(dataPayload, 'utf8'));
110
+ const b64 = compressed.toString('base64');
111
+
112
+ // Serialise only the code portion (require() entries) with substitution
113
+ const codeFsJSON = JSON.stringify(codeFilesystem);
114
+ const codeFsJS = codeFsJSON.replace(/"(require\('.*?'\))"/gm, '$1');
115
+
116
+ JS = `
117
+ const __c="${b64}";
118
+ function __bd(s){const b=atob(s);const a=new Uint8Array(b.length);for(let i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a;}
119
+ async function __decompress(b64){const ds=new DecompressionStream("gzip");const w=ds.writable.getWriter();w.write(__bd(b64));w.close();const buf=await new Response(ds.readable).arrayBuffer();return JSON.parse(new TextDecoder().decode(buf));}
120
+ function __merge(a,b){const r={};const ks=new Set([...Object.keys(a||{}),...Object.keys(b||{})]);for(const k of ks){const av=a&&a[k],bv=b&&b[k];r[k]=(av!==null&&typeof av==="object"&&bv!==null&&typeof bv==="object")?__merge(av,bv):(av!==undefined?av:bv);}return r;}
121
+ const __codeFs=${codeFsJS};
122
+ module.exports=__decompress(__c).then(function(__d){return{filesystem:__merge(__codeFs,__d.filesystem),permissions:__d.permissions};});
123
+ `;
124
+ } else {
125
+ const fsJson = JSON.stringify(filesystem, null, options.pretty ? 2 : null);
126
+ const permJson = JSON.stringify(permissions, null, options.pretty ? 2 : null);
127
+ const fsJS = fsJson.replace(/"(require\('.*?'\))"/gm, '$1');
128
+ JS = `module.exports = { filesystem: ${fsJS}, permissions: ${permJson} }`;
129
+ }
78
130
 
79
131
  const tf = tmp.fileSync({ postfix: '.tmp.js' });
80
132
  fs.writeFileSync(tf.name, JS);
package/dist/brsh.css CHANGED
@@ -1,2 +1,2 @@
1
- .terminal__cursor{display:inline-block}.terminal__cursor.blink{animation:1s step-end .5s infinite blink}.terminal__line{white-space:pre;min-height:1.15em;line-height:1.15em;overflow:hidden}.terminal--wrap .terminal__line,.terminal--wrap li{white-space:pre-wrap;overflow:visible}@keyframes blink{0%,to{opacity:0}50%{opacity:1}}.ansi-black-fg{color:#000}.ansi-black-bg{background:#000}.ansi-red-fg{color:#b00}.ansi-red-bg{background:#b00}.ansi-green-fg{color:#0b0}.ansi-green-bg{background:#0b0}.ansi-yellow-fg{color:#bb0}.ansi-yellow-bg{background:#bb0}.ansi-blue-fg{color:#00b}.ansi-blue-bg{background:#00b}.ansi-magenta-fg{color:#b0b}.ansi-magenta-bg{background:#b0b}.ansi-cyan-fg{color:#0bb}.ansi-cyan-bg{background:#0bb}.ansi-white-fg{color:#fff}.ansi-white-bg{background:#fff}.ansi-bright-black-fg{color:#555}.ansi-bright-black-bg{background:#555}.ansi-bright-red-fg{color:#f55}.ansi-bright-red-bg{background:#f55}.ansi-bright-green-fg{color:#0f0}.ansi-bright-green-bg{background:#0f0}.ansi-bright-yellow-fg{color:#ff5}.ansi-bright-yellow-bg{background:#ff5}.ansi-bright-blue-fg{color:#55f}.ansi-bright-blue-bg{background:#55f}.ansi-bright-magenta-fg{color:#f5f}.ansi-bright-magenta-bg{background:#f5f}.ansi-bright-cyan-fg{color:#5ff}.ansi-bright-cyan-bg{background:#5ff}.ansi-bright-white-fg{color:#fff}.ansi-bright-white-bg{background:#fff}
1
+ :root{--terminal-cursor-bg:#000;--terminal-cursor-color:#fff}.terminal__cursor{display:inline-block}.terminal__screen{white-space:pre;flex:1;margin:0;padding:0;line-height:1.15em;display:none;overflow:hidden}.terminal__char-measure{visibility:hidden;pointer-events:none;white-space:pre;line-height:1.15em;position:absolute}.terminal__cursor.blink{animation:1s step-end .5s infinite blink}.terminal__cursor.block{background-color:var(--terminal-cursor-bg);color:var(--terminal-cursor-color)}.terminal__line{white-space:pre;min-height:1.15em;line-height:1.15em;overflow:hidden}.terminal--wrap .terminal__line,.terminal--wrap li{white-space:pre-wrap;overflow:visible}@keyframes blink{0%,to{background-color:var(--terminal-cursor-bg);color:var(--terminal-cursor-color)}50%{color:inherit;background-color:#0000}}.ansi-black-fg{color:#000}.ansi-black-bg{background:#000}.ansi-red-fg{color:#b00}.ansi-red-bg{background:#b00}.ansi-green-fg{color:#0b0}.ansi-green-bg{background:#0b0}.ansi-yellow-fg{color:#bb0}.ansi-yellow-bg{background:#bb0}.ansi-blue-fg{color:#00b}.ansi-blue-bg{background:#00b}.ansi-magenta-fg{color:#b0b}.ansi-magenta-bg{background:#b0b}.ansi-cyan-fg{color:#0bb}.ansi-cyan-bg{background:#0bb}.ansi-white-fg{color:#fff}.ansi-white-bg{background:#fff}.ansi-bright-black-fg{color:#555}.ansi-bright-black-bg{background:#555}.ansi-bright-red-fg{color:#f55}.ansi-bright-red-bg{background:#f55}.ansi-bright-green-fg{color:#0f0}.ansi-bright-green-bg{background:#0f0}.ansi-bright-yellow-fg{color:#ff5}.ansi-bright-yellow-bg{background:#ff5}.ansi-bright-blue-fg{color:#55f}.ansi-bright-blue-bg{background:#55f}.ansi-bright-magenta-fg{color:#f5f}.ansi-bright-magenta-bg{background:#f5f}.ansi-bright-cyan-fg{color:#5ff}.ansi-bright-cyan-bg{background:#5ff}.ansi-bright-white-fg{color:#fff}.ansi-bright-white-bg{background:#fff}
2
2
  /*$vite$:1*/