Advanced Java console input
-
21-02-2021 - |
문제
As a self-practice, I'm making a BF interpreter in Java that does I/O through the console. For the most part it's fine, however, as you might be aware, BF takes input one character at a time, including newlines. This means that as far as I know the standard console input libraries won't work, because they take in entire strings, and then ask for a return at the end. I want ,
to take in the next keystroke that fits into a char
without printing it when it is typed. So when BF asks for input, and you type in a
, it takes in the a
but doesn't show it in the console unless the BF program outputs a
itself later.
How can I do this?
해결책
I suggest using JLine http://jline.sourceforge.net
The Terminal
class has a disableEcho()
method to do what you want.
다른 팁
Write your own console output/input using a textArea in a frame and a keyListener
Check out java.io.Console
- you can read a string w/o echo with readPassword()
. It is still line oriented though, so you won't receive anything until user presses Enter. Another possible disadvatage is that there may be no console - depends on the way app is launched.