#!/usr/bin/perl -w # For when a misbehaving curses app leaves xterm or urxvt in a state # where it prints gibberish. This also can happen when a binary is # catted to the terminal. If the sequence "Escape ( 0" gets printed, # we get stuck in gibberish mode (there might be a couple other escape # sequences that do the same). # We get crap like this: # <┤⎼␌␤┌▒≤@└⎺┼⎺┌␋├␤:·/⎽␉⎺±␋├/▒┤␍␋⎺/␍⎼┤└┐┴1>$ # I *think* the explanation below is accurate: # There are 2 character sets called G0 and G1. Either of these can be # set to various settings. The normal setting is "United States". There's # also a "United Kingdom" and "Special chars & line set". We can set G0 # and G1 to any of these, and switch between whatever G0 and G1 are with # Esc(1 and Esc)1. # When the terminal gets stuck in gibberish mode, what's happened is that # "Special chars & line set" has become the active character set. The # fix is to set both the "G0" and "G1" character sets to US. # Reference: # http://ascii-table.com/ansi-escape-sequences-vt-100.php # urxvt and IIRC xterm actually support 4 character sets, G0 thru # G3, any of which can be switched between various types. So fix # all 4 here. # This script seems to work OK for urxvt but not for xterm. # For either, it fixes your shell... but on xterm, links is # sometimes still messed up (and sometimes it isn't, I dunno # what's different). print chr(27).')B'; print chr(27).'(B'; print chr(27).'*B'; print chr(27).'+B';