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

Alt-h/j/k/l not working when TERM not xterm* or vt220 #348

Open
ybc37 opened this issue Nov 27, 2020 · 3 comments
Open

Alt-h/j/k/l not working when TERM not xterm* or vt220 #348

ybc37 opened this issue Nov 27, 2020 · 3 comments
Labels
bug 🐛 Something isn't working

Comments

@ybc37
Copy link

ybc37 commented Nov 27, 2020

Hey there,

first, thanks for the htop-dev initiative. Cool to see this project going :)

After upgrading to htop 3.0.0 I noticed that some of the added vim bindings do not work for me. I think at least all Alt- bindings. I finally got some time to look at it to be able to provide at least some information.

In my case TERM is set to tmux-256color or alacritty (if not in tmux). I realized it works when using xterm* and was able to pin it down to how the keys are defined in CRT.c

htop/CRT.c

Lines 687 to 706 in f704bae

if (String_startsWith(CRT_termType, "xterm") || String_eq(CRT_termType, "vt220")) {
define_key("\033[H", KEY_HOME);
define_key("\033[F", KEY_END);
define_key("\033[7~", KEY_HOME);
define_key("\033[8~", KEY_END);
define_key("\033OP", KEY_F(1));
define_key("\033OQ", KEY_F(2));
define_key("\033OR", KEY_F(3));
define_key("\033OS", KEY_F(4));
define_key("\033[11~", KEY_F(1));
define_key("\033[12~", KEY_F(2));
define_key("\033[13~", KEY_F(3));
define_key("\033[14~", KEY_F(4));
define_key("\033[17;2~", KEY_F(18));
char sequence[3] = "\033a";
for (char c = 'a'; c <= 'z'; c++) {
sequence[1] = c;
define_key(sequence, KEY_ALT('A' + (c - 'a')));
}
}

When skipping the condition it works for other TERM values as well (btw even on VTs; TERM=linux).

I'm not an expert, so not sure what's a valid approach to fix it. Adding every possible TERM that supports these keys most probably isn't ;) Is it somehow possible to check the "capabilities" of a terminal emulator instead of TERM? Or is it safe nowadays to drop this condition without breaking htop for other systems (the condition dates back even before the initial git import 15 years ago (d6231ba). Touched 3 years ago (45f3769) to support for everything that starts with xterm)?

@BenBE BenBE added the bug 🐛 Something isn't working label Nov 27, 2020
@BenBE
Copy link
Member

BenBE commented Nov 27, 2020

To make this fully portable the code would have to check the termcap library for the exact mappings.
Cf. https://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html#SEC37
Unfortunately these definitions are regularly broken and thus unreliable …

@fasterit
Copy link
Member

Just FTR, vim mode has been removed again in c9ecd0f. The way it was implemented caused too many issues elsewhere.

@ybc37
Copy link
Author

ybc37 commented Nov 27, 2020

I think there's a misunderstanding: AFAIU the bindings I'm talking about are just alternative bindings to the default ones. I didn't use a dedicated "vim mode". I'm using htop 3.0.2 and also tested with current master.

Sorry, I wasn't aware of the difference of the vim key bindings and the vim mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants