让 Scala 的 REPL 选项卡完成向下读取列而不是跨行?

发布于 2024-10-17 04:50:37 字数 101 浏览 5 评论 0原文

Scala REPL 中制表符补全的输出跨行读取,项目在开始新行之前从左到右排序。这对我来说感觉很尴尬;我习惯于在开始新专栏之前阅读从上到下排序的列表。有什么方法可以更改输出,使其读取列?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2024-10-24 04:50:37

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);
    }
}

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文