문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top