Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readline: fix tab completion bug #2816

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ Interface.prototype._tabComplete = function() {
var width = completions.reduce(function(a, b) {
return a.length > b.length ? a : b;
}).length + 2; // 2 space padding
var maxColumns = Math.floor(self.columns / width) || 1;
var maxColumns = Math.floor(self.columns / width);
if (!maxColumns || maxColumns === Infinity) {
maxColumns = 1;
}
var group = [], c;
for (var i = 0, compLen = completions.length; i < compLen; i++) {
c = completions[i];
Expand Down
36 changes: 36 additions & 0 deletions test/parallel/test-readline-undefined-columns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const assert = require('assert');
const PassThrough = require('stream').PassThrough;
const readline = require('readline');

// Checks that tab completion still works
// when output column size is undefined

const iStream = new PassThrough();
const oStream = new PassThrough();

const rli = readline.createInterface({
terminal: true,
input: iStream,
output: oStream,
completer: function(line, cb) {
cb(null, [['process.stdout', 'process.stdin', 'process.stderr'], line]);
}
});

var output = '';

oStream.on('data', function(data) {
output += data;
});

oStream.on('end', function() {
const expect = 'process.stdout\r\n' +
'process.stdin\r\n' +
'process.stderr';
assert(new RegExp(expect).test(output));
});

iStream.write('process.std\t');
oStream.end();