Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So, when I cat /dev/input/mouse0 in a TTY, move the mouse around a bit, and then ctrl-z to stop cat, my terminal characters are all messed up. Almost every single character gets swapped out for another character in the ASCII character set. This same situation occurs when I execute this in Python 3.2:

print('\033[1;12mTest.\033[1;m')

The the same symptom does not appear on a shell in the GUI, only on the virtual terminals. The problem does not go away if I log out. I suspect that a certain escape code (which may be contained within the Python code) is remapping the ASCII byte codes to the character representations, but that is just a guess. What is happening and how do I undo it?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

I finally found the command that I was looking for on Command Line Fu. The command is reset. I tried it, and it worked perfectly, without logging out or restarting the system.

share|improve this answer
add comment

When outputting binary files to the terminal, like your cat /dev/input/mouse0, you can send it ANY character. This can confuse the virtual terminal.

The character string ESC [ introduces a "VT100 Control sequence" (compatibility with an old glass keypunch). Other characters like ^Q, ^S, ^N, ^O do magic things based on compatibility with Model 35 Teletypes with paper tape reader/punch.

When I'm trying to de-confuse a terminal, I do:

Is output frozen? Type ^Q (ctrl-Q) (the XON character, to start the paper tape reader).

Type the command stty sane. If there are no characters echoed as you type, stty echo will restore the echo.

Read man stty, and you'll see how you can save a set of terminal settings, and restore them later!

BTW, stopping a program uses crtl-C to stop a program. Ctrl-Z just interrupts the program, in preparation for putting it in the background. Some programs catch ^C and do some necessary cleanup, file saving, etc. on the way out. If you just ^Z and run something else, this cleanup doesn't get done.

share|improve this answer
    
I have heard about using stty sane before, and have tried it. Unfortunately, the results have been the same as always: it did not work, and a restart was required to allow me to use those TTYs again. –  InkBlend Apr 14 '12 at 3:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.