]>
git.proxmox.com Git - mirror_xterm.js.git/blob - test/escape_sequences.js
1 var glob
= require('glob');
2 var fs
= require('fs');
3 var pty
= require('pty.js');
4 var sleep
= require('sleep');
5 var Terminal
= require('../src/xterm');
7 var CONSOLE_LOG
= console
.log
;
9 // expect files need terminal at 80x25!
13 // primitive pty pipe is enough for the test cases
14 var primitive_pty
= pty
.native.open(COLS
, ROWS
);
16 // fake sychronous pty write - read
17 // pty.js opens pipe fds with O_NONBLOCK
18 // just wait 10ms instead of setting fds to blocking mode
19 function pty_write_read(t
, s
) {
20 fs
.writeSync(t
.slave
, s
);
22 var b
= Buffer(64000);
23 var bytes
= fs
.readSync(t
.master
, b
, 0, 64000);
24 return b
.toString('utf8', 0, bytes
);
27 // generate noisy output to compare xterm and emulator
28 function formatError(in_
, out_
, expected
) {
29 function addLineNumber(start
, color
) {
30 var counter
= start
|| 0;
33 return '\x1b[33m' + (' ' + counter
).slice(-2) + color
+ s
;
36 var line80
= '12345678901234567890123456789012345678901234567890123456789012345678901234567890';
38 s
+= '\n\x1b[34m' + JSON
.stringify(in_
);
39 s
+= '\n\x1b[33m ' + line80
+ '\n';
40 s
+= out_
.split('\n').map(addLineNumber(0, '\x1b[31m')).join('\n');
41 s
+= '\n\x1b[33m ' + line80
+ '\n';
42 s
+= expected
.split('\n').map(addLineNumber(0, '\x1b[32m')).join('\n');
46 // simple debug output of terminal cells
47 function terminalToString(term
) {
50 for (var line
=0; line
<term
.rows
; ++line
) {
52 for (var cell
=0; cell
<term
.cols
; ++cell
) {
53 line_s
+= term
.lines
[line
][cell
][1];
55 // rtrim empty cells as xterm does
56 line_s
= line_s
.replace(/\s+$/, '');
63 describe('Escape code files', function() {
66 beforeEach(function () {
67 xterm
= new Terminal(80, 25);
70 // omit stack trace for escape sequence files
71 Error
.stackTraceLimit
= 0;
72 var files
= glob
.sync('test/escape_sequence_files/*.in');
73 // first 44 are the most basic escape sequences
74 for (var i
=0; i
<44; ++i
) {
75 //for (var i=0; i<files.length; ++i) {
77 it(filename
.split('/').slice(-1)[0], function () {
78 var in_file
= fs
.readFileSync(filename
, 'utf8');
79 var from_pty
= pty_write_read(primitive_pty
, in_file
);
80 // uncomment this to get log from terminal
81 console
.log = function(){};
82 xterm
.write(from_pty
);
83 var from_emulator
= terminalToString(xterm
);
84 console
.log
= CONSOLE_LOG
;
85 var expected
= fs
.readFileSync(filename
.split('.')[0] + '.text', 'utf8');
86 if (from_emulator
!= expected
) {
87 // uncomment to get noisy output
88 //throw new Error(formatError(in_file, from_emulator, expected));
89 throw new Error('mismatch');