What are these symbols? ;3D;4D

delphinoob

New Member

Reaction score: 3
Messages: 14

Sometimes I will be doing some work in a terminal emulator and will fat finger some key by accident, and various symbols will be produced like this
;3D;4D

What are they? are they a relic of the past?
 

ralphbsz

Son of Beastie

Reaction score: 2,097
Messages: 3,062

Typically terminal control escape sequences. Example (here for bash, a similar version works in tcsh): Type Control V, and then a cursor right key. What you will see on the screen is "^[[C". Here's why: When you press the cursor right key, the terminal (emulator) actually emits the control sequence Esc [ C. That's because terminals emit the ASCII code of the key that is pressed (for example "a" = 0x61 when you hit the lowercase a key). But there are no ASCII codes for most of the function keys on the keyboard, only for the "displaying" characters. So those function keys like cursor control, the F-keys and the block of 6 keys above the cursor control keys emit escape sequences, a set of characters that starts with the Escape character. And the shell knows to not echo those to the screen, but take an action based on them.

When you press Control V, you are telling the shell: Take the next character that you see literally, as if I had typed it, and put it into the command line. That removes the Escape from "cursor right", leaving the "[C". And since Escape is echoed by the shell as "^[" (since it is really is Control-opening-square-bracket), you see "^[ [ C".

The same works the other way. When emacs or vi do complicated drawing on the screen, they use lots of complicated escape sequences. For example: Esc [ 31 m means: Print the next text in red. Esc [ H means: start drawing at the beginning (top left corner) of the screen. And so on. If you confuse the terminal emulator (for example by printing another escape character, or putting it into a strange mode), sometimes these escape sequences that are being sent to the terminal become visible.

If you want to figure out what these escape sequences are, search the web for "ANSI vt100 escape sequences" or something like that.
 

fraxamo

Member

Reaction score: 60
Messages: 75

What are they? are they a relic of the past?
@ralphbsz has kindly explained what they are, but to get rid of them you will need to tell us which shell you are running. Then you can put some code into your shell initialisation file to prevent what you're seeing from happening.
 

olli@

Daemon
Developer

Reaction score: 1,218
Messages: 1,108

@ralphbsz has kindly explained what they are, but to get rid of them you will need to tell us which shell you are running. Then you can put some code into your shell initialisation file to prevent what you're seeing from happening.
You cannot get rid of them in general, short of disabling your keyboard altogether. For example, at the shell prompt, try pressing Esc followed by F12, or Ctrl-V followed by F12 (depends on the shell). You will most likely see strange combinations of numbers and other characters appear. This is the way “escape sequences” work.

It might be possible to disable some of them by binding the combined sequences to empty strings, but you cannot do that for every possible combination of fat-fingered keys. First, that would be a huge number of combinations, and second, you would probably disable some desirable sequences.

By the way, when you just enter cat at the shell prompt, you can see the sequences generated by various special keys.
 

fraxamo

Member

Reaction score: 60
Messages: 75

You cannot get rid of them in general, short of disabling your keyboard altogether
Fair point. I was thinking more along the lines of the characters that appear when you hit the delete key (for example) without previously having mapped that keystroke using bindkey.
 

ralphbsz

Son of Beastie

Reaction score: 2,097
Messages: 3,062

Fair point. I was thinking more along the lines of the characters that appear when you hit the delete key (for example) without previously having mapped that keystroke using bindkey.
I think "most" shells and editors come with sensible default key bindings for "most" keys these days, out of the box. So in practice, you should see very few escape sequences, unless special characters (like Control V) or garbled sequences show up. The only problem with that statement is that I said "most": I just tried it on my 12.2 machine with bash, tcsh, and emacs, and they do mostly sensible things, or ignore unknown keys. But that leaves lots of other shells and programs that are probably not as well configured.
 
OP
D

delphinoob

New Member

Reaction score: 3
Messages: 14

@ralphbsz has kindly explained what they are, but to get rid of them you will need to tell us which shell you are running. Then you can put some code into your shell initialisation file to prevent what you're seeing from happening.
everyone, i was simply curious of what they were, i have no desire to remove them, they do not bother me or get in the way
 
OP
D

delphinoob

New Member

Reaction score: 3
Messages: 14

Typically terminal control escape sequences. Example (here for bash, a similar version works in tcsh): Type Control V, and then a cursor right key. What you will see on the screen is "^[[C". Here's why: When you press the cursor right key, the terminal (emulator) actually emits the control sequence Esc [ C. That's because terminals emit the ASCII code of the key that is pressed (for example "a" = 0x61 when you hit the lowercase a key). But there are no ASCII codes for most of the function keys on the keyboard, only for the "displaying" characters. So those function keys like cursor control, the F-keys and the block of 6 keys above the cursor control keys emit escape sequences, a set of characters that starts with the Escape character. And the shell knows to not echo those to the screen, but take an action based on them.

When you press Control V, you are telling the shell: Take the next character that you see literally, as if I had typed it, and put it into the command line. That removes the Escape from "cursor right", leaving the "[C". And since Escape is echoed by the shell as "^[" (since it is really is Control-opening-square-bracket), you see "^[ [ C".

The same works the other way. When emacs or vi do complicated drawing on the screen, they use lots of complicated escape sequences. For example: Esc [ 31 m means: Print the next text in red. Esc [ H means: start drawing at the beginning (top left corner) of the screen. And so on. If you confuse the terminal emulator (for example by printing another escape character, or putting it into a strange mode), sometimes these escape sequences that are being sent to the terminal become visible.

If you want to figure out what these escape sequences are, search the web for "ANSI vt100 escape sequences" or something like that.
thanks, that makes sense
i'm on it
 
Top