brsh 2.8.1 → 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.
- package/.github/workflows/release.yml +3 -1
- package/CHANGELOG.md +25 -0
- package/bin/brsh-shell.js +16 -131
- package/bin/exportFileSystem.js +4 -0
- package/bin/zsh-server.js +261 -0
- package/dist/brsh.css +1 -1
- package/dist/shell.es.js +783 -418
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +30 -15
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +77 -100
- package/dist/terminal.cjs.js.map +1 -1
- package/dist/terminal.es.js +1382 -603
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +77 -100
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +266 -116
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +7 -5
- package/dist/wbt.min.js.map +1 -1
- package/index.js +472 -0
- package/lib/Command.js +30 -0
- package/lib/InteractiveCommand.js +28 -0
- package/lib/ReplCommand.js +15 -0
- package/lib/Terminal.js +769 -510
- package/lib/TtyStream.js +181 -0
- package/lib/builtins/cat.js +2 -2
- package/lib/builtins/grep.js +2 -2
- package/lib/local/clear.js +3 -0
- package/lib/terminal/DomRenderer.js +325 -0
- package/lib/terminal/PtyBridge.js +169 -0
- package/lib/terminal/ScreenBuffer.js +594 -0
- package/lib/terminal/VtParser.js +728 -0
- package/package.json +4 -2
- package/styles/terminal.css +33 -4
- package/test/terminal.test.js +762 -40
package/test/terminal.test.js
CHANGED
|
@@ -1,43 +1,98 @@
|
|
|
1
|
-
import { describe, it, expect,
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
2
|
import Shell from '../index.js';
|
|
3
3
|
import Terminal from '../lib/Terminal.js';
|
|
4
|
+
import Pico from '../demo/pico.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
function createMockDom() {
|
|
7
|
+
const windowListeners = {};
|
|
8
|
+
const makeElement = (tag = 'div') => {
|
|
9
|
+
const el = {
|
|
10
|
+
tagName: tag.toUpperCase(),
|
|
11
|
+
style: {},
|
|
12
|
+
className: '',
|
|
13
|
+
textContent: '',
|
|
14
|
+
_innerHTML: '',
|
|
15
|
+
children: [],
|
|
16
|
+
parentNode: null,
|
|
17
|
+
classList: {
|
|
18
|
+
_set: new Set(),
|
|
19
|
+
add(c) { this._set.add(c); },
|
|
20
|
+
remove(c) { this._set.delete(c); },
|
|
21
|
+
contains(c) { return this._set.has(c); }
|
|
22
|
+
},
|
|
23
|
+
_listeners: {},
|
|
24
|
+
appendChild(child) {
|
|
25
|
+
child.parentNode = el;
|
|
26
|
+
this.children.push(child);
|
|
27
|
+
return child;
|
|
28
|
+
},
|
|
29
|
+
removeChild(child) {
|
|
30
|
+
const idx = this.children.indexOf(child);
|
|
31
|
+
if (idx !== -1) {
|
|
32
|
+
this.children.splice(idx, 1);
|
|
33
|
+
child.parentNode = null;
|
|
34
|
+
}
|
|
35
|
+
return child;
|
|
36
|
+
},
|
|
37
|
+
setAttribute(k, v) { this[k] = v; },
|
|
38
|
+
addEventListener(ev, fn) {
|
|
39
|
+
if (!this._listeners[ev]) this._listeners[ev] = [];
|
|
40
|
+
this._listeners[ev].push(fn);
|
|
41
|
+
},
|
|
42
|
+
dispatchEvent(ev, payload = {}) {
|
|
43
|
+
const fns = this._listeners[ev] || [];
|
|
44
|
+
for (const fn of fns) fn(payload);
|
|
45
|
+
},
|
|
46
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 800, height: 480 }),
|
|
47
|
+
querySelectorAll: () => []
|
|
21
48
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
Object.defineProperty(el, 'innerHTML', {
|
|
50
|
+
get() { return this._innerHTML; },
|
|
51
|
+
set(v) { this._innerHTML = v; }
|
|
52
|
+
});
|
|
53
|
+
return el;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
globalThis.window = {
|
|
57
|
+
addEventListener(ev, fn) {
|
|
58
|
+
if (!windowListeners[ev]) windowListeners[ev] = [];
|
|
59
|
+
windowListeners[ev].push(fn);
|
|
60
|
+
},
|
|
61
|
+
removeEventListener(ev, fn) {
|
|
62
|
+
const list = windowListeners[ev];
|
|
63
|
+
if (!list) return;
|
|
64
|
+
const i = list.indexOf(fn);
|
|
65
|
+
if (i !== -1) list.splice(i, 1);
|
|
66
|
+
},
|
|
67
|
+
dispatchEvent(ev, payload = {}) {
|
|
68
|
+
const fns = windowListeners[ev] || [];
|
|
69
|
+
for (const fn of fns) fn(payload);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
globalThis.document = {
|
|
74
|
+
createElement: (tag) => makeElement(tag),
|
|
75
|
+
head: makeElement('head')
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return { makeElement, windowListeners };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function waitForReady(shell) {
|
|
82
|
+
return new Promise(resolve => {
|
|
83
|
+
const check = status => {
|
|
84
|
+
if (status === Shell.STATUS_READY) {
|
|
85
|
+
shell.removeListener('status', check);
|
|
86
|
+
resolve();
|
|
87
|
+
}
|
|
33
88
|
};
|
|
89
|
+
shell.on('status', check);
|
|
34
90
|
});
|
|
91
|
+
}
|
|
35
92
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
globalThis.Shell = originalShell;
|
|
40
|
-
globalThis.shell = originalGlobalShell;
|
|
93
|
+
describe('Terminal decoupling and Shell resolution', () => {
|
|
94
|
+
beforeEach(() => {
|
|
95
|
+
createMockDom();
|
|
41
96
|
});
|
|
42
97
|
|
|
43
98
|
it('instantiates with options.cli directly', () => {
|
|
@@ -91,14 +146,7 @@ describe('Terminal decoupling and Shell resolution', () => {
|
|
|
91
146
|
|
|
92
147
|
it('can be required as a CommonJS module via dist/terminal.cjs.js', () => {
|
|
93
148
|
const { createRequire } = require('module');
|
|
94
|
-
const fs = require('fs');
|
|
95
|
-
const path = require('path');
|
|
96
149
|
const cjsRequire = createRequire(import.meta.url);
|
|
97
|
-
const distFile = path.resolve(import.meta.dirname, '../dist/terminal.cjs.js');
|
|
98
|
-
if (!fs.existsSync(distFile)) {
|
|
99
|
-
const { execSync } = require('child_process');
|
|
100
|
-
execSync('npm run build:terminal', { stdio: 'ignore' });
|
|
101
|
-
}
|
|
102
150
|
const CjsTerminal = cjsRequire('../dist/terminal.cjs.js');
|
|
103
151
|
const TermClass = CjsTerminal.default || CjsTerminal;
|
|
104
152
|
expect(typeof TermClass).toBe('function');
|
|
@@ -111,3 +159,677 @@ describe('Terminal decoupling and Shell resolution', () => {
|
|
|
111
159
|
expect(term.cli).toBe(customShell);
|
|
112
160
|
});
|
|
113
161
|
});
|
|
162
|
+
|
|
163
|
+
describe('VT100 / ANSI Terminal Emulation & Line Rewriting', () => {
|
|
164
|
+
let term;
|
|
165
|
+
let container;
|
|
166
|
+
|
|
167
|
+
beforeEach(() => {
|
|
168
|
+
createMockDom();
|
|
169
|
+
container = document.createElement('div');
|
|
170
|
+
term = new Terminal({
|
|
171
|
+
el: container,
|
|
172
|
+
Shell: false,
|
|
173
|
+
cols: 80,
|
|
174
|
+
rows: 24,
|
|
175
|
+
cursor: 'block'
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('rewrites lines in-place using carriage return (\\r) and erase-in-line (\\x1b[K)', () => {
|
|
180
|
+
term.write('Downloading: 10%');
|
|
181
|
+
expect(term.getLineText(0)).toBe('Downloading: 10%');
|
|
182
|
+
|
|
183
|
+
term.write('\rDownloading: 55% (fast)');
|
|
184
|
+
expect(term.getLineText(0)).toBe('Downloading: 55% (fast)');
|
|
185
|
+
|
|
186
|
+
term.write('\r\x1b[2KDone!');
|
|
187
|
+
expect(term.getLineText(0)).toBe('Done!');
|
|
188
|
+
expect(term.getLineText(1)).toBe('');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('supports cursor addressing (CUP), relative movement (CUU/CUD/CUF/CUB), and save/restore (DECSC/DECRC)', () => {
|
|
192
|
+
term.write('\x1b[5;10HHello');
|
|
193
|
+
expect(term.getLineText(4)).toBe(' Hello');
|
|
194
|
+
|
|
195
|
+
// Save cursor, jump to row 1 col 1, write Header, then restore cursor and continue writing
|
|
196
|
+
term.write('\x1b7\x1b[1;1HHeader\x1b8 World!');
|
|
197
|
+
expect(term.getLineText(0)).toBe('Header');
|
|
198
|
+
expect(term.getLineText(4)).toBe(' Hello World!');
|
|
199
|
+
|
|
200
|
+
// Move up 2 rows, back 6 cols
|
|
201
|
+
term.write('\x1b[2A\x1b[6DAbove');
|
|
202
|
+
expect(term.getLineText(2)).toBe(' Above');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('supports DEC Special Graphics (ACS) box drawing characters used by blessed', () => {
|
|
206
|
+
term.write('\x1b(0lqqqk\r\nx\x1b(BHi!\x1b(0x\r\nmqqqj\x1b(B');
|
|
207
|
+
expect(term.getLineText(0)).toBe('┌───┐');
|
|
208
|
+
expect(term.getLineText(1)).toBe('│Hi!│');
|
|
209
|
+
expect(term.getLineText(2)).toBe('└───┘');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('supports alternate screen buffer (\\x1b[?1049h / \\x1b[?1049l) and restores primary screen on exit', () => {
|
|
213
|
+
term.writeln('Primary Line 1');
|
|
214
|
+
term.writeln('Primary Line 2');
|
|
215
|
+
expect(term.getLineText(0)).toBe('Primary Line 1');
|
|
216
|
+
expect(term.getLineText(1)).toBe('Primary Line 2');
|
|
217
|
+
|
|
218
|
+
// Enter alt screen
|
|
219
|
+
term.write('\x1b[?1049h\x1b[1;1HFull Screen App Content');
|
|
220
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
221
|
+
expect(term.getLineText(0)).toBe('Full Screen App Content');
|
|
222
|
+
expect(term.getLineText(1)).toBe('');
|
|
223
|
+
|
|
224
|
+
// Exit alt screen -> primary buffer & cursor restored
|
|
225
|
+
term.write('\x1b[?1049l');
|
|
226
|
+
expect(term.screen.isAltScreen).toBe(false);
|
|
227
|
+
expect(term.getLineText(0)).toBe('Primary Line 1');
|
|
228
|
+
expect(term.getLineText(1)).toBe('Primary Line 2');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('supports scroll regions (DECSTBM) and insert/delete lines & chars', () => {
|
|
232
|
+
term.write('\x1b[1;1HFixed Header');
|
|
233
|
+
term.write('\x1b[2;1HRow A');
|
|
234
|
+
term.write('\x1b[3;1HRow B');
|
|
235
|
+
term.write('\x1b[4;1HRow C');
|
|
236
|
+
term.write('\x1b[5;1HFixed Footer');
|
|
237
|
+
|
|
238
|
+
// Set scroll region to rows 2..4 and scroll up 1 line
|
|
239
|
+
term.write('\x1b[2;4r\x1b[4;1H\nNew Row D');
|
|
240
|
+
expect(term.getLineText(0)).toBe('Fixed Header');
|
|
241
|
+
expect(term.getLineText(1)).toBe('Row B');
|
|
242
|
+
expect(term.getLineText(2)).toBe('Row C');
|
|
243
|
+
expect(term.getLineText(3)).toBe('New Row D');
|
|
244
|
+
expect(term.getLineText(4)).toBe('Fixed Footer');
|
|
245
|
+
|
|
246
|
+
// Reset scroll region and test insert/delete chars (ICH/DCH)
|
|
247
|
+
term.write('\x1b[r\x1b[6;1HWorld\x1b[6;1H\x1b[6@Hello ');
|
|
248
|
+
expect(term.getLineText(5)).toBe('Hello World');
|
|
249
|
+
term.write('\x1b[6;1H\x1b[6P');
|
|
250
|
+
expect(term.getLineText(5)).toBe('World');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('renders SGR 16-color classes, 256-color palette, and 24-bit RGB styles', () => {
|
|
254
|
+
term.write('\x1b[1;31mRedBold\x1b[0m \x1b[38;5;208mOrange256\x1b[0m \x1b[48;2;10;20;30mTrueBg\x1b[0m');
|
|
255
|
+
const rowHtml = term.renderer._rowElements[0].innerHTML;
|
|
256
|
+
expect(rowHtml).toContain('ansi-red-fg');
|
|
257
|
+
expect(rowHtml).toContain('font-weight:bold');
|
|
258
|
+
expect(rowHtml).toContain('color:rgb(255, 135, 0)');
|
|
259
|
+
expect(rowHtml).toContain('background-color:rgb(10, 20, 30)');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('replies to DSR (\\x1b[6n) cursor position and DA (\\x1b[c) queries via onData', () => {
|
|
263
|
+
const responses = [];
|
|
264
|
+
term.onData(d => responses.push(d));
|
|
265
|
+
|
|
266
|
+
term.write('\x1b[4;12H\x1b[6n\x1b[c');
|
|
267
|
+
expect(responses).toEqual(['\x1b[4;12R', '\x1b[?1;2c']);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('HTTP / URL Auto-Linking and OSC 8 Hyperlinks', () => {
|
|
272
|
+
let term;
|
|
273
|
+
|
|
274
|
+
beforeEach(() => {
|
|
275
|
+
createMockDom();
|
|
276
|
+
term = new Terminal({
|
|
277
|
+
el: document.createElement('div'),
|
|
278
|
+
Shell: false,
|
|
279
|
+
cols: 100,
|
|
280
|
+
rows: 10
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('auto-detects http/https/mailto/tel links and excludes trailing punctuation', () => {
|
|
285
|
+
term.writeln('Visit https://example.com/docs/path?x=1, or mailto:test@example.com.');
|
|
286
|
+
const html = term.renderer._rowElements[0].innerHTML;
|
|
287
|
+
expect(html).toContain('<a href="https://example.com/docs/path?x=1" target="_blank" rel="noopener noreferrer" class="terminal__link">https://example.com/docs/path?x=1</a>,');
|
|
288
|
+
expect(html).toContain('<a href="mailto:test@example.com" target="_blank" rel="noopener noreferrer" class="terminal__link">mailto:test@example.com</a>.');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('renders OSC 8 explicit hyperlinks and blocks unsafe javascript: URLs', () => {
|
|
292
|
+
term.writeln('\x1b]8;;https://vibestac.kr\x07VibeStack\x1b]8;;\x07 and \x1b]8;;javascript:alert(1)\x07Evil\x1b]8;;\x07');
|
|
293
|
+
const html = term.renderer._rowElements[0].innerHTML;
|
|
294
|
+
expect(html).toContain('<a href="https://vibestac.kr" target="_blank" rel="noopener noreferrer" class="terminal__link">VibeStack</a>');
|
|
295
|
+
expect(html).not.toContain('javascript:alert');
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('Mouse Tracking & Scrollback Support', () => {
|
|
300
|
+
let term;
|
|
301
|
+
|
|
302
|
+
beforeEach(() => {
|
|
303
|
+
createMockDom();
|
|
304
|
+
term = new Terminal({
|
|
305
|
+
el: document.createElement('div'),
|
|
306
|
+
Shell: false,
|
|
307
|
+
cols: 80,
|
|
308
|
+
rows: 10
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('encodes SGR mouse press, drag, release, and wheel events when ?1002h and ?1006h are enabled', () => {
|
|
313
|
+
const events = [];
|
|
314
|
+
term.onData(d => events.push(d));
|
|
315
|
+
|
|
316
|
+
term.write('\x1b[?1002h\x1b[?1006h');
|
|
317
|
+
term.sendMouse('mousedown', { button: 0, col: 12, row: 5 });
|
|
318
|
+
term.sendMouse('mousemove', { button: 0, col: 15, row: 5 });
|
|
319
|
+
term.sendMouse('mouseup', { button: 0, col: 15, row: 5 });
|
|
320
|
+
term.sendMouse('wheel', { col: 10, row: 3, deltaY: -100 });
|
|
321
|
+
|
|
322
|
+
expect(events).toEqual([
|
|
323
|
+
'\x1b[<0;12;5M',
|
|
324
|
+
'\x1b[<32;15;5M',
|
|
325
|
+
'\x1b[<0;15;5m',
|
|
326
|
+
'\x1b[<64;10;3M'
|
|
327
|
+
]);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('scrolls the primary scrollback buffer on mouse wheel when mouse tracking is off', () => {
|
|
331
|
+
for (let i = 1; i <= 15; i++) {
|
|
332
|
+
term.writeln(`Line ${i}`);
|
|
333
|
+
}
|
|
334
|
+
// Bottom of viewport shows Line 7..15 + empty prompt line
|
|
335
|
+
expect(term.screen.viewportOffset).toBe(0);
|
|
336
|
+
term.sendMouse('wheel', { deltaY: -120 });
|
|
337
|
+
expect(term.screen.viewportOffset).toBe(3);
|
|
338
|
+
|
|
339
|
+
// Typing snaps viewport back to bottom
|
|
340
|
+
term.sendKey('a');
|
|
341
|
+
expect(term.screen.viewportOffset).toBe(0);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe('brsh Shell Integration, Line Editing, and Full-Screen Apps', () => {
|
|
346
|
+
let shell;
|
|
347
|
+
let term;
|
|
348
|
+
|
|
349
|
+
beforeEach(async () => {
|
|
350
|
+
createMockDom();
|
|
351
|
+
shell = new Shell({
|
|
352
|
+
filesystem: {
|
|
353
|
+
root: {
|
|
354
|
+
'hello.txt': 'Hello from file'
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
cwd: '/root',
|
|
358
|
+
hostname: 'brsh'
|
|
359
|
+
});
|
|
360
|
+
shell.context.setCommand(Pico);
|
|
361
|
+
const ready = waitForReady(shell);
|
|
362
|
+
term = new Terminal({
|
|
363
|
+
el: document.createElement('div'),
|
|
364
|
+
cli: shell,
|
|
365
|
+
cols: 80,
|
|
366
|
+
rows: 24,
|
|
367
|
+
cursor: 'blink'
|
|
368
|
+
});
|
|
369
|
+
await ready;
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('supports interactive line editing, cursor movement, history, and running commands', async () => {
|
|
373
|
+
expect(term.getLineText(0)).toBe('brsh:root$');
|
|
374
|
+
|
|
375
|
+
for (const ch of 'echo world') term.sendKey(ch);
|
|
376
|
+
expect(term.getLineText(0)).toBe('brsh:root$ echo world');
|
|
377
|
+
|
|
378
|
+
// Move back one word (Alt+ArrowLeft) and insert "hello "
|
|
379
|
+
term.sendKey('ArrowLeft', { alt: true });
|
|
380
|
+
for (const ch of 'hello ') term.sendKey(ch);
|
|
381
|
+
expect(term.getLineText(0)).toBe('brsh:root$ echo hello world');
|
|
382
|
+
|
|
383
|
+
const done = waitForReady(shell);
|
|
384
|
+
term.sendKey('Enter');
|
|
385
|
+
await done;
|
|
386
|
+
|
|
387
|
+
expect(term.getLineText(0)).toBe('brsh:root$ echo hello world');
|
|
388
|
+
expect(term.getLineText(1)).toBe('hello world');
|
|
389
|
+
expect(term.getLineText(2)).toBe('brsh:root$');
|
|
390
|
+
|
|
391
|
+
// Navigate history up
|
|
392
|
+
term.sendKey('ArrowUp');
|
|
393
|
+
expect(term.getLineText(2)).toBe('brsh:root$ echo hello world');
|
|
394
|
+
|
|
395
|
+
// Delete word with Alt+Backspace
|
|
396
|
+
term.sendKey('Backspace', { alt: true });
|
|
397
|
+
expect(term.getLineText(2)).toBe('brsh:root$ echo hello');
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('edits wrapped input lines in-place on backspace without repeating onto next line', async () => {
|
|
401
|
+
const narrowShell = new Shell({
|
|
402
|
+
filesystem: { root: {} },
|
|
403
|
+
cwd: '/root',
|
|
404
|
+
hostname: 'brsh'
|
|
405
|
+
});
|
|
406
|
+
const ready = waitForReady(narrowShell);
|
|
407
|
+
// Narrow terminal to 40 columns so input easily wraps
|
|
408
|
+
const narrowTerm = new Terminal({
|
|
409
|
+
el: document.createElement('div'),
|
|
410
|
+
cli: narrowShell,
|
|
411
|
+
cols: 40,
|
|
412
|
+
rows: 10
|
|
413
|
+
});
|
|
414
|
+
await ready;
|
|
415
|
+
|
|
416
|
+
// Prompt is 'brsh:root$ ' (11 chars). Typing 35 chars = 46 chars total (row 0 has 40, row 1 has 6).
|
|
417
|
+
for (const ch of '12345678901234567890123456789012345') narrowTerm.sendKey(ch);
|
|
418
|
+
expect(narrowTerm.getLineText(0)).toBe('brsh:root$ 12345678901234567890123456789');
|
|
419
|
+
expect(narrowTerm.getLineText(1)).toBe('012345');
|
|
420
|
+
expect(narrowTerm.screen.cursorRow).toBe(1);
|
|
421
|
+
|
|
422
|
+
// Backspace should edit row 1 in-place rather than repeating the line onto row 2
|
|
423
|
+
narrowTerm.sendKey('Backspace');
|
|
424
|
+
expect(narrowTerm.getLineText(0)).toBe('brsh:root$ 12345678901234567890123456789');
|
|
425
|
+
expect(narrowTerm.getLineText(1)).toBe('01234');
|
|
426
|
+
expect(narrowTerm.getLineText(2)).toBe('');
|
|
427
|
+
expect(narrowTerm.screen.cursorRow).toBe(1);
|
|
428
|
+
|
|
429
|
+
// Backspacing across the wrap boundary restores cursor cleanly back to row 0
|
|
430
|
+
for (let i = 0; i < 5; i++) narrowTerm.sendKey('Backspace');
|
|
431
|
+
expect(narrowTerm.getLineText(0)).toBe('brsh:root$ 12345678901234567890123456789');
|
|
432
|
+
expect(narrowTerm.getLineText(1)).toBe('');
|
|
433
|
+
narrowTerm.sendKey('Backspace');
|
|
434
|
+
expect(narrowTerm.getLineText(0)).toBe('brsh:root$ 1234567890123456789012345678');
|
|
435
|
+
expect(narrowTerm.screen.cursorRow).toBe(0);
|
|
436
|
+
expect(narrowTerm.screen.cursorCol).toBe(39);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('keeps cursor element visible when arrowing through input in blink mode', async () => {
|
|
440
|
+
expect(term.renderer.cursorStyle).toBe('blink');
|
|
441
|
+
for (const ch of 'abcde') term.sendKey(ch);
|
|
442
|
+
|
|
443
|
+
// Arrow left across input characters; cursor span is rendered on each step
|
|
444
|
+
const rowEl = term._cmdList.children[0];
|
|
445
|
+
term.sendKey('ArrowLeft');
|
|
446
|
+
expect(rowEl.innerHTML).toContain('class="terminal__cursor blink">e</span>');
|
|
447
|
+
|
|
448
|
+
term.sendKey('ArrowLeft');
|
|
449
|
+
expect(rowEl.innerHTML).toContain('class="terminal__cursor blink">d</span>');
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('runs pico in the alternate screen buffer and restores shell screen on exit', async () => {
|
|
453
|
+
await shell.onCommand('echo before-pico');
|
|
454
|
+
expect(term.getLineText(0)).toContain('before-pico');
|
|
455
|
+
|
|
456
|
+
// Start pico
|
|
457
|
+
const picoDone = waitForReady(shell);
|
|
458
|
+
shell.onCommand('pico notes.txt');
|
|
459
|
+
await new Promise(r => setTimeout(r, 20));
|
|
460
|
+
|
|
461
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
462
|
+
expect(term.getLineText(0)).toContain('pico notes.txt');
|
|
463
|
+
|
|
464
|
+
// Type inside pico, save (^S), and exit (^X)
|
|
465
|
+
for (const ch of 'Real terminal text') term.sendKey(ch);
|
|
466
|
+
term.sendKey('s', { ctrl: true });
|
|
467
|
+
term.sendKey('x', { ctrl: true });
|
|
468
|
+
await picoDone;
|
|
469
|
+
|
|
470
|
+
expect(term.screen.isAltScreen).toBe(false);
|
|
471
|
+
expect(term.getLineText(0)).toContain('before-pico');
|
|
472
|
+
expect(shell.context.fs._getFileRaw('/root/notes.txt')).toBe('Real terminal text');
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('allows a brsh Command to control the terminal directly via this.stdout and this.stdin', async () => {
|
|
476
|
+
class BlessedLikeCmd extends Shell.Command {
|
|
477
|
+
static get name() { return 'tuicmd'; }
|
|
478
|
+
run() {
|
|
479
|
+
return new Promise(resolve => {
|
|
480
|
+
this.stdin.setEncoding('utf8');
|
|
481
|
+
this.stdin.setRawMode(true);
|
|
482
|
+
this.stdout.write(
|
|
483
|
+
'\x1b[?1049h\x1b[?25l\x1b[?1000h\x1b[?1006h\x1b[2J\x1b[H' +
|
|
484
|
+
'\x1b(0lqqqqqqqqqqqqqqk\x1b(B\r\n' +
|
|
485
|
+
'\x1b(0x\x1b(B Status: IDLE \x1b(0x\x1b(B\r\n' +
|
|
486
|
+
'\x1b(0mqqqqqqqqqqqqqqj\x1b(B'
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
this.stdin.on('data', (chunk) => {
|
|
490
|
+
if (chunk.startsWith('\x1b[<0;')) {
|
|
491
|
+
// Mouse click received via this.stdin -> rewrite row 2 in-place via this.stdout
|
|
492
|
+
this.stdout.write('\x1b[2;3HStatus: CLICK');
|
|
493
|
+
} else if (chunk === 'q') {
|
|
494
|
+
this.stdout.write('\x1b[?1006l\x1b[?1000l\x1b[?25h\x1b[?1049l');
|
|
495
|
+
this.stdin.setRawMode(false);
|
|
496
|
+
resolve();
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
shell.context.setCommand(BlessedLikeCmd);
|
|
504
|
+
const cmdDone = waitForReady(shell);
|
|
505
|
+
shell.onCommand('tuicmd');
|
|
506
|
+
await new Promise(r => setTimeout(r, 20));
|
|
507
|
+
|
|
508
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
509
|
+
expect(term.getLineText(0)).toBe('┌──────────────┐');
|
|
510
|
+
expect(term.getLineText(1)).toBe('│ Status: IDLE │');
|
|
511
|
+
expect(term.getLineText(2)).toBe('└──────────────┘');
|
|
512
|
+
|
|
513
|
+
// Click inside the TUI box -> routed through shell.stdin -> cmd.stdin
|
|
514
|
+
term.sendMouse('mousedown', { button: 0, col: 5, row: 2 });
|
|
515
|
+
expect(term.getLineText(1)).toBe('│ Status: CLICK│');
|
|
516
|
+
|
|
517
|
+
// Press 'q' to exit TUI command
|
|
518
|
+
term.sendKey('q');
|
|
519
|
+
await cmdDone;
|
|
520
|
+
|
|
521
|
+
expect(term.screen.isAltScreen).toBe(false);
|
|
522
|
+
expect(term.getLineText(0)).toContain('brsh:root$ tuicmd');
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('runs a full-screen ReplCommand (used by wbt interactive REPLs) and restores screen on exit', async () => {
|
|
526
|
+
class DemoRepl extends Shell.ReplCommand {
|
|
527
|
+
static get name() { return 'demorepl'; }
|
|
528
|
+
shouldBeInteractive() { return true; }
|
|
529
|
+
getReplTitle() { return 'Demo Interactive REPL'; }
|
|
530
|
+
getReplPrompt() { return 'demo> '; }
|
|
531
|
+
async evaluateReplLine(line) {
|
|
532
|
+
return { output: [`result: ${line.toUpperCase()}`] };
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
shell.context.setCommand(DemoRepl);
|
|
537
|
+
const replDone = waitForReady(shell);
|
|
538
|
+
shell.onCommand('demorepl');
|
|
539
|
+
await new Promise(r => setTimeout(r, 30));
|
|
540
|
+
|
|
541
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
542
|
+
expect(term.getLineText(0)).toContain('Demo Interactive REPL');
|
|
543
|
+
|
|
544
|
+
for (const ch of 'hello repl') term.sendKey(ch);
|
|
545
|
+
term.sendKey('Enter');
|
|
546
|
+
await new Promise(r => setTimeout(r, 30));
|
|
547
|
+
|
|
548
|
+
expect(term.getScreenText()).toContain('demo> hello repl');
|
|
549
|
+
expect(term.getScreenText()).toContain('result: HELLO REPL');
|
|
550
|
+
|
|
551
|
+
// Exit REPL with Ctrl+D
|
|
552
|
+
term.sendKey('d', { ctrl: true });
|
|
553
|
+
await replDone;
|
|
554
|
+
|
|
555
|
+
expect(term.screen.isAltScreen).toBe(false);
|
|
556
|
+
expect(term.getLineText(0)).toContain('brsh:root$ demorepl');
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
describe('TUI (blessed-style) Application over Virtual TTY & Real zsh PTY Compatibility', () => {
|
|
561
|
+
beforeEach(() => {
|
|
562
|
+
createMockDom();
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('renders a blessed-style TUI application with box borders, scroll regions, mouse & keyboard over createTty()', () => {
|
|
566
|
+
const term = new Terminal({
|
|
567
|
+
el: document.createElement('div'),
|
|
568
|
+
Shell: false,
|
|
569
|
+
cols: 40,
|
|
570
|
+
rows: 10
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
term.writeln('Shell history before TUI');
|
|
574
|
+
const tty = term.createTty();
|
|
575
|
+
expect(tty.stdin.isTTY).toBe(true);
|
|
576
|
+
expect(tty.stdout.isTTY).toBe(true);
|
|
577
|
+
expect(tty.stdout.getWindowSize()).toEqual([40, 10]);
|
|
578
|
+
|
|
579
|
+
const receivedInput = [];
|
|
580
|
+
tty.stdin.setEncoding('utf8');
|
|
581
|
+
tty.stdin.on('data', d => receivedInput.push(d));
|
|
582
|
+
|
|
583
|
+
// Simulate blessed entering alt screen, hiding cursor, enabling SGR mouse, and drawing a bordered box
|
|
584
|
+
tty.stdout.write(
|
|
585
|
+
'\x1b[?1049h\x1b[?25l\x1b[?1000h\x1b[?1006h\x1b[2J\x1b[H' +
|
|
586
|
+
'\x1b(0lqqqqqqqqqqqqqqqqqqk\x1b(B\r\n' +
|
|
587
|
+
'\x1b(0x\x1b(B \x1b[1;32mBlessed TUI Box\x1b[0m \x1b(0x\x1b(B\r\n' +
|
|
588
|
+
'\x1b(0x\x1b(B > Item 1 \x1b(0x\x1b(B\r\n' +
|
|
589
|
+
'\x1b(0x\x1b(B Item 2 \x1b(0x\x1b(B\r\n' +
|
|
590
|
+
'\x1b(0mqqqqqqqqqqqqqqqqqqj\x1b(B'
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
594
|
+
expect(term.screen.cursorVisible).toBe(false);
|
|
595
|
+
expect(term.getLineText(0)).toBe('┌──────────────────┐');
|
|
596
|
+
expect(term.getLineText(1)).toBe('│ Blessed TUI Box │');
|
|
597
|
+
expect(term.getLineText(2)).toBe('│ > Item 1 │');
|
|
598
|
+
expect(term.getLineText(3)).toBe('│ Item 2 │');
|
|
599
|
+
expect(term.getLineText(4)).toBe('└──────────────────┘');
|
|
600
|
+
|
|
601
|
+
// Send key navigation and mouse click to the TUI app
|
|
602
|
+
term.sendKey('ArrowDown');
|
|
603
|
+
term.sendMouse('mousedown', { button: 0, col: 5, row: 4 });
|
|
604
|
+
expect(receivedInput).toEqual(['\x1b[B', '\x1b[<0;5;4M']);
|
|
605
|
+
|
|
606
|
+
// Update only rows 3 & 4 in-place via cursor addressing (like blessed smartCSR)
|
|
607
|
+
tty.stdout.write('\x1b[3;3H Item 1\x1b[4;3H> Item 2');
|
|
608
|
+
expect(term.getLineText(2)).toBe('│ Item 1 │');
|
|
609
|
+
expect(term.getLineText(3)).toBe('│ > Item 2 │');
|
|
610
|
+
|
|
611
|
+
// Exit TUI app
|
|
612
|
+
tty.stdout.write('\x1b[?1006l\x1b[?1000l\x1b[?25h\x1b[?1049l');
|
|
613
|
+
tty.dispose();
|
|
614
|
+
|
|
615
|
+
expect(term.screen.isAltScreen).toBe(false);
|
|
616
|
+
expect(term.getLineText(0)).toBe('Shell history before TUI');
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
it('spawns and interacts with a real shell process in a PTY', async () => {
|
|
620
|
+
const req = typeof require === 'function' ? require : null;
|
|
621
|
+
const fs = req ? req('fs') : null;
|
|
622
|
+
const candidates = [
|
|
623
|
+
{ cmd: '/bin/zsh', args: ['-f'], prompt: 'zsh-pty$ ', promptRegex: /zsh-pty\$/ },
|
|
624
|
+
{ cmd: '/usr/bin/zsh', args: ['-f'], prompt: 'zsh-pty$ ', promptRegex: /zsh-pty\$/ },
|
|
625
|
+
{ cmd: '/bin/bash', args: ['--norc', '--noprofile'], prompt: 'bash-pty$ ', promptRegex: /bash-pty\$/ },
|
|
626
|
+
{ cmd: '/usr/bin/bash', args: ['--norc', '--noprofile'], prompt: 'bash-pty$ ', promptRegex: /bash-pty\$/ },
|
|
627
|
+
{ cmd: '/bin/sh', args: [], prompt: 'sh-pty$ ', promptRegex: /sh-pty\$/ }
|
|
628
|
+
];
|
|
629
|
+
const match = candidates.find(c => fs && fs.existsSync(c.cmd));
|
|
630
|
+
if (!match) return;
|
|
631
|
+
|
|
632
|
+
const term = new Terminal({
|
|
633
|
+
el: document.createElement('div'),
|
|
634
|
+
Shell: false,
|
|
635
|
+
cols: 80,
|
|
636
|
+
rows: 24
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
const { pty, detach } = term.spawn(match.cmd, match.args, {
|
|
640
|
+
env: { PS1: match.prompt }
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
const waitForScreenMatch = (regex, timeoutMs = 4000) => {
|
|
644
|
+
return new Promise((resolve, reject) => {
|
|
645
|
+
const start = Date.now();
|
|
646
|
+
const timer = setInterval(() => {
|
|
647
|
+
const text = term.getScreenText();
|
|
648
|
+
if (regex.test(text)) {
|
|
649
|
+
clearInterval(timer);
|
|
650
|
+
resolve(text);
|
|
651
|
+
} else if (Date.now() - start > timeoutMs) {
|
|
652
|
+
clearInterval(timer);
|
|
653
|
+
reject(new Error(`Timed out waiting for ${regex}. Screen:\n${text}`));
|
|
654
|
+
}
|
|
655
|
+
}, 20);
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
try {
|
|
660
|
+
await waitForScreenMatch(match.promptRegex);
|
|
661
|
+
|
|
662
|
+
// Run a command and an in-place carriage-return line rewrite in real shell
|
|
663
|
+
term.onCommand('printf "step1\\rstep2-rewritten\\n"; echo SHELL_OK_$((20 + 22))');
|
|
664
|
+
const screenText = await waitForScreenMatch(/SHELL_OK_42/);
|
|
665
|
+
|
|
666
|
+
expect(term.getLineText(1)).toBe('step2-rewritten');
|
|
667
|
+
expect(screenText).toContain('SHELL_OK_42');
|
|
668
|
+
} finally {
|
|
669
|
+
detach();
|
|
670
|
+
pty.kill();
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
it('runs a real OS ncurses (Python curses) full-screen application in a PTY and restores screen on exit', async () => {
|
|
675
|
+
const term = new Terminal({
|
|
676
|
+
el: document.createElement('div'),
|
|
677
|
+
Shell: false,
|
|
678
|
+
cols: 60,
|
|
679
|
+
rows: 15
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
term.writeln('Primary shell line before ncurses');
|
|
683
|
+
|
|
684
|
+
const cursesScript = [
|
|
685
|
+
'import curses',
|
|
686
|
+
'def main(stdscr):',
|
|
687
|
+
' curses.curs_set(0)',
|
|
688
|
+
' stdscr.clear()',
|
|
689
|
+
' win = curses.newwin(6, 30, 2, 4)',
|
|
690
|
+
' win.box()',
|
|
691
|
+
' win.addstr(1, 2, "Real NCURSES Window")',
|
|
692
|
+
' win.addstr(3, 2, "Press j to update, q to quit")',
|
|
693
|
+
' stdscr.refresh()',
|
|
694
|
+
' win.refresh()',
|
|
695
|
+
' while True:',
|
|
696
|
+
' ch = win.getch()',
|
|
697
|
+
' if ch == ord("j"):',
|
|
698
|
+
' win.addstr(2, 2, "State: UPDATED")',
|
|
699
|
+
' win.refresh()',
|
|
700
|
+
' elif ch == ord("q"):',
|
|
701
|
+
' break',
|
|
702
|
+
'curses.wrapper(main)'
|
|
703
|
+
].join('\n');
|
|
704
|
+
|
|
705
|
+
const { pty, detach } = term.spawn('python3', ['-c', cursesScript]);
|
|
706
|
+
|
|
707
|
+
const waitForScreen = (predicate, timeoutMs = 4000) => {
|
|
708
|
+
return new Promise((resolve, reject) => {
|
|
709
|
+
const start = Date.now();
|
|
710
|
+
const timer = setInterval(() => {
|
|
711
|
+
if (predicate()) {
|
|
712
|
+
clearInterval(timer);
|
|
713
|
+
resolve();
|
|
714
|
+
} else if (Date.now() - start > timeoutMs) {
|
|
715
|
+
clearInterval(timer);
|
|
716
|
+
reject(new Error(`Timed out waiting for curses screen:\n${term.getScreenText()}`));
|
|
717
|
+
}
|
|
718
|
+
}, 20);
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
try {
|
|
723
|
+
await waitForScreen(() => term.getScreenText().includes('Real NCURSES Window'));
|
|
724
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
725
|
+
expect(term.getLineText(2)).toContain('┌────────────────────────────┐');
|
|
726
|
+
expect(term.getLineText(3)).toContain('│ Real NCURSES Window │');
|
|
727
|
+
|
|
728
|
+
// Send 'j' keystroke to update window in-place via ncurses cursor addressing
|
|
729
|
+
term.sendKey('j');
|
|
730
|
+
await waitForScreen(() => term.getScreenText().includes('State: UPDATED'));
|
|
731
|
+
expect(term.getLineText(4)).toContain('│ State: UPDATED │');
|
|
732
|
+
|
|
733
|
+
// Send 'q' keystroke to exit ncurses and restore primary screen
|
|
734
|
+
term.sendKey('q');
|
|
735
|
+
await waitForScreen(() => !term.screen.isAltScreen);
|
|
736
|
+
expect(term.getLineText(0)).toBe('Primary shell line before ncurses');
|
|
737
|
+
} finally {
|
|
738
|
+
detach();
|
|
739
|
+
pty.kill();
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
describe('Output Typing Animation Suppression', () => {
|
|
745
|
+
beforeEach(() => {
|
|
746
|
+
createMockDom();
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
it('renders user typing input instantly even when outputAnimation is "type"', async () => {
|
|
750
|
+
const shell = new Shell({
|
|
751
|
+
filesystem: { root: {} },
|
|
752
|
+
cwd: '/root',
|
|
753
|
+
hostname: 'brsh'
|
|
754
|
+
});
|
|
755
|
+
const ready = waitForReady(shell);
|
|
756
|
+
|
|
757
|
+
const term = new Terminal({
|
|
758
|
+
el: document.createElement('div'),
|
|
759
|
+
cli: shell,
|
|
760
|
+
cols: 80,
|
|
761
|
+
rows: 24,
|
|
762
|
+
outputAnimation: 'type',
|
|
763
|
+
animateSpeed: 1
|
|
764
|
+
});
|
|
765
|
+
await ready;
|
|
766
|
+
|
|
767
|
+
try {
|
|
768
|
+
// Normal multi-line output is queued for typing animation (not rendered synchronously)
|
|
769
|
+
term.writeln('Animated background output line');
|
|
770
|
+
expect(term.getScreenText()).not.toContain('Animated background output line');
|
|
771
|
+
|
|
772
|
+
// User typing into the terminal flushes pending animation and renders keystrokes synchronously
|
|
773
|
+
term.sendKey('e');
|
|
774
|
+
term.sendKey('c');
|
|
775
|
+
term.sendKey('h');
|
|
776
|
+
term.sendKey('o');
|
|
777
|
+
expect(term.getScreenText()).toContain('brsh:root$ echo');
|
|
778
|
+
} finally {
|
|
779
|
+
term.reset();
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
it('renders same-line rewrites (\\r, \\x1b[K) instantly without re-animating the line', () => {
|
|
784
|
+
const term = new Terminal({
|
|
785
|
+
el: document.createElement('div'),
|
|
786
|
+
Shell: false,
|
|
787
|
+
cols: 60,
|
|
788
|
+
rows: 10,
|
|
789
|
+
outputAnimation: 'type',
|
|
790
|
+
animateSpeed: 1
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
try {
|
|
794
|
+
term.write('\rDownloading: [### ] 30%\x1b[K');
|
|
795
|
+
expect(term.getLineText(0)).toBe('Downloading: [### ] 30%');
|
|
796
|
+
|
|
797
|
+
term.write('\rDownloading: [####### ] 70%\x1b[K');
|
|
798
|
+
expect(term.getLineText(0)).toBe('Downloading: [####### ] 70%');
|
|
799
|
+
|
|
800
|
+
term.write('\rDownloading: [##########] 100%\x1b[K');
|
|
801
|
+
expect(term.getLineText(0)).toBe('Downloading: [##########] 100%');
|
|
802
|
+
} finally {
|
|
803
|
+
term.reset();
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
it('renders full-screen apps instantly without typing animation', () => {
|
|
808
|
+
const term = new Terminal({
|
|
809
|
+
el: document.createElement('div'),
|
|
810
|
+
Shell: false,
|
|
811
|
+
cols: 60,
|
|
812
|
+
rows: 10,
|
|
813
|
+
outputAnimation: 'type',
|
|
814
|
+
animateSpeed: 1
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
try {
|
|
818
|
+
// Entering alternate screen buffer + rendering full screen happens synchronously on write()
|
|
819
|
+
term.write('\x1b[?1049h\x1b[2J\x1b[HFull Screen Header\r\nBody Row 1');
|
|
820
|
+
expect(term.screen.isAltScreen).toBe(true);
|
|
821
|
+
expect(term.getLineText(0)).toBe('Full Screen Header');
|
|
822
|
+
expect(term.getLineText(1)).toBe('Body Row 1');
|
|
823
|
+
|
|
824
|
+
// Updating inside the full-screen app is also synchronous
|
|
825
|
+
term.write('\x1b[2;1HBody Row 1 Updated');
|
|
826
|
+
expect(term.getLineText(1)).toBe('Body Row 1 Updated');
|
|
827
|
+
|
|
828
|
+
// Exiting alternate screen buffer is synchronous
|
|
829
|
+
term.write('\x1b[?1049l');
|
|
830
|
+
expect(term.screen.isAltScreen).toBe(false);
|
|
831
|
+
} finally {
|
|
832
|
+
term.reset();
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
});
|