2

Scala REPL 中制表符补全的输出跨行读取,项目在开始新行之前从左到右排序。这让我感觉很尴尬;我习惯于在开始新列之前阅读从上到下排序的列表。有没有办法改变输出,以便它读取列,而不是?

4

1 回答 1

2

Scala REPL 使用jline以正确完成。查看 jline 的代码,您可以在此处看到复制/粘贴的CandidateListCompletionHandler.printCandidates(...)调用。reader.printColumns(candidates)

如您所见,没有办法在列模式而不是行模式下对完成候选进行排序,也许您能做的最好的事情就是修补 jline 并将其替换到您的 scala/lib/ 目录中。

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);
    }
}
于 2011-02-11T09:09:28.380 回答