jline保持提示在底部 [英] jline keep prompt at the bottom

查看:372
本文介绍了jline保持提示在底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 jline ,我有一个整洁 ConsoleReader ,一切都很好。但是,如果您在提示符中输入内容,并且在stdout上有输出(从另一个线程),则输出将分割您正在键入的单词/命令。

I am using jline and I have a neat ConsoleReader and everything works great. However, if you are typing something into the the prompt and there is output on stdout (from another thread), the output splits the word/command that you are typing.

如何保持终端底部的 jline 提示?

How can I keep the jline prompt at the bottom of the terminal?

我使用 jline 1,但如果它足够稳定,我可以使用 jline 2。

I am using jline 1, but I am open to using jline 2 if it is stable enough.

推荐答案

最后想出了这一点...这里是你做的。首先,定义这些函数:

Finally figured this out... here's what you do. First, define these functions:

private ConsoleReader console = ...;
private CursorBuffer stashed;

private void stashLine() {
    this.stashed = this.console.getCursorBuffer().copy();
    try {
        this.console.getOutput().write("\u001b[1G\u001b[K");
        this.console.flush();
    } catch (IOException e) {
        // ignore
    }
}

private void unstashLine() {
    try {
        this.console.resetPromptLine(this.console.getPrompt(),
          this.stashed.toString(), this.stashed.cursor);
    } catch (IOException e) {
        // ignore
    }
}

然后,当你想输出新数据时,首先调用 stashLine()来保存当前的控制台输入,然后输出任何新的输出行,调用 unstashLine()以恢复它。

Then when you want to output new data, first invoke stashLine() to save the current console input, then output whatever new lines of output, then invoke unstashLine() to restore it.

这篇关于jline保持提示在底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆