Move function declaration to top-level

Gets rid of a strict mode error and a few levels of indentation.
This commit is contained in:
Jonas Westerlund 2012-07-04 23:01:03 +02:00 коммит произвёл Nathan Rajlich
Родитель e5bb8391a8
Коммит 0b0b72c2fa
1 изменённых файлов: 28 добавлений и 28 удалений

Просмотреть файл

@ -346,43 +346,17 @@ Interface.prototype._tabComplete = function() {
return a.length > b.length ? a : b;
}).length + 2; // 2 space padding
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;
for (var i = 0, compLen = completions.length; i < compLen; i++) {
c = completions[i];
if (c === '') {
handleGroup(group);
handleGroup.call(self, group);
group = [];
} else {
group.push(c);
}
}
handleGroup(group);
handleGroup.call(self, group);
// If there is a common prefix to all matches, then apply that
// 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) {
if (!strings || strings.length == 0) {