Wednesday, March 4, 2009

Re: [BLUG] How do you like to get rid of terminal corruption?



On Wed, Mar 4, 2009 at 8:56 PM, Gillis, Chad <rcgillis@indiana.edu> wrote:



Quoting Mark Krenz <mark@slugbug.org>:
 Ok, just kidding. I'm curious though, how do you usually like to get
rid of terminal corruption?  Do you just close the terminal or are you
daring and try to reverse it by cat'ing out /dev/urandom or /dev/sda?
Sometimes I'll try cat'ing /dev/urandom, but something makes me think
that its dangerous to do that. Anyone know?

On Wed, Mar 04, 2009 at 01:06:21PM -0500, Gillis,  Chad wrote:
What does cat /dev/urandom acheive?  Doesn't that just say spew random
garbage?  Is it the homeopathic method? :)


Quoting Steven Black <blacks@indiana.edu>:
The issue is that some garbage sent to the terminal emulator mucked
up some setting and now you can't read any new text. The scroll back
is unimpacted, presuming that wasn't cleared or just swamped. (This is
due to the problem being the character set being set oddly. VT100's
supported a concept of an 'alternate' character set which would contain
characters not normally in the main character set. You could send a
control sequence to change the character set. This allowed for non-Latin
glyphs on some models of those early terminals.)

Thanks for the interesting explanation.  So I have another question now.  The purpose of cat is to print to standard output.  Since the role of /dev/urandom is to produce random numbers, it makes sense that the stuff being printed to standard out would be uninterpretable gibberish.  But how do you go from printing to standard out to sending a command to the terminal to change its settings? If I hadn't already seen my terminal get mucked up in the past, I might have thought that you'd just get gibberish up until /cat/udev was finished, and then after that things would be normal again.  Does the terminal just assume that if it's expected to print gibberish once then it should go forever into gibberish mode?  This is my simple perception of it but I'm sure there's a better explanation.


catting /dev/urandom does work most of the times, but as Steven said not the right way to fix terminal corruption.
here's an exercise:
do a $ cat /dev/urandom and send a SIGINT (Ctrl - C) immediately.
see how often you can corrupt and restore back the terminal.
it works each time for me.
the random sequences very often generate a terminal escape sequence, and that is the reason you are not supposed to cat a binary file.
try with cat -v and it works.

don't forget, unix was written in the days when a baud rate in hundreds was considered fast and the terminal used paper. in the good old days, terminals used to be away from the computer connected with serial cables. these terminals could be configured or controlled through a series of byte sequences . with vt100 emulation today, these still work.

$ stty
speed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?; swtch = M-^?;
ixany iutf8

uhm? why should a window have a baud rate

as people kept adding features, some of the early interfaces never evolved. there's an interesting discussion on program design in the unix environment by rob pike and  brian kernighan which makes for an interesting read.

here's another escape sequence trick i like to show:
$ for i in `seq 10` `seq 30 38`; do echo "^[[0;$i;40mHello World"; done

where ^[ is the escape sequence you get by Ctrl-V and Esc.

So much fun. My 2 cents (probably not worth anything these days)

 



_______________________________________________
BLUG mailing list
BLUG@linuxfan.com
http://mailman.cs.indiana.edu/mailman/listinfo/blug

No comments: