Skip to content
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

invalid character input after ctrl+g input #74

Open
CyanMARgh opened this issue Nov 10, 2023 · 2 comments
Open

invalid character input after ctrl+g input #74

CyanMARgh opened this issue Nov 10, 2023 · 2 comments

Comments

@CyanMARgh
Copy link

if you enter ctrl+g and press by mistake, for example, F1, then ĉ will be entered into the terminal. The bug was discovered when i replaced default navigation keys with wasd in the config. The characters A/B/C/D were entered into the console when i pressed the arrows by mistake. I would like that when entering an invalid command, nothing would be printed.

@Kieran-Weaver
Copy link

Normal invalid commands do display nothing. Your bug won't be seen during normal usage because it doesn't happen with any of the normal keys, only special keys like the arrow keys and the F keys.

The reason this is happening is that the terminal representation for the arrow keys is longer than just one character. You can figure this out by doing ctrl-V and then pressing one of them in the terminal:

Left:  ^[ [ D
Right: ^[ [ C
Up: ^[ [ A
Down: ^[ [ B

where
^[ is escape.

To mtm, ctrl-G, left arrow is an invalid command. it's ctrl-G, [, then a D.

@dpeschel
Copy link

dpeschel commented Nov 8, 2024

This annoyed me as well. Any keys you type that don't have DO() lines in mtm.c just fall through to the code that passes the input to the terminal. This explains characters such as ĉ. It might explain the escape sequences as well; I don't know though.

I propose a three-part fix. I already wrote it in my fork of the repo, and tested it a little bit. But I'd like other people's opinions.

  1. When you have not typed the command character, and you type any unhandled special key, such as F20 or clear all tabs or help, mtm ignores it. Yes, these are real keys you could type, on various non-PC keyboards that ncurses knows about. This change doesn't affect normal ASCII or UTF-8 input. And if you want to handle a new special key, you can add a new line of code.

    Note, these are keys that ncurses knows about but mtm does not. I haven't tried generating escape sequences that ncurses doesn't know about.

  2. When you have typed the command character, and you type any unhandled key (special or not), mtm cancels the command.

    In my opinion, after you have typed the command character, the next key should never turn into input, except for typing the command character twice in a row.

  3. Then the BAILOUT key becomes unnecessary because all unknown keys bail out. (So the code and the configuration files should not define it.) And the manual should say explicitly that all unknown keys bail out.

dpeschel added a commit to dpeschel/mtm that referenced this issue Nov 10, 2024
Proposed fix:

1. When you have not typed the command character, and you type any
   unhandled special key, such as F20 or clear all tabs or help,
   mtm ignores it.

2. When you have typed the command character, and you type any
   unhandled key (special or not), mtm cancels the command.

3. Then the BAILOUT key becomes unnecessary because all unknown
   keys bail out. (So the code and the configuration files should not
   define it.) And the manual should say explicitly that all unknown
   keys bail out.

Cleanup:

Added blank lines, removed extra semicolons, changed comma operator
to two separate statements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants