aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2018-08-29 13:46:49 -0400
committerB. Watson <yalhcru@gmail.com>2018-08-29 13:46:49 -0400
commitb5d2db7e452c6463ff7629e9d0fb8525c881bce4 (patch)
tree23112cda4cf40367f910833222a5626df5128ccb
parent6139a45988ab697662575ab9862d8a9cd2a9d33c (diff)
downloadmisc-scripts-b5d2db7e452c6463ff7629e9d0fb8525c881bce4.tar.gz
fixterm: fix a urxvt or xterm that's stuck displaying gibberish
-rwxr-xr-xfixterm28
1 files changed, 28 insertions, 0 deletions
diff --git a/fixterm b/fixterm
new file mode 100755
index 0000000..e9fd832
--- /dev/null
+++ b/fixterm
@@ -0,0 +1,28 @@
+#!/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
+
+print chr(27).")B";
+print chr(27)."(B";