我希望每次在页面底部显示提示符。
我有一个GIF:提示显示不正确
代码是读行的代码:
@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);
}
}
}对于完整的源代码:程序的全部来源
发布于 2016-12-21 13:19:23
我发布了一个解决办法与当前代码(只要用户不使用多行输入即可工作)。
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
https://stackoverflow.com/questions/38399230
复制相似问题