You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the terminal keyboard can be in keypad_local/normal/raw/non-transmit mode or keypad_xmit/application/transmit mode (all of these names are used)
by default the terminal assumes that the keypad is in "normal" mode
in "normal" mode stterm does not send any codes for the keypad delete key, sends an ASCII DEL for the standard delete key, and sends ESC [ D for the keypad left and standard left keys
in "application" mode stterm does send the delete key code listed in its termcap under kdch for both the keypad and the standard delete key, and sends ESC O t from the keypad left and ESC O D from the standard left key
This is different to, say, gnome-terminal, which always sends the key code listed under kdch for the standard delete and keypad delete keys regardless of keypad mode. Setting "application mode" produces ESC O D from both left keys and "normal mode" sends ESC [ D for both left keys.
I'm not terribly convinced that stterm actually does sensible things here but I think it would be reasonable to do the same thing that ZSH is configured to do under Debian: send smkx before entering the prompt and rmkx when leaving. Adding the extra bindings that stterm sends is an additional exercise.
It's a major change so I don't think they'd appreciate it. But if you want, go ahead.
In a nutshell, the problem is with smkx or delete?
No. The problem is st seems to be the only terminal that sends weird keycodes when the keypad is not explicitly activated. It's not "delete" since it also affects other keys. It's not "smkx" but the fact that it's necessary.
There you said it didn't work in bash, and then you later managed to do it anyway.
Sorry, I only show you the link for the solution for bash, that doesn't happened in fish.
It's a major change so I don't think they'd appreciate it. But if you want, go ahead.
Yeah, I can do that, I just don't know how to check which keys is abnormal.
No. The problem is st seems to be the only terminal that sends weird keycodes when the keypad is not explicitly activated. It's not "delete" since it also affects other keys. It's not "smkx" but the fact that it's necessary.
So, st is wrong, fish is **right* is al what you want to say? (took from st)
But it sems that zsh is doing everything correct, I haven't found an issue with zsh except speed issues.
The kind of "hack" like described above can be better than what we do currently, though.
Back to reality: the trouble has sometimes been the user has TERM=xterm but we think their xterm can do 256 colors or they won't hurt. If we were to make an idealized xterm-256color entry and then convert it to C and compile it in as fishunknown-256color, what we could at least do is switch to that at runtime internally when things are looking grim, and then let that run the show form there. We can at least, this way, not do the nasty stuff later in the code where we spin plates on one foot trying to pull off a big lie. We can really just get a string from tparm(set_a_foreground, 256fgval)) check for error values returned, and write that to the screen if it worked or not rite it if it did not, and know that we sent the right thing to everyone we can, instead of nesting 5 levels deep with if/else clauses.
It can solve everything as long as we put out releases and update the entries time to time.
(Rarely) we totally give up and set TERM=ansi hoping for the best.
What we don't actually do is compile in a known safe TERM=ansi or TERM=linux. We could!
It can solve everything as long as we put out releases and update the entries time to time.
Except for everything curses/terminfo isn't doing right/can't do/will never do. The structures can't accommodate 24bit colors and for some stupid reason they won't just put a darned boolean there. We could technically mitigate by adding that ourselves to every entry, and then doing a use=actual_entry. Still!
And all the runtime support code to detect Terminal.app/Konsole/etc, where, unlike st, which could be accommodated quite easily, everyone else lies about TERM- it can't just automagically be put in place for them transparently after we #include that header. We still need to do that in C++. We need to detect them correctly, pick the appropriate entries for them (the real them), in a way that won't break things for other people, or piss off users of that terminal when we haven't made some change they want in there.
Hi everyone, i've been investigating about this a few hours but i'm still confused. Whats the status on this?
If i want to get the DEL key working on st, what i have to do? Using tput smkx seems to fix it.
There is a hacky functions above that set smkx and rmkx based on events, but why is rmkx needed for? What if i just add tput smkx to my fish config file? From the last comment, it seems like some people (i.e. tmux) has smkx by default, with no rmkx anymore. I'm wrong here?
So... what is the solution here? Are we waiting for something to be implemented? This should be fixed at runtime?
This has been "fixed" when using fish inside latest tmux by the commit referenced by @krader1961 above - but IMHO setting smkx hardcoded by tmux is again more of a workaround then a real fix/solution.
@felixsanzsmkx and rmkx are (put simply) two different modes a terminal can be in. The first is keyboard-interactive mode, i.e. the user is supposed to type in something and the latter is a mode where users are not supposed to do some inputs, e.g. because a program is still running but not expecting any input. Why pressing DEL in rmkx leads to a different keycode being interpreted crosses the borders of my historical knowledge (someone obviously had some intention when defining this). st is following this strict convention and if the shell (or some other process) is not setting the correct mode then st will interpret key presses depending on the currently set mode.
Solutions are plentiful, mostly workarounds (like setting modes based on events or as tmux does it by just setting smkx hardcoded) but the problem is doing it right, meaning implementing in it a way where it does not break compatibility with terminals that cannot handle these switches correctly.
I, personally, solved this issue by using the event-based approach plus functions that set the required mode where the event-based approach fails (namely neovim). This works great for me. I even extended the event-based approach a little bit to only consider st and interactive mode of fish.
There's a lot of misinformation here. Here's what you need to know:
Terminals have calculator, cursor, and editing keypads. DEC VT keyboards had the cursor keypad before the calculator keypad. IBM PC keyboards had the calculator keypad (in the Model F) before the cursor keypad (in the Model M).
The cursor and calculator keypads can be in either application or normal mode. In normal mode they usually send a DECFNK or some other CSI-introduced control sequence. In application mode they usually send a character shifted by SS3. The idea was that systems that wanted essentially a big bunch of application function keys used application mode, and systems that were happy with DECFNK and ECMA-48-style control sequences that (say) related both up arrow keys to the CUU control sequence, used normal mode.
These keypads are individually switchable between application and normal modes in DEC VT alikes, with the private mode settings DECCKM (Cursor Keypad Mode) and DECNKM (Numeric Keypad Mode), respectively.
termcap and terminfo sometimes conflate actual terminal capabilities into an abstract model that is significantly limited compared to the capabilities of the actual terminals and slightly off-kilter. In this case, keypad_local and keypad_xmit conflate the cursor and calculator keypad settings into one and imply notions of local versus remote keys, which is not in fact what they do at all. Cursor and calculator keypad keys always transmit shift sequences and control sequences. These capabilities merely switch between two sets.
As you can see from the doco, what people are trying to emulate is this:
The normal mode control sequence for Delete on the calculator keypad is either DEL or . according to the NumLock state, or DECFNK 3 if the ALT modifier is in effect; and the application mode shift sequence is SS3 n.
The control sequence for Delete on the editing keypad is always DECFNK 3, because the editing keypad does not have an application/normal mode switch.
The normal mode control sequence for Left Arrow on the calculator keypad is either CUL (i.e. CSI D) or 4 according to the NumLock state, or DECFNK 7 if the ALT modifier is in effect; and the application mode shift sequence is SS3 t.
The normal mode control sequence for Left Arrow on the cursor keypad is CUL (i.e. CSI D), or DECFNK 7 if the ALT modifier is in effect; and the application mode shift sequence is SS3 D.
For what it's worth, terminfo is pretty much the wrong tool for the job for decoding this stuff. It is wholly inadequate. There are far more possibilities than are accountable for with a simple kdch1= setting. DECFNK control sequences also incorporate modifier information as optional parameters (which is, to repeat, in the doco).
What I have done in my softwares is use an ECMA-48 state machine, checking completed CSI control sequences to see whether they are DECFNK and decoding the extended/function key and modifiers from them, decoding CSI A to CSI Z into their various DEC VT normal mode extended keys or SCO console function keys, decoding SS3 shifted characters into DEC VT application mode keys, and handling most of the rest as simple character input.
Other people take similar approaches. NeoVIM uses libtermkey, whose CSI driver is roughly a state machine too. It does not correctly handle SCO console function keys (which is a protocol distinct from the DECFNK protocol, and conflicting with DEC's ECMA-48 CSI sequences, with a different ancestry, that you will find used by some terminal emulators including the FreeBSD kernel's built-in terminal emulator). And it does not account for the mess that is the Linux kernel's built-in terminal emulator which erroneously swaps Home and End with Find and Select. If you want to adopt it, you'll have to remedy those.
Reacted by Mahmoud Al-Qudsi
Reacted by David Adam
Reacted by Mauro Toffanin, Mahmoud Al-Qudsi, Carlos Moro García, Marlon Richert and Doug Richardson
Activity
zanchey commentedon Jun 18, 2015
I'm struggling to understand. Can you describe what the difference between you are seeing and what you expect is?
pickfire commentedon Jun 21, 2015
Without
tput smkxorprintf '\033[?1h\033=' >/dev/ttyin config, when you press <DELETE> in st:zanchey commentedon Jul 1, 2015
Useful reading:
AIUI:
ESC [ Dfor the keypad left and standard left keyskdchfor both the keypad and the standard delete key, and sendsESC O tfrom the keypad left andESC O Dfrom the standard left keyThis is different to, say, gnome-terminal, which always sends the key code listed under
kdchfor the standard delete and keypad delete keys regardless of keypad mode. Setting "application mode" producesESC O Dfrom both left keys and "normal mode" sendsESC [ Dfor both left keys.I'm not terribly convinced that stterm actually does sensible things here but I think it would be reasonable to do the same thing that ZSH is configured to do under Debian: send
smkxbefore entering the prompt andrmkxwhen leaving. Adding the extra bindings that stterm sends is an additional exercise.pickfire commentedon Jul 1, 2015
I don't understand what you mean? Do you mean to set
smkxmanually infish.config?zanchey commentedon Jul 2, 2015
No, to echo the smkx sequence when accepting input and rmkx when leaving that state.
pickfire commentedon Jul 2, 2015
On Wed, Jul 01, 2015 at 11:40:35PM -0700, David Adam wrote:
In fish? Manually?
< Do what you like, like what you do. >
zanchey commentedon Jul 2, 2015
In fish.
pickfire commentedon Jul 2, 2015
Manually?
pickfire commentedon Sep 1, 2015
Do you think I need to patch
stfor the smkx?faho commentedon Sep 1, 2015
Putting this in config.fish should solve the issue:
Should we ship this by default, e.g. in __fish_config_interactive?
That would work too, though I don't think st upstream would take it.
pickfire commentedon Sep 1, 2015
I said that
kdoesn't work, #2309 (comment) talked about this.I thought about that too, but we could still add that to http://st.suckless.org/patches/ first and see if they want to take that.
The patch you give works like a charm. I hope you can add it to
fish.In a nutshell, the problem is with
smkxordelete?faho commentedon Sep 1, 2015
There you said it didn't work in bash, and then you later managed to do it anyway.
It's a major change so I don't think they'd appreciate it. But if you want, go ahead.
No. The problem is st seems to be the only terminal that sends weird keycodes when the keypad is not explicitly activated. It's not "delete" since it also affects other keys. It's not "smkx" but the fact that it's necessary.
pickfire commentedon Sep 1, 2015
Sorry, I only show you the link for the solution for bash, that doesn't happened in fish.
Yeah, I can do that, I just don't know how to check which keys is abnormal.
So, st is wrong, fish is **right* is al what you want to say? (took from st)
But it sems that
zshis doing everything correct, I haven't found an issue withzshexcept speed issues.faho commentedon Sep 1, 2015
st does something apparently nobody else does, but I guess they'd like to keep their way and they might have a reason for it.
It's quite possible zsh already has a hack like what I proposed above.
42 remaining items
floam commentedon Sep 4, 2016
The kind of "hack" like described above can be better than what we do currently, though.
Back to reality: the trouble has sometimes been the user has TERM=xterm but we think their xterm can do 256 colors or they won't hurt. If we were to make an idealized xterm-256color entry and then convert it to C and compile it in as fishunknown-256color, what we could at least do is switch to that at runtime internally when things are looking grim, and then let that run the show form there. We can at least, this way, not do the nasty stuff later in the code where we spin plates on one foot trying to pull off a big lie. We can really just get a string from
tparm(set_a_foreground, 256fgval))check for error values returned, and write that to the screen if it worked or not rite it if it did not, and know that we sent the right thing to everyone we can, instead of nesting 5 levels deep with if/else clauses.It can solve everything as long as we put out releases and update the entries time to time.
What we don't actually do is compile in a known safe TERM=ansi or TERM=linux. We could!
floam commentedon Sep 4, 2016
Except for everything curses/terminfo isn't doing right/can't do/will never do. The structures can't accommodate 24bit colors and for some stupid reason they won't just put a darned boolean there. We could technically mitigate by adding that ourselves to every entry, and then doing a
use=actual_entry. Still!And all the runtime support code to detect Terminal.app/Konsole/etc, where, unlike
st, which could be accommodated quite easily, everyone else lies aboutTERM- it can't just automagically be put in place for them transparently after we#includethat header. We still need to do that in C++. We need to detect them correctly, pick the appropriate entries for them (the real them), in a way that won't break things for other people, or piss off users of that terminal when we haven't made some change they want in there.That all sucks.
krader1961 commentedon Mar 15, 2017
FWIW, the tmux project recently recognized the need to set smkx mode. Whether or not fish should do something similar is still open for debate.
felixsanz commentedon May 27, 2017
Hi everyone, i've been investigating about this a few hours but i'm still confused. Whats the status on this?
If i want to get the DEL key working on
st, what i have to do? Usingtput smkxseems to fix it.There is a hacky functions above that set
smkxandrmkxbased on events, but why isrmkxneeded for? What if i just addtput smkxto my fish config file? From the last comment, it seems like some people (i.e. tmux) hassmkxby default, with normkxanymore. I'm wrong here?So... what is the solution here? Are we waiting for something to be implemented? This should be fixed at runtime?
Thanks
wilriker commentedon Jun 1, 2017
This has been "fixed" when using
fishinside latesttmuxby the commit referenced by @krader1961 above - but IMHO settingsmkxhardcoded bytmuxis again more of a workaround then a real fix/solution.@felixsanz
smkxandrmkxare (put simply) two different modes a terminal can be in. The first is keyboard-interactive mode, i.e. the user is supposed to type in something and the latter is a mode where users are not supposed to do some inputs, e.g. because a program is still running but not expecting any input. Why pressingDELinrmkxleads to a different keycode being interpreted crosses the borders of my historical knowledge (someone obviously had some intention when defining this).stis following this strict convention and if the shell (or some other process) is not setting the correct mode thenstwill interpret key presses depending on the currently set mode.Solutions are plentiful, mostly workarounds (like setting modes based on events or as
tmuxdoes it by just settingsmkxhardcoded) but the problem is doing it right, meaning implementing in it a way where it does not break compatibility with terminals that cannot handle these switches correctly.I, personally, solved this issue by using the event-based approach plus functions that set the required mode where the event-based approach fails (namely
neovim). This works great for me. I even extended the event-based approach a little bit to only considerstand interactive mode offish.jdebp commentedon May 14, 2018
There's a lot of misinformation here. Here's what you need to know:
DECFNKor some other CSI-introduced control sequence. In application mode they usually send a character shifted by SS3. The idea was that systems that wanted essentially a big bunch of application function keys used application mode, and systems that were happy withDECFNKand ECMA-48-style control sequences that (say) related both up arrow keys to the CUU control sequence, used normal mode.DECCKM(Cursor Keypad Mode) andDECNKM(Numeric Keypad Mode), respectively.keypad_localandkeypad_xmitconflate the cursor and calculator keypad settings into one and imply notions of local versus remote keys, which is not in fact what they do at all. Cursor and calculator keypad keys always transmit shift sequences and control sequences. These capabilities merely switch between two sets.All of this stuff is documented. Here is a list of some of the doco to read.
As you can see from the doco, what people are trying to emulate is this:
Deleteon the calculator keypad is either DEL or.according to the NumLock state, or DECFNK 3 if the ALT modifier is in effect; and the application mode shift sequence is SS3n.Deleteon the editing keypad is always DECFNK 3, because the editing keypad does not have an application/normal mode switch.Left Arrowon the calculator keypad is either CUL (i.e. CSID) or4according to the NumLock state, or DECFNK 7 if the ALT modifier is in effect; and the application mode shift sequence is SS3t.Left Arrowon the cursor keypad is CUL (i.e. CSID), or DECFNK 7 if the ALT modifier is in effect; and the application mode shift sequence is SS3D.For what it's worth, terminfo is pretty much the wrong tool for the job for decoding this stuff. It is wholly inadequate. There are far more possibilities than are accountable for with a simple
kdch1=setting. DECFNK control sequences also incorporate modifier information as optional parameters (which is, to repeat, in the doco).What I have done in my softwares is use an ECMA-48 state machine, checking completed CSI control sequences to see whether they are DECFNK and decoding the extended/function key and modifiers from them, decoding CSI
Ato CSIZinto their various DEC VT normal mode extended keys or SCO console function keys, decoding SS3 shifted characters into DEC VT application mode keys, and handling most of the rest as simple character input.Other people take similar approaches. NeoVIM uses libtermkey, whose CSI driver is roughly a state machine too. It does not correctly handle SCO console function keys (which is a protocol distinct from the DECFNK protocol, and conflicting with DEC's ECMA-48 CSI sequences, with a different ancestry, that you will find used by some terminal emulators including the FreeBSD kernel's built-in terminal emulator). And it does not account for the mess that is the Linux kernel's built-in terminal emulator which erroneously swaps
HomeandEndwithFindandSelect. If you want to adopt it, you'll have to remedy those.faho commentedon Apr 2, 2024
The way forward here is #10359 - make the terminal report the actual keys in a better way.
I'll be closing this because keypad mode is pretty gnarly.