5

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...

Peter V. Mørch
  • 812
  • 7
  • 15

3 Answers3

6

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:

printf "\033[?7h"

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:

tput smam

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.

wfaulk
  • 6,828
  • 7
  • 45
  • 75
  • 1
    Bingo! `tput smam` fixes it! – Peter V. Mørch Aug 10 '14 at 19:01
  • FWIW, I downloaded a Wyse60 emulator and tested connections to HP switches. They still spew out vt100 codes, making them totally unusable in that terminal. Even better, I'll bet you that the folks over at HP's network department have no idea that they've made this unreasonable, pointless assumption. – wfaulk Aug 12 '14 at 22:25
1

Besides reset there are a few other things I always try. And sometimes it helps restoring terminal sanity:

  1. resize (on some systems it's not in $PATH, usually found in something like /usr/X11/bin/)
  2. echo "^v^o" (press CTRL+V and afterwards CTRL+O, this is an old Unix trick that has helped my very often after I inadvertently did cat on a binary file.)
  3. stty sane
Paidhi
  • 326
  • 2
  • 6
  • 1
    Humorous note: `stty cooked` is an alias for `stty sane`. – Paidhi Oct 21 '11 at 07:45
  • I just tried these, and my terminal is still broken. I note that 'echo "^v^o"' Is never seen in the terminal. I pressed `e+c+h+o++CTRL-V+CTRL-O+`, right? That printed `echo ^O` in my terminal. – Peter V. Mørch Oct 26 '11 at 09:48
  • That's right. I think the quotation (") is optional. This often helped me with a broken terminal shell session. Especiallay when connected to HP-UX systems. – Paidhi Oct 30 '11 at 10:14
0

In addition try:

# https://gist.github.com/raw/1294767/a1ea19be2f70b092057a5232c2d05a0ee9bf145b/hptelnet.escape
cat hptelnet.escape

tput reset

# each of the following commands may work as well
tput smcup   # string to start programs using cup
tput is2     # initialization string; init_2string


# ... and as a last resort try ...
# cf. "The Alternate Character Set", 
# http://www.in-ulm.de/~mascheck/various/alternate_charset/

# added \033c to clear screen
alias vtn='echo "X[mX(BX)0OX[?5lX7X[rX8Xc" | tr "XO" "\033\017"'   
vtn
markc
  • 1
  • Thanks. I tried all 4 of these, but they didn't work for me. You write "may work", and "as a last resort try"... Did any of these actually work for you? Which ones? – Peter V. Mørch Feb 19 '13 at 22:14