Reputation:
The output of tab completion in the Scala REPL reads across rows, with items sorted left to right before beginning a new row. This feels awkward to me; I'm used to reading lists that are sorted top-to-bottom before beginning a new column. Is there any way to change the output so that it reads down columns, instead?
Upvotes: 2
Views: 291
Reputation: 15648
Scala REPL use jline in order to have proper completion.
Looking into the code of jline, you can see that CandidateListCompletionHandler.printCandidates(...)
call reader.printColumns(candidates)
which is copy/paste here.
As you can see, there is no way to sort completion candidates in colomn mode instead of line mode, maybe the best you can do is to patch jline and replace it in your scala/lib/ directory.
public void printColumns(final Collection stuff) throws IOException {
if ((stuff == null) || (stuff.size() == 0)) {
return;
}
int width = getTermwidth();
int maxwidth = 0;
for (Iterator i = stuff.iterator(); i.hasNext(); maxwidth = Math.max(
maxwidth, i.next().toString().length())) {
;
}
StringBuffer line = new StringBuffer();
int showLines;
if (usePagination)
showLines = getTermheight() - 1; // page limit
else
showLines = Integer.MAX_VALUE;
for (Iterator i = stuff.iterator(); i.hasNext();) {
String cur = (String) i.next();
if ((line.length() + maxwidth) > width) {
printString(line.toString().trim());
printNewline();
line.setLength(0);
if (--showLines == 0) { // Overflow
printString(loc.getString("display-more"));
flushConsole();
int c = readVirtualKey();
if (c == '\r' || c == '\n')
showLines = 1; // one step forward
else if (c != 'q')
showLines = getTermheight() - 1; // page forward
back(loc.getString("display-more").length());
if (c == 'q')
break; // cancel
}
}
pad(cur, maxwidth + 3, line);
}
if (line.length() > 0) {
printString(line.toString().trim());
printNewline();
line.setLength(0);
}
}
Upvotes: 2