3

私は使用jlineしており、きちんとConsoleReaderしていて、すべてがうまく機能しています。ただし、プロンプトに何かを入力していて、(別のスレッドからの) stdout に出力がある場合、出力は入力している単語/コマンドを分割します。

jline端末の下部にプロンプ​​トを表示するにはどうすればよいですか?

私は1 を使用していますが、十分に安定していれば 2jlineを使用してもかまいません。jline

4

1 に答える 1

6

最後にこれを理解しました...これがあなたがすることです。まず、次の関数を定義します。

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()を復元するために呼び出します。

于 2014-12-09T22:16:15.453 に答える