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. 54
      lib/readline.js

54
lib/readline.js

@ -346,8 +346,35 @@ 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;
var group = [], c;
for (var i = 0, compLen = completions.length; i < compLen; i++) {
c = completions[i];
if (c === '') {
handleGroup.call(self, group);
group = [];
} else {
group.push(c);
}
}
handleGroup.call(self, group);
// If there is a common prefix to all matches, then apply that
// portion.
var f = completions.filter(function(e) { if (e) return e; });
var prefix = commonPrefix(f);
if (prefix.length > completeOn.length) {
self._insertString(prefix.slice(completeOn.length));
}
}
self._refreshLine();
}
});
};
// this = Interface instance
function handleGroup(group) { function handleGroup(group) {
var self = this;
if (group.length == 0) { if (group.length == 0) {
return; return;
} }
@ -372,33 +399,6 @@ Interface.prototype._tabComplete = function() {
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);
group = [];
} else {
group.push(c);
}
}
handleGroup(group);
// If there is a common prefix to all matches, then apply that
// portion.
var f = completions.filter(function(e) { if (e) return e; });
var prefix = commonPrefix(f);
if (prefix.length > completeOn.length) {
self._insertString(prefix.slice(completeOn.length));
}
}
self._refreshLine();
}
});
};
function commonPrefix(strings) { function commonPrefix(strings) {
if (!strings || strings.length == 0) { if (!strings || strings.length == 0) {
return ''; return '';

Loading…
Cancel
Save