Ale*_*rge 2 java shell command-line jline
我正在使用jline,我有一个整洁ConsoleReader,一切都很好.但是,如果您在提示符中键入内容并且stdout上有输出(来自另一个线程),则输出将拆分您键入的单词/命令.
如何将jline提示保留在终端的底部?
我正在使用jline1,但jline如果它足够稳定,我愿意使用2.
终于想通了......这就是你做的.首先,定义这些功能:
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
}
}
Run Code Online (Sandbox Code Playgroud)
然后,当您想要输出新数据时,首先调用stashLine()以保存当前控制台输入,然后输出任何新的输出行,然后调用unstashLine()以恢复它.