Hi,
Thanks for providing such a comprehensive template!
I tried to play around with the async counter example, but the text input doesn't work for me.
After some digging I found the issue and there is a quick semi-fix, but a somewhat more annoying issue remains, which also applies to the template and not just the counter example.
Quick Fix
The handle_key_events()
function of the Home
Component is never called. This is because the handle_events()
function is overwritten with the handling of the mouse event. Changing the function name to handle_mouse_events()
fixes the issue (with some minor other changes to make the compiler happy).
Remaining issue
Typing a lowercase q
in the input field still makes the program quit, even in insert mode. This is because the key presses are passed through the key map and the resulting action is triggered regardless of component state. I think this is a bigger issue, as TUI applications usually quit on q
and often require text input. So I think it's probably best to make the template easily compatible with such applications.
Maybe a possible solution would be to let component cancel actions, or to move the keybinding handling into the component (the keybindings are in the home section of the config, so maybe their logic should also be in the Home component so it can depend on the component state). The handling for the j
,k
,/
,?
keys is already inside the component so they can be handled better. But that raises the question about the case when multiple components need to handle the same key (e.g. two components with text inputs). Maybe full text input should be a first class citizen, that components can trigger, so it's handled outside of components all together?
These ideas are not very thought out and I'm not totally happy with them. I thought I'd first try to get some feedback as you likely have a better overview over how things are and should work.
I'm happy to help with a PR later