brsh 2.4.1 → 2.5.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [2.5.1](https://github.com/eliotstocker/Brsh-JS/compare/v2.5.0...v2.5.1) (2026-05-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * store binary data at runtime as uint8array rather than base64 string ([f2edfec](https://github.com/eliotstocker/Brsh-JS/commit/f2edfec18cb890846e152f71f1e033ee6f9c80f1))
7
+
8
+ # [2.5.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.4.1...v2.5.0) (2026-05-25)
9
+
10
+
11
+ ### Features
12
+
13
+ * interactive commands + pico demo + filesystem compression ([255ba2b](https://github.com/eliotstocker/Brsh-JS/commit/255ba2b782276c06116ff3118eccff0794b98ec7))
14
+
1
15
  ## [2.4.1](https://github.com/eliotstocker/Brsh-JS/compare/v2.4.0...v2.4.1) (2026-05-24)
2
16
 
3
17
 
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,17 @@ try {
70
76
  process.exit(1);
71
77
  }
72
78
  const { filesystem, permissions } = struct;
79
+
80
+ if (options.compress && !options.output) {
81
+ console.log('--compress requires --output (-o) to be set');
82
+ process.exit(1);
83
+ }
84
+
73
85
  const fsJson = JSON.stringify(filesystem, null, options.pretty ? 2 : null);
74
86
  const permJson = JSON.stringify(permissions, null, options.pretty ? 2 : null);
75
87
  const fsJS = fsJson.replace(/"(require\('.*?'\))"/gm, '$1');
76
88
 
77
- let JS = `module.exports = { filesystem: ${fsJS}, permissions: ${permJson} }`;
89
+ const JS = `module.exports = { filesystem: ${fsJS}, permissions: ${permJson} }`;
78
90
 
79
91
  const tf = tmp.fileSync({ postfix: '.tmp.js' });
80
92
  fs.writeFileSync(tf.name, JS);
@@ -143,5 +155,40 @@ esbuild.build({
143
155
  alias,
144
156
  })
145
157
  .then(() => {
158
+ if (options.compress) {
159
+ // Post-process: gzip the entire esbuild output.
160
+ // The compressed bytes are written to <output>.gz as raw binary.
161
+ // The JS file is replaced with a tiny loader that fetches the .gz,
162
+ // decompresses it, and executes it — no base64 overhead.
163
+ const bundle = fs.readFileSync(options.output, 'utf8');
164
+ // Append a return statement so new Function() can hand back the value
165
+ const codeToCompress = bundle + `\nreturn ${options.variable};`;
166
+ const compressed = zlib.gzipSync(Buffer.from(codeToCompress, 'utf8'));
167
+ const gzPath = options.output.replace(/\.js$/, '') + '.brfs';
168
+ fs.writeFileSync(gzPath, compressed);
169
+
170
+ const varName = options.variable;
171
+ // The loader captures document.currentScript.src synchronously
172
+ // (unavailable once the async IIFE runs) and derives the .brfs URL.
173
+ const loader =
174
+ `globalThis.${varName}=(function(){` +
175
+ `var s=typeof document!=="undefined"&&document.currentScript?document.currentScript.src:` +
176
+ `typeof location!=="undefined"?location.href:null;` +
177
+ `if(!s)throw new Error("${varName}: cannot resolve .brfs URL");` +
178
+ `var u=s.replace(/\\.js(\\?[^#]*)?$/,".brfs");` +
179
+ `return fetch(u)` +
180
+ `.then(function(r){return r.arrayBuffer();})` +
181
+ `.then(function(b){` +
182
+ `var ds=new DecompressionStream("gzip");` +
183
+ `var w=ds.writable.getWriter();` +
184
+ `w.write(new Uint8Array(b));` +
185
+ `w.close();` +
186
+ `return new Response(ds.readable).text();` +
187
+ `})` +
188
+ `.then(function(code){return new Function(code)();});` +
189
+ `})();`;
190
+ fs.writeFileSync(options.output, loader);
191
+ console.log(`Compressed bundle written to ${gzPath}`);
192
+ }
146
193
  console.log('Build succeeded');
147
194
  });
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*/