Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4cd5ac

Browse filesBrowse files
mtharrisonFishrock123
authored andcommitted
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 <me@silverwind.io>
1 parent d63e02e commit d4cd5ac
Copy full SHA for d4cd5ac

File tree

Expand file treeCollapse file tree

2 files changed

+40
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-1
lines changed
Open diff view settings
Collapse file

‎lib/readline.js‎

Copy file name to clipboardExpand all lines: lib/readline.js
+4-1Lines changed: 4 additions & 1 deletion
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];
Collapse file
+36Lines changed: 36 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.