【问题标题】:JLine 3 - Keep the prompt always at the bottomJLine 3 - 始终将提示保持在底部
【发布时间】:2016-07-15 14:55:03
【问题描述】:

我希望每次都在页面底部显示提示。

我有一个 GIF:The prompt not displaying properly

代码是读取行的代码:

@Override
public void run()
{
    while (((ElytraServer) ElytraAPI.getServer()).isRunning())
    {
        String cmd;
        ((ElytraServer) ElytraAPI.getServer()).getReader().getTerminal().writer().flush();
        cmd = ((ElytraServer) ElytraAPI.getServer()).getReader().readLine("> ");
        if (!cmd.isEmpty())
        {
            String[] aCMD = cmd.split(" ");
            String[] arguments = Arrays.copyOfRange(aCMD, 1, aCMD.length);
            ElytraAPI.getCommandRegistry().dispatch(ElytraAPI.getConsole(), aCMD[0], arguments);
        }
    }
}

它在一个线程中。

还有另一个线程: 使用 JLine 2,代码将提示保持在底部(但它被错误了!)

public void run()
{
    while (((ElytraServer) ElytraAPI.getServer()).isRunning())
    {
        try
        {
            if (useJline)
            {
                /*
                JLine 2 / Old:
                reader.print(Ansi.ansi().eraseLine(Erase.ALL).toString() + '\n');
                reader.flush();
                 */
                reader.getBuffer().down();
                reader.getTerminal().flush();
                output.write("".getBytes());
                output.flush();

                /* // For JLine2
                try
                {
                    reader.drawLine();
                }
                catch (Throwable throwable)
                {
                    reader.getCursorBuffer().clear();
                }*/

                reader.getTerminal().flush();
            }
            else
            {
                output.write("".getBytes());
                output.flush();
            }
        }
        catch (IOException ioexception)
        {
            Logger.getLogger(TerminalConsoleWriterThread.class.getName()).log(Level.SEVERE, null, ioexception);
        }
    }
}

完整来源: Full source of the program

【问题讨论】:

    标签: java jline


    【解决方案1】:

    I posted a workaround 使用当前代码(只要用户不使用多行输入,它就可以工作)。

    reader.getTerminal().puts(Capability.carriage_return);
    reader.getTerminal().writer().println("World!");
    reader.callWidget(LineReader.REDRAW_LINE);
    reader.callWidget(LineReader.REDISPLAY);
    reader.getTerminal().writer().flush();
    

    下一个 jline 版本 (3.2) 将包含更好的修复。见:https://github.com/jline/jline3/issues/75

    【讨论】:

      猜你喜欢
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 2019-01-03
      • 2015-11-12
      • 2012-04-19
      相关资源
      最近更新 更多