When I press an arrow in the terminal the cursor moves correctly, but when I make a simple application in C, C++ or Python it writes ^[[A, ^[[B... I've written a simple program in Python so you can see the code and the results.
Asked
Active
Viewed 929 times
0
-
That is the normal behaviour. Bash and the interactive Python use something called readline that catches the arrow key sequences and does useful stuff. https://docs.python.org/3/library/readline.html – Oskar Skog Mar 19 '20 at 08:56
-
2@OskarSkog Please don't answer questions in comments. Your comment is a perfectly valid answer, so please turn it into one. – TooTea Mar 19 '20 at 09:14
-
Thanks, @OskarSkog, problem solved – gerardet46 Mar 19 '20 at 10:05
-
1We don't do "SOLVED" in questions on this WWW site. Answers go in answers. – JdeBP Mar 19 '20 at 10:45
1 Answers
3
This is the level of terminal input decoding that you get from the line discipline in canonical input mode. It's not very much.
Every application that wants to present an editable command-line input that respects cursor keypad, editing keypad, and function keys has to switch the terminal into raw input mode and decode the ECMA-48 input stream, accounting for terminal types (and various state machine bodges for RXVT, the Linux KVTs, the SCO Console, and Interix). Your program has to do this.
There are various libraries for doing this, from GNU ReadLine through libtermkey/libtickit and editline (a.k.a. libedit) to ZLE in the Z shell and the Korn shell's editing library.
Further reading

JdeBP
- 68,745