Numpad doesn't work in curses #194

Closed
opened 12 months ago by ofiala · 6 comments
ofiala commented 12 months ago

Anything I try to type in curses-based programs using the numpad is interpretted as if the numlock was off, regardless of its actual state.

Anything I try to type in curses-based programs using the numpad is interpretted as if the numlock was off, regardless of its actual state.
Owner

I haven't had time to look into this yet, but could you try setting TERM=xterm-256color? For some things, ncurses looks at the name of the terminfo, rather than the terminfo itself.

I haven't had time to look into this yet, but could you try setting `TERM=xterm-256color`? For some things, ncurses looks at the **name** of the terminfo, rather than the terminfo itself.
Poster

Doesn't help.

Doesn't help.
Owner

Could you give a couple of examples of misbehaving applications?

Could you give a couple of examples of misbehaving applications?
Poster

nano, irssi

nano, irssi
Owner

It's not that they don't work, it's just that they don't send the escapes ncurses/nano/irssi/you are expecting.

The keypad has effectively three modes: num lock off, num lock on in numerical mode and num lock on in application mode.

Num Lock changes which keys foot "sees". For example, the '9' key is a KP_PageUp when num lock is off, and a KP_9 when it's on.

Then, foot uses internal keymap tables to translate those keys to an escape sequence to be sent to the client application.

There are two different tables, or modes of translation: numerical and application. When foot starts, the keypad is in numerical mode. Applications can change this at any time.

In numerical mode, KP_9 is translated to 9. But in application mode, KP_9 is translated to \EOy.

ncurses, or e.g. nano switches the keypad over to application mode when it starts. This is why it "doesn't work"; nano is receiving \EOy which it doesn't know what to do with.

So why does it work in e.g. XTerm? XTerm has an option, numLock, that when set to true overrides the keypad mode and effectively enforces numerical mode. The default value of numLock is true...

#196 implements numLock (except it isn't exposed as an option, but can be controlled with the CSI ? 1035 h and CSI ? 1035 l escape sequences), and changes the default to match XTerm.

It's not that they don't work, it's just that they don't send the escapes ncurses/nano/irssi/you are expecting. The keypad has effectively three modes: num lock off, num lock on in numerical mode and num lock on in application mode. Num Lock changes which keys foot "sees". For example, the '9' key is a `KP_PageUp` when num lock is off, and a `KP_9` when it's on. Then, foot uses internal keymap tables to translate those keys to an escape sequence to be sent to the client application. There are two different tables, or modes of translation: _numerical_ and _application_. When foot starts, the keypad is in _numerical_ mode. Applications can change this at any time. In _numerical_ mode, `KP_9` is translated to `9`. But in _application_ mode, `KP_9` is translated to `\EOy`. ncurses, or e.g. nano switches the keypad over to _application_ mode when it starts. This is why it "doesn't work"; nano is receiving `\EOy` which it doesn't know what to do with. So why does it work in e.g. XTerm? XTerm has an option, `numLock`, that when set to true **overrides** the keypad mode and effectively enforces _numerical_ mode. The default value of `numLock` is `true`... https://codeberg.org/dnkl/foot/pulls/196 implements `numLock` (except it isn't exposed as an option, but can be controlled with the `CSI ? 1035 h` and `CSI ? 1035 l` escape sequences), and changes the default to match XTerm.
dnkl added the
enhancement
label 12 months ago
dnkl closed this issue 12 months ago
Poster

That is interesting, thank you for the explanation and fix (although 'workaround' would probably be more appropriate). I think this was caused by ncurses rather than the individual applications as e. g. irssi really has no use for numpad in application mode.

That is interesting, thank you for the explanation and fix (although 'workaround' would probably be more appropriate). I think this was caused by ncurses rather than the individual applications as e. g. irssi really has no use for numpad in application mode.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.