brsh 2.5.2 → 2.5.4

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/index.js CHANGED
@@ -34,6 +34,12 @@ class Shell extends EventEmitter {
34
34
  onFsChange: typeof onFsChange === 'function' ? onFsChange : null
35
35
  }));
36
36
 
37
+ this._readonlyContext = Object.freeze({
38
+ getVar: (v) => this.context.getVar(v),
39
+ getAlias: (a) => this.context.getAlias(a),
40
+ getCommand: (c) => this.context.getCommand(c),
41
+ });
42
+
37
43
  this.context.setVar('PATH', path);
38
44
  this.context.setVar('HOST', hostname);
39
45
  if (useRealFilesystem) {
@@ -223,7 +229,7 @@ class Shell extends EventEmitter {
223
229
  if(Cmd.prototype instanceof LocalCommand || new Cmd() instanceof ScriptCommand) {
224
230
  instance = new Cmd(args, this.context);
225
231
  } else if(isCommandClass(Cmd)) {
226
- instance = new Cmd(args);
232
+ instance = new Cmd(args, this._readonlyContext);
227
233
  } else {
228
234
  this.emit('stdErr', `${bin}: Command not found`);
229
235
  this.lastCode = 1;
package/lib/Command.js CHANGED
@@ -6,10 +6,11 @@ const Result = require('./Result');
6
6
  const EventEmitter = events.EventEmitter || events.default || events;
7
7
 
8
8
  class Command extends EventEmitter {
9
- constructor(args) {
9
+ constructor(args, context) {
10
10
  super();
11
11
  this.arguments = args;
12
12
  this.result = new Result();
13
+ this.context = context || null;
13
14
  }
14
15
 
15
16
  get name() {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const LocalCommand = require('./local/LocalCommand');
3
+ const Command = require('./Command');
4
4
 
5
5
  /**
6
6
  * Base class for interactive full-screen terminal applications (e.g. text editors).
@@ -19,7 +19,7 @@ const LocalCommand = require('./local/LocalCommand');
19
19
  *
20
20
  * Terminal size is available via `this.terminalSize` → `{ cols, rows }`.
21
21
  */
22
- class InteractiveCommand extends LocalCommand {
22
+ class InteractiveCommand extends Command {
23
23
  /**
24
24
  * Tells Shell to route all keystrokes here via onInput().
25
25
  */
package/lib/Terminal.js CHANGED
@@ -149,15 +149,23 @@ class Terminal {
149
149
  this._screen.style.fontFamily = `'${font}', monospace`;
150
150
  parent.appendChild(this._screen);
151
151
 
152
- // Hidden single-character span for measuring character cell dimensions
152
+ // Hidden single-character span for measuring character cell dimensions.
153
+ // fontFamily must be set explicitly to match _cmdList — without it the span
154
+ // inherits from the page font, giving a wrong character width.
153
155
  this._charMeasure = document.createElement('span');
154
156
  this._charMeasure.className = 'terminal__char-measure';
157
+ this._charMeasure.style.fontFamily = `'${font}', monospace`;
155
158
  this._charMeasure.textContent = 'X';
156
159
  this._charMeasure.setAttribute('aria-hidden', 'true');
157
160
  parent.appendChild(this._charMeasure);
158
161
 
159
- // Measure on first paint, then track container resizes
162
+ // Measure on first paint, then re-measure once the webfont is ready
163
+ // (the setTimeout fires before the Google Font downloads, so the initial
164
+ // measurement uses the fallback font; document.fonts.ready corrects it).
160
165
  setTimeout(() => this._measureAndSetSize(), 0);
166
+ if (document.fonts) {
167
+ document.fonts.ready.then(() => this._measureAndSetSize());
168
+ }
161
169
  if (typeof ResizeObserver !== 'undefined') {
162
170
  new ResizeObserver(() => this._measureAndSetSize()).observe(parent);
163
171
  }
@@ -4,8 +4,7 @@ const Command = require('../Command');
4
4
 
5
5
  class LocalCommand extends Command {
6
6
  constructor(args, context) {
7
- super(args);
8
- this.context = context;
7
+ super(args, context);
9
8
  }
10
9
  }
11
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brsh",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "A unix like shell written in javascript",
5
5
  "main": "./dist/shell.min.js",
6
6
  "module": "./dist/shell.es.js",