Tuesday, 12 September 2017

bash - Sending correct escape sequences in terminal



To scroll a few lines up in WeeChat one is supposed to press + . When I press these keys, the program thinks I'm pressing + , instead.



In my terminal, typing is received as meta2-5~. This works fine and represents the escape sequence: [5~. (So, it is my understanding that meta2 is [.)


Typing + is received as meta-, instead of meta-meta2-5~. (Typing + , is also received as meta-,, so it is my understanding that corresponds to meta here.) The reasons is received as meta- is because I've checked "Send Alt as Meta" in Terminal.app settings.


Now (hold on for such strange behaviour), if I press , this guy is received as meta! So, to scroll up a few lines I can press + a few times. (I cannot simply keep pressed and hit a few s. I need to repress as well.)




  • is escaped correctly as meta2-5~.

  • + is escaped incorrectly as meta-, (should be meta-meta2-5~).

  • + , is escaped correctly as meta-,.

  • + is escaped incorrectly (?) as meta-meta2-5~.



I'm sitting on a Mac, using Terminal.app, ssh-ing into a CentOS 7.6.1810, connected to a tmux session, running WeeChat in one window.



Here the whole list of ANSI escape sequences can be found. Strangely, seems to be encoded as 0;73, and not the expected [5~. So, I'm not sure what's going on in this website as well.




You seem to be misunderstanding the required keystrokes and which keys generate characters.



Point taken.





So did you hold down the key, type the key, and then release the key?
If the program responds as if you are "pressing + ,", then you apparently did something else.



I indeed did "hold down the key, type the key, and then release the key".


I'm wondering whether MacOS caught that key combination and did send something else to my terminal, like that + ,.





The key is not a modifier key, and should not be kept "pressed".



Got it.





The two-byte code for the key is 0x0 0x49 or decimal 0 73.



Do you understand what [5~ may refer to, then?
This answer points out that sometimes it's necessary to enforce Mac's Terminal.app to send correct escape sequences, and precisely as \033[5~, which it's what is already happening on my machine. I'm wondering now what sequence should be sent when + is pressed instead.


These are "bindings" between keystrokes and... ?


Thanks for clearing my confusion.



Answer




WeeChat expects a \033[5;3~ escape sequence (see source code) to scroll a few lines up. You can configure your terminal application to send such escape sequence (if it's not already doing so) when pressing + .


For Apple's Terminal.app go to Terminal > Preferences... > Profiles > Keyboard to add such missing key-action pair. (Use \033[6;3~ for + .)



I ought to thank sawdust for his comprehensive answer and having me directed towards the solution of this issue. Debugging help has also been provided by the folk on #weechat@chat.freenode.net.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...