mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.26k stars 242 forks source link

custom input #557

Closed JoJpeg closed 2 years ago

JoJpeg commented 2 years ago

Hey guys, sorry in advance I tried everything to find information on this. If i call terminal.readInput(), I will take the input that is supposed to go to the terminal right? How can i reach it back to the Terminal after I handled it? For now the whole program freezes because i steal that poor thing every KeyStroke it gets.

I want do implement some custom behaviour for my program to control it via numpad only on a raspberry. I got it working with the SwingTerminalFrame by calling addInput() but the UnixTerminal does not implement that method. I hope I have not missed anything very obvious. Thanks for your time!

avl42 commented 2 years ago

"it depends"

it depends on what kind your application is. If it is based on Terminal, then reading input of Terminal is fine.

otherwise, it might be based on Screen if your app uses the double-buffered Screen-layer of lanterna. in that case, you should among the methods in Screen to find the one to read Input from - the difference here is, that the screen might handle some keystrokes directly, and only pass on the rest. That way it can e.g. still do scrolling for too small terminal-windows.

If, however you use the TextGui components, then it works completely differently: You no longer actively read input, but instead have the Gui-classes handle input, or arrange to have custom callbacks called, if input is received from user.

If this wasn't what you meant by "take the input that is supposed to go to the terminal", then please clarify - or hope&wait for other replies... ;-)

On Mon, Mar 21, 2022 at 10:27 PM Jo @.***> wrote:

Hey guys, sorry in advance I tried everything to find information on this. If i call terminal.readInput(), I will take the input that is supposed to go to the terminal right? How can i reach it back to the Terminal after I handled it? For now the whole program freezes because i steal that poor thing every KeyStroke it gets.

I want do implement some custom behaviour for my program that to control it via a numpad only on a raspberry. I got it working with the SwingTerminalFrame by calling addInput() but the UnixTerminal does not implement that method. I hope I have not missed anything very obvious. Thanks for your time!

— Reply to this email directly, view it on GitHub https://github.com/mabe02/lanterna/issues/557, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIDBMS7BSBKL33RSY2NDCTVBDSTPANCNFSM5RI7AJDQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

JoJpeg commented 2 years ago

Ok i just found the solution: You gotta send the KeyStroke to the Window not to the Terminal. In my case it was the MultiWindowTextGUI.handleInput() method that did the trick.
Thank you @avl42 for the heads up that i have to interact with the GUI classes 🙏

And i already foolishly injected my own InputDecoder to the StreamBasedTerminal via Java Reflections 😭