LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 03-07-2015, 12:42 PM   #1
odin_ago
Member
 
Registered: Mar 2011
Posts: 61

Rep: Reputation: 1
wrong character sequences for ctrl+arrow in putty (windows client)


Hello.

I guess this problem should be quite well-known, and I was quite surprised that I didn't find a clear description. Anyway, it does not seem to be here, so here is my question.

Putty (an ssh client for windows) identifies its terminal emulator as "xterm" by default, but the character sequences I get for some keys are not the same as I get in a descent xterm (I've tried twice, on two different machines with two different linux distros). Namely, in putty, shift+up, ctrl+up, and alt+up produce ^[OA, ^[OA, and ^[^[[A, respectively, while in the real xterm they produce ^[[1;2A, ^[[1;5A, and ^[[1;3A, resp. All the same for other arrow keys. Note that the codes for shift+up and ctrl+up produce the same character sequences, so a program running on the server-side will be completely unable to distinguish between them, whatever configuration I set up on the server-side.

Maybe, I don't know something important (e. g. there is a general and official linux standard called "xterm" and a program also called "xterm", and the program violates the standard, while putty does not), but for me this looks like a bug in putty (if you call yourself "xterm", you should behave like xterm), and I have the intent to report it to putty developers. But first I would like to ask: maybe I really miss something important? It is very strange for me that such a situation (which should have occurred a lot of times to a lot of users) has not been yet reported (I searched through putty bug reports).

PS The same situation is for Fn keys, but for the Fn keys I know how to reconfigure putty so that it sends the same sequences as xterm (even though this is not the deault putty configuration).

PPS I know that there is some terminal setting, which is controlled from inside the terminal (by "printing" a special sequence of characters) and which is called "application mode". I believe that it is related with ncurses, but AFAIK it can also be toggled by hand, by the commands
Code:
echo -e '\033[?1h'
to turn it on and
Code:
echo -e '\033[?1l'
to turn it off. Doing this changes the behavior of shift+arrow, etc keys in putty (in the real xterm they stay the same!), but they don't become like in xterm anyway: shift+up, ctrl+up, and alt+up then produce ^[[A, ^[[A, and ^[^[OA, resp.
 
Old 03-08-2015, 01:00 PM   #2
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Rep: Reputation: 22
I'm looking at the source code for putty right now. It seems the escape sequences for the arrow keys are hard coded into it. It's in terminal.c, around line 6015, int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl). Control is the only modifier it seems to care about.

Any way you cut it, the codes for arrows/home/end/ins/del/pgup/pgdn/Fn are hard to predict. They are supposed to be the ones in terminfo, but there is no guarantee that the terminal emulator you use actually abides by this. For example, rxvt actually makes up it's own sequences for any of these keys with control/shift modifiers, and doesn't even look at terminfo. It's not surprising that putty does this also.

I have so many hacks to determine the state of the modifiers from a terminal window I can't even tell you. There's a different set for every different terminal: linux/xterm/rxvt/etc. It's a gong show.
 
Old 03-08-2015, 04:57 PM   #3
odin_ago
Member
 
Registered: Mar 2011
Posts: 61

Original Poster
Rep: Reputation: 1
1. I looked through terminfo manual a little, but I didn't find how it can prescribe the sequence for ctrl+arrow. Anyway, this is not the problem. rxvt does produce different sequences for ctrl+arrow than xterm does, but rxvt doesn't call itself xterm in the TERM variable. So, the programs working inside rxvt don't try to interpret the codes given by rxvt as if they were given by xterm. Konsole and gnome-terminal do call themselves xterm, but they produce the same codes. Putty also tells internal programs that it is xterm, but it produces wrong codes. And yes, despite I didn't find how ctrl+arrow keys are represented in terminfo, but, for example, I did find how fn keys are represented. In the cases of rxvt, xterm, konsole, and gnome-terminal, the sequences actually produced by the terminal coincide with what terminfo for the vaule of TERM variable (rxvt or xterm) says they should be. In case of putty, they don't coincide.

2. If I am going to report a bug, not to write an ncurses program which will work with the current (apparently buggy) behavior of putty (an will not work in xterm, konsole and gnome-terminal then, I can't distinguish them from inside the terminal). An for a bug report, it should not be a problem that the wrong sequences are now hardcoded. And my question in this thread was not "how to fix it" (while this information is also helpful, thank you), but rather "why did this behavior appeared at all"? Why did putty developers decide that putty will set TERM=xterm and deliberately hardcoded the sequences for ctrl+arrows, which were different than what actual xterm produces? This does not look like a usual mistake, so I conclude that I don't understand something and the things are not as wrong as they look for me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Putty, SSH, Arrow Keys Produce Character String Instead Of Working As Expected newOperator Debian 4 12-21-2011 10:45 AM
[SOLVED] ANSI escape sequences not working in PuTTY (Mandriva 2010) Xotli Mandriva 2 07-17-2010 08:41 PM
screen / screenrc: how to use the right / ctrl arrow to go left and right in windows? frenchn00b Linux - General 6 11-10-2009 01:11 PM
Problem in getting telnet client prompt by pressing Escape character( ctrl -] ) Prassanta SUSE / openSUSE 0 01-23-2007 12:33 AM
echo out CTRL- sequences how to? jamesps Linux - General 0 07-22-2005 04:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 09:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration