-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async counter example text input broken #38
Comments
I'd definitely encourage you to share more feedback on any aspect of this template (including the docs). The async template is pretty much a single person effort (props to @kdheepak). But as a result it hasn't the same level of feedback as the more core parts of the library, and it needs it to help make it meet your use cases (or in case @kdheepak wins the lottery tomorrow). |
Thanks for the feedback! Sorry for the frustrating experience. I did think of this issue when I was first added a text input field in the template but I think while adding features to the template along the way (e.g. reading key configuration from a file etc) I didn't test everything in the counter app and didn't account for this. I've fixed this particular issue in the linked PR. The way I fixed it is the "intended way" of dealing with this kind of issue. Specifically, every component can return a For this issue, I introduce a I say "intended way" in quotes because there's so many ways to architect a ratatui application and this is just one way to do it. For example, I think another way to solve this be to introduce a layer in the key configuration that uses component name + mode: {
"keybindings": {
"Home": {
"Normal": {
"<q>": "Quit", // Quit the application
"<j>": "ScheduleIncrement",
"<k>": "ScheduleDecrement",
"<?>": "ToggleShowHelp",
"</>": "EnterInsert",
"<Ctrl-d>": "Quit", // Another way to quit
"<Ctrl-c>": "Quit", // Yet another way to quit
"<Ctrl-z>": "Suspend" // Suspend the application
},
}
}
} Generally, I want to say that this template is very opinionated + also not as well documented as I'd like. It's also a trivial example with complicated features to showcase the features. I feel more strongly about moving this template to a different name, like We are discussing a rewrite to the tutorial documentation and I think when that happens I'll revisit this template as well and rework whatever example we use in the tutorial to use this "component"-based template. |
I've reopened the issue to get feedback from you and see if you have any more ideas on how you might have gone about making a PR to sort this out. |
I've made another PR where This doesn't use the "intended way" of fixing this problem. Rather, this is what I should have done to begin with, i.e. This PR also lets you add key configurations per mode, for example:
I think there may be a bug somewhere related to key-events though, since I'm not able to get |
Thank you very much for the detailed answer and fix! |
The counter was broken again when #45 was merged in. The fixes discussed in this issue were deleted. |
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 theHome
Component is never called. This is because thehandle_events()
function is overwritten with the handling of the mouse event. Changing the function name tohandle_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 onq
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
The text was updated successfully, but these errors were encountered: