Skip to content

Commit e29e470

Browse files
mtharrisonsilverwind
authored andcommittedSep 18, 2015
readline: fix tab completion bug
This fixes a problem where tab completion is empty when the input stream column size is undefined. As a solution we can force maxColumns to 1 in this scenario. PR-URL: #2816 Fixes: #2396 Reviewed-By: Roman Reiss <[email protected]>
1 parent 0a329d2 commit e29e470

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
 

‎lib/readline.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ Interface.prototype._tabComplete = function() {
390390
var width = completions.reduce(function(a, b) {
391391
return a.length > b.length ? a : b;
392392
}).length + 2; // 2 space padding
393-
var maxColumns = Math.floor(self.columns / width) || 1;
393+
var maxColumns = Math.floor(self.columns / width);
394+
if (!maxColumns || maxColumns === Infinity) {
395+
maxColumns = 1;
396+
}
394397
var group = [], c;
395398
for (var i = 0, compLen = completions.length; i < compLen; i++) {
396399
c = completions[i];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const PassThrough = require('stream').PassThrough;
5+
const readline = require('readline');
6+
7+
// Checks that tab completion still works
8+
// when output column size is undefined
9+
10+
const iStream = new PassThrough();
11+
const oStream = new PassThrough();
12+
13+
const rli = readline.createInterface({
14+
terminal: true,
15+
input: iStream,
16+
output: oStream,
17+
completer: function(line, cb) {
18+
cb(null, [['process.stdout', 'process.stdin', 'process.stderr'], line]);
19+
}
20+
});
21+
22+
var output = '';
23+
24+
oStream.on('data', function(data) {
25+
output += data;
26+
});
27+
28+
oStream.on('end', function() {
29+
const expect = 'process.stdout\r\n' +
30+
'process.stdin\r\n' +
31+
'process.stderr';
32+
assert(new RegExp(expect).test(output));
33+
});
34+
35+
iStream.write('process.std\t');
36+
oStream.end();

0 commit comments

Comments
 (0)