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];
--- /dev/null
+'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();