jline keep prompt at the bottom

随声附和 提交于 2019-12-03 08:59:41

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!