I telnet to an HP switch from my (xterm|gnome-terminal). Exit telnet. That breaks the behaviour of the terminal. (If you don't have a HP switch to telnet to, one can cat
this file in a terminal instead).
Now type a very long command (more than one line, and see that the second line doesn't wrap down to the next line, but "stays in the current line". Which makes it impossible to edit prior commands or use the terminal for anything longer than one line.
See that cat filewithlonglines.txt
or git log -p
only shows the first 80 chars of lines longer than 80 chars.
reset
doesn't work. stty -g > stty.works
, run telnet, stty $(stty.works)
restores changed stty
settings, but behaviour is still broken.
I have to close the terminal and start a new one. :-(
What can I do besides reset
and stty
save/restore to fix my broken terminals after a telnet?
EDIT: I've discovered that if I use screen
like in one of these commands:
screen bash -c "cat hptelnet.escape ; bash"
or
screen telnet hpswitch
Then my terminal still works properly when screen exits. So a workaround is to put screen in front of the command that messes up my terminal, but I'd still like to know how to recover a terminal that already has been messed up...
In the specific case of the problem caused by HP switches, I found (by using
script
, which records every byte sent to the terminal), that the autowrap mode of the terminal was being turned off via the VT100 code "<ESC>[?7l
" and then never being turned back on again. †The VT100 code to turn autowrap back on is "
<ESC>[?7h
", which you could send to the terminal with this command:However, this assumes that your terminal is VT100-compliant, which, while a good bet, is not a certainty.‡ The more correct way to do it is to rely on your terminfo settings and run this command:
which generates the exact same output as the above
printf
command, assuming a VT100-style terminal. The terminfo capability "smam" is "Set Mode: Automatic Margins". Its partner is "rmam": "Reset Mode: Automatic Margins".By the way, I really wish
ssh
had a "LocalEndCommand" config option (similar to "LocalCommand") so that I could just have it automatically run this un-fucker at the end of every HP switch ssh connection.† Thanks, HP!
‡ Do you think HP made that bet or not? I'm guessing they did, and always send VT100 codes. In which case, if your terminal isn't VT100-compatible, you won't be having this problem to begin with.
Besides
reset
there are a few other things I always try. And sometimes it helps restoring terminal sanity:resize
(on some systems it's not in $PATH, usually found in something like /usr/X11/bin/)echo "^v^o"
(pressCTRL+V
and afterwardsCTRL+O
, this is an old Unix trick that has helped my very often after I inadvertently didcat
on a binary file.)stty sane
In addition try: