Browse Source

Move function declaration to top-level

Gets rid of a strict mode error and a few levels of indentation.
v0.8.7-release
Jonas Westerlund 13 years ago
committed by Nathan Rajlich
parent
commit
0b0b72c2fa
  1. 56
      lib/readline.js

56
lib/readline.js

@ -346,43 +346,17 @@ Interface.prototype._tabComplete = function() {
return a.length > b.length ? a : b; return a.length > b.length ? a : b;
}).length + 2; // 2 space padding }).length + 2; // 2 space padding
var maxColumns = Math.floor(self.columns / width) || 1; var maxColumns = Math.floor(self.columns / width) || 1;
function handleGroup(group) {
if (group.length == 0) {
return;
}
var minRows = Math.ceil(group.length / maxColumns);
for (var row = 0; row < minRows; row++) {
for (var col = 0; col < maxColumns; col++) {
var idx = row * maxColumns + col;
if (idx >= group.length) {
break;
}
var item = group[idx];
self.output.write(item);
if (col < maxColumns - 1) {
for (var s = 0, itemLen = item.length; s < width - itemLen;
s++) {
self.output.write(' ');
}
}
}
self.output.write('\r\n');
}
self.output.write('\r\n');
}
var group = [], c; var group = [], c;
for (var i = 0, compLen = completions.length; i < compLen; i++) { for (var i = 0, compLen = completions.length; i < compLen; i++) {
c = completions[i]; c = completions[i];
if (c === '') { if (c === '') {
handleGroup(group); handleGroup.call(self, group);
group = []; group = [];
} else { } else {
group.push(c); group.push(c);
} }
} }
handleGroup(group); handleGroup.call(self, group);
// If there is a common prefix to all matches, then apply that // If there is a common prefix to all matches, then apply that
// portion. // portion.
@ -398,6 +372,32 @@ Interface.prototype._tabComplete = function() {
}); });
}; };
// this = Interface instance
function handleGroup(group) {
var self = this;
if (group.length == 0) {
return;
}
var minRows = Math.ceil(group.length / maxColumns);
for (var row = 0; row < minRows; row++) {
for (var col = 0; col < maxColumns; col++) {
var idx = row * maxColumns + col;
if (idx >= group.length) {
break;
}
var item = group[idx];
self.output.write(item);
if (col < maxColumns - 1) {
for (var s = 0, itemLen = item.length; s < width - itemLen;
s++) {
self.output.write(' ');
}
}
}
self.output.write('\r\n');
}
self.output.write('\r\n');
}
function commonPrefix(strings) { function commonPrefix(strings) {
if (!strings || strings.length == 0) { if (!strings || strings.length == 0) {

Loading…
Cancel
Save