java - 使用 readChar() 后 JLine 不显示字符
问题描述
我尝试在 java 中制作简单的键盘测试器,所以我使用 Jline 读取字符而不按 ENTER,但是当我尝试从控制台读取行时,它没有显示字符。我尝试使用不同版本的 JLine(目前我使用 2.14.6),重置终端,打开 Echo 等。但仍然没有。
ConsoleReader console = new ConsoleReader();
//ConsoleReader cr = new ConsoleReader();
console.setKeyMap("UTF-8");
System.out.println("Press ESC for end testing");
int key = 0;
while(key != 27)
{
key = console.readCharacter(true);
System.out.println(key + " : " + Character.getName(key));
}
//console.getTerminal().setEchoEnabled(true);
console.getTerminal().init();
console.getTerminal().reset();
console.close();
console.delete();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter text: ");
System.out.println(br.readLine());
br.close();
编辑:我添加了这些行并且它有效
console.getTerminal().setEchoEnabled(true);
console.getTerminal().init();
console.getTerminal().reset();
console.getTerminal().restore();
解决方案
看起来你使用的是 JLine 2 而不是 JLine 3。Jline 2 多年来一直没有维护,所以你真的应该升级到 3.x
推荐阅读
- electron - Electron 无法在 mac 中自动更新版本 big sur
- angular - 如何在 Angular Formly 表单上显示超链接
- spring - Spring Security Microsoft Oauth2 登录错误
- jupyter-notebook - Jupiter notebook 在绘制我的图像之前正在打印文字(顺序不正确)
- bash - 开机后自动运行脚本 - 树莓派
- python - Pyautogui click() 和 moveTo() 不起作用 mac os bigsur
- flutter - 在标题和文本字段之间填充不呈现?
- python - gerrit 的 Rest api 给出响应,但用于获取修订的 Python-gerrit-api 包给出状态 404
- javascript - 有没有办法使用基于对象的嵌入来制作“嵌入页面”?(不和谐.js)
- perl - RRDTools RRDs::xport 模块的工作示例