mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #925] [question/bug] Trying to understand key events better #675
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#675
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dkyanakiev on GitHub (Nov 30, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/925
Hi,
Hopefully this is a good format to ask a question..
I've been toying around with the library after some inspiration from a few similar TUIs and wanted to try and build my own.
For the most part it's great and I manage to figure out all the issues I have, except one.
The Enter key.. no matter what I do to configure my inputs .. the moment I hit enter - my app goes back to the main table that is shown when starting the app.
I've tried modifying the keyEnter to return nil, to just print out log messages..
It would do what it's supposed to do + still return me to my Home Screen . Example: https://github.com/dkyanakiev/vaul7y/blob/feature/improvments/view/policy.go#L49
On tables that don't even have the enter key configured in the events the result is the same.
I've tried looking for similar issues but I can't seem to find anything even close to my issue.
Thanks in advance
@dkyanakiev commented on GitHub (Nov 30, 2023):
I actually found the issue I believe
Adding a code snippet
I tried to modify the keyEnter to see what's happening exactly and noticed that the IDE is complaining, and then I saw it
Does this mean there is a bug with what id each key is mapped to?
@moson-mo commented on GitHub (Dec 2, 2023):
Not really a bug. Some key combos are overlapping.
(e.g. try CTRL+m in the terminal -> Same as if you'd press ENTER😉)
See
github.com/gdamore/tcell@8a50441ee1/key.go (L384)https://unix.stackexchange.com/questions/533759/why-are-ctrl-m-and-return-keys-the-same-r-char
@FJuedesOrcl commented on GitHub (Dec 7, 2023):
If you want to "reserve" a key for your own purpose, you must assign "nil" to the event after you have processed your code, like for example
This way your KeyHandler acts like a filter and disables the default functionality, like for example CTRL-C exits the program. If you want to use the Key-Combination CTRL-C for something else like Copy you need to filter this key-event from the event loop.
It is possible to stack Key-Handlers:
For example you have an InputField in a Form in an Application.
When the InputField has the focus, for every keystroke this happens:
Sometimes you can shoot yourself in the foot due to this. I had assigned a functionality to the Plus and the Minus keys in the custom event-handler for my Application and discovered that i wasn't able to enter the plus or minus sign into an InputField anymore.