-
Notifications
You must be signed in to change notification settings - Fork 5
/
checkmode
executable file
·385 lines (331 loc) · 17 KB
/
checkmode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#!/bin/bash
# checkmodes
#
# Print the status of DEC Private modes given on command line.
# If no arguments are given, checks all known modes.
#
# With -v flag, also show notes, if any.
# With -x flag, also print "Not recognized" for unrecognized modes.
# With -m flag, output as a Markdown table.
# With -t flag, trawl through modes 0 to 9999.
# How long to wait for the terminal to reply, in seconds. (Non-integer okay).
#timeout=1.0
# By default, show double-wide frippery
fflag=yup
status=("not recognized" "set" "reset" "permanently set" "permanently reset")
checkmode() {
# Given a DEC private mode number, query the terminal with DECRQM.
# Prints a result from the 0 to 4. ([0]="not recognized" [1]="set"
# [2]="reset" [3]="permanently set" [4]="permanently reset").
#
# If the terminal doesn't reply within ${timeout} seconds, prints
# nothing and returns an error . (Default timeout is 0.25 seconds).
IFS=";$" read -a REPLY -t${timeout:-0.25} -s -p $'\e[?'$1'$p' -d y \
&& echo "${REPLY[1]}"
}
printmodes() {
# Print the status of DEC Private modes given on command line.
# With -v flag, also show notes.
# With -x flag, also print "Not recognized" for unrecognized modes.
# If no arguments given, check every known mode.
if [[ $# -eq 0 ]]; then set - ${!Ps[@]}; fi
if [[ -t 1 && $fflag ]]; then # stdout is a terminal? let's go garish!
local dw=$'\e#6' # dw turns on double-wide characters
status=( "$(tput dim)not recognized$(tput sgr0)$dw"
"$(tput bold)set$(tput sgr0)$dw"
"reset$dw"
"$(tput ul bold)permanently set$(tput sgr0)$dw"
"$(tput ul)permanently reset$(tput sgr0)$dw" )
fi
if [[ $vflag ]]; then
local COLUMNS=$(tput cols)
COLUMNS=${COLUMNS:-80}
fi
for mode; do
if ! result=$(checkmode $mode); then
echo "Error: Terminal did not respond." >&2
exit 1
fi
# Skip "Not recognized", unless -x given, or only one arg.
if [[ ${result} -ne 0 || $xflag || $# -eq 1 ]]; then
echo "Checking mode #$mode. ${Ps[$mode]}"
echo "${status[result]}"
if [[ $vflag ]]; then
echo ${Nt[mode]:--n} | fold -sw $((COLUMNS-24)) | sed 's/^/\t/'
fi
fi
done
}
maketable() {
# Check the status of each DEC private mode given as an argument
# and create a MarkDown table. Similar to printmodes() above.
# Allows -x flag to print "Not recognized" results.
# Ignores -v, notes are always printed.
# If no arguments given, check every known mode.
if [[ $# -eq 0 ]]; then set - ${!Ps[@]}; fi
for mode; do
if ! result=$(checkmode $mode); then
echo "Terminal did not respond to mode $mode." >&2
else
# Skip "Not recognized"
if [[ $result == 0 && -z "$xflag" ]]; then continue; fi
echo -n "$mode | "
echo -n "${status[result]}"
echo "| ${Ps[$mode]} | ${Nt[$mode]//|/\\|}"
fi
done
}
usage() {
cat <<EOF
Usage:
checkmode # Try all known DEC Private Modes
checkmode 80 # Request the status of mode 80.
checkmode {1..100} # Request the status of modes 1 to 100.
Options:
-v, --show-notes Show notes of unusual, surprising trivia
-x, --show-not-recognized Do not skip modes the terminal doesn't recognize
-m, --output-markdown Output a Markdown table instead of plain text
-t, --trawl Try modes from 0 to 9999
-F, --no-frippery Don't use double-wide chars or other frippery
EOF
}
main() {
local TEMP
if ! TEMP=$(
getopt -o 'vxmtFfh' \
--long 'show-notes' \
--long 'show-not-recognized' \
--long 'output-markdown' \
--long 'trawl' \
--long 'no-frippery' \
--long 'frippery' \
--long 'help' \
--name 'checkmode' -- "$@"); then
# Invalid option error, so just quit.
exit 1
fi
eval set -- "$TEMP"
while true; do
case "$1" in
-v|--show-notes)
vflag=yup
shift
;;
-x|--show-not-recognized)
xflag=yup
shift
;;
-m|--output-markdown)
mflag=yup
shift
;;
-t|--trawl)
tflag=yup
shift
;;
-F|--no-frippery)
fflag=""
shift
;;
-f|--frippery)
fflag="yup"
shift
;;
'--')
shift
break
;;
*)
usage
exit 1
;;
esac
done
if [[ $tflag ]]; then
if [[ $# -eq 0 ]]; then
set -- {0..9999}
else
echo "Warning: Ignoring --trawl since modes were specified" >&2
fi
fi
if [[ -z $mflag ]]; then
printmodes "$@"
else
maketable "$@"
fi
# Return value is same as whichever function got run.
}
# Ps holds the array of DEC Private Mode. (See end for list of scoures.)
Ps=()
Ps[0]="Invalid mode"
Nt[0]="Use of mode #0 is an error and always ignored." # std-070
Ps[1]="Application Cursor Key Mode (DECCKM), VT100." # From std-070
Nt[1]="When SET, arrow keys send special application commands to the host"
Ps[2]="Designate US ASCII/ANSI for character sets G0-G3 (DECANM), VT100." # From Xterm
Ps[2]="VT52 (ANSI) Mode (DECANM), VT100." # From ek-520-rm
Nt[2]="To leave VT52 mode, use Esc <."
Ps[3]="132 Column Mode (DECCOLM), VT100."
Nt[3]="VT340 docs claim DECCOLM is deprecated for DECSCPP (CSI 132 $ |). However, DECSCPP sets the columns per _page_, not screen. Unlike DECCOLM, DECSCPP does not change the visible number of columns on the screen; instead DECSCPP requires horizontal scrolling (see mode 60, DECHCCM)." # ek-vt3xx-tp
Nt[3]+=" On the VT5x0, see mode 95 (DECNCSM) to prevent the page from being cleared by DECCOLM." # ek-520-rm
Ps[4]="Smooth (Slow) Scroll (DECSCLM), VT100."
Nt[4]="On the VT340 and possibly other terminals, this option is not binary. In the SetUp menu, scrolling can be 'Jump' (same as RESET), or 'Smooth-1', '-2', or '-4' which scroll by scanlines instead of character cells. The VT340 factory default is 'Smooth-2', which is 25 scanlines (2.5 text lines) per second. Smooth-1 is half and Smooth-4 is twice the speed. If any of the Smooth options are selected, then the result from DECRQM (Request DEC Private Mode) will show mode 4 as SET. However, when mode 4 is SET using DECSET (CSI ? 4 h), the VT340 always selects Smooth-2. See also the VT5x0's DECSSCLS (Set Scroll Speed, CSI Ps SP p)."
Ps[5]="Reverse Video Screen (DECSCNM), VT100."
Nt[5]="SET is light bg, RESET is dark bg." # From EK-VT38T-UG.
Ps[6]="Origin Mode (DECOM), VT100."
Ps[7]="Auto-Wrap Mode (DECAWM), VT100."
Nt[7]="When RESET, cursor will not advance beyond right-most column." # From std-070
Ps[8]="Auto-Repeat Keys (DECARM), VT100."
Ps[9]="Interlace mode (DECINLM), VT1xx only." # Documented in VT100-UG
Ps[9]="Send Mouse X & Y on button press, X10 XTerm." # Conflicts with VT100-UG
Nt[9]="VT100 used mode 9 for interlace, but dropped it in VT200+."
Ps[10]="Show toolbar, rxvt." # Conflicts with ek-vt3xx-tp.
Ps[10]="Edit Mode (DECEDM)." # As documented by ek-vt3xx-tp.
Ps[11]="Line Transmit Mode (DECLTM)." # Added from ek-vt3xx-tp.
Ps[12]="Start blinking cursor (AT&T 610)." # Conflicts with ek-vt382-rm.
Ps[12]="Katakana Shift Mode (DECKANAM), VT382-J" # Documented in ek-vt382-rm.
Ps[13]="Start blinking cursor, xterm." # Conflicts with ek-vt3xx-tp.
Ps[13]="Space compression field delimiter (DECSCFDM)" # As documented by ek-vt3xx-tp.
Ps[14]="XOR of blinking cursor control sequence and menu." # Conflicts with ek-vt3xx-tp.
Ps[14]="Transmit execution (DECTEM)." # As documented by ek-vt3xx-tp.
Ps[16]="Edit key execution (DECEKEM)." # Added from ek-vt3xx-tp.
Ps[18]="Print Form Feed (DECPFF), VT220."
Nt[18]="When SET, the terminal sends a form feed (FF) to the printer at the end of a printing function. The default, RESET, is to send to nothing. DECPFF does not affect the Print Cursor Line function." # ek-vt3xx-tp
Ps[19]="Set printer extent to full screen (DECPEX), VT220."
Nt[19]="When RESET, the print page function only prints the scrolling region (data inside the margins)." # ek-vt3xx-tp
Ps[20]="Overstrike Mode (OS), VK100." # Documented in ek-vk100-tm-001
Ps[21]="Local BASIC Mode (BA), VK100." # Documented in ek-vk100-tm-001
Ps[22]="Host BASIC Mode (BA), VK100." # Documented in ek-vk100-tm-001
Ps[23]="Programmed Keypad Mode (PK), VK100." # Documented in ek-vk100-tm-001
Ps[24]="Auto Hardcopy Mode (AH), VK100." # Documented in ek-vk100-tm-001
Ps[25]="Text cursor enable (DECTCEM), VT220."
Ps[27]="Proportional Spacing, printers." # Added from ppl2
Ps[29]="Pitch Select Mode, printers." # Added from ppl2
Ps[30]="Show scrollbar, rxvt."
Ps[34]="Cursor direction, right to left." # Added from ek-520-rm
Ps[35]="Tektronix mode (DECTEK), incorrect." # As erroneously documented by ek-vt3xx-tp.
Nt[35]="ek-vt3xx-tp is in error. DECTEK is actually 38."
Ps[35]="Font-shifting functions, rxvt." # As documented by Xterm
Ps[35]="Hebrew keyboard mapping." # Added from ek-520-rm
Ps[36]="Hebrew encoding mode." # Added from ek-520-rm
Ps[38]="Tektronix mode (DECTEK), VT240, xterm." # As documented by Xterm
Ps[40]="Allow 80/132 mode, xterm." # From xterm. Conflicts with ppl2.
Nt[40]="Allow DECCOLM (mode 3) to switch columns."
Ps[40]="Carriage Return/New Line Mode (DECCRNLM), printers." # From ppl2
Ps[41]="more(1) fix." # From xterm. Conflicts with ppl2.
Ps[41]="Unidirectional Print Mode (DECUPM), printers." # From ppl2
Nt[41]="Bidirectional when RESET."
Ps[42]="National Replacement Character sets (DECNRCM), VT220."
Nt[42]="On the VT340 and perhaps other terminals, DECNRCM is PERMANENTLY RESET when the Keyboard Dialect selected in the Set Up menu is 'North American'."
Ps[43]="Graphics Expanded Print Mode (DECGEPM)."
Ps[44]="Margin bell, xterm." # Conflicts with ek-vt3xx-tp.
Ps[44]="Graphics Print Color (DECGPCM)" # As documented by ek-vt3xx-tp
Ps[45]="Reverse-wraparound mode, xterm." # Conflicts with ek-vt3xx-tp.
Ps[45]="Graphics Print Color Space (DECGPCS)." # As documented by Xterm.
Ps[45]="Graphics Print Color Syntax (DECGPCS)." # As documented by ek-vt3xx-tp.
Ps[46]="Start logging, xterm." # Conflicts with ek-vt3xx-tp.
Ps[46]="Graphics Print Background (DECGPBM)." # As documented by ek-vt3xx-tp.
Ps[47]="Use Alternate Screen Buffer, xterm." # Conflicts with ek-vt3xx-tp.
Ps[47]="Graphics Rotated Print Mode (DECGRPM)." # As documented by ek-vt3xx-tp.
Ps[49]="Thai Keyboard Input Mode (DECTHAIM), VT382-T" # Added from ek-vt38t-ug
Ps[50]="Thai Cursor Mode (DECTHAICM), VT382-T" # Added from ek-vt38t-ug
Nt[50]="SET is internal cursor, RESET is physical cursor"
Ps[53]="VT131 transmit (DEC131TM)." # Added from ek-vt3xx-tp.
Ps[57]="North American / Greek keyboard mapping (DECNAKB)" # Added from ek-520-rm
Ps[58]="IBM ProPrinter Emulation (DECIPEM)" # Added from ek-520-rm
Nt[58]="Interpret subsequent data according to the IBM ProPrinter protocol syntax instead of the DEC protocol."
Ps[59]="Kanji/Katakana Display Mode (DECKKDM), VT382-J" # Documented in ek-vt382-rm.
Ps[60]="Horizontal cursor coupling (DECHCCM)." # Added from ek-vt3xx-tp.
Ps[61]="Vertical cursor coupling (DECVCCM)." # Added from ek-vt3xx-tp.
Ps[64]="Page cursor coupling (DECPCCM)." # Added from ek-vt3xx-tp.
Ps[66]="Application/Numeric keypad mode (DECNKM), VT320"
Ps[67]="Backarrow key sends backspace (DECBKM), VT340, VT420, VT520."
Nt[67]="When RESET (the default), backarrow key sends delete."
Ps[68]="Keyboard Usage: Data Processing or Typewriter Keys (DECKBUM)." # Added from ek-vt3xx-tp.
Nt[68]="Data Processing characters are printed on the right half of the keycaps. According to ek-520-rm, 'If you use the North American language, then DECKBUM should always be RESET (typewriter). For all other languages, you can use either mode.'"
Ps[69]="Left and right margin mode (DECLRMM), VT420 and up." # Allows DECSLRM to set margins
Ps[69]="Vertical split screen / Left and right margin mode (DECVSSM/DECLRMM), VT420 and up." # Added from ek-520-rm. (Yes, it gives two different mnemonics!)
Ps[73]="Transmit rate limiting (DECXRLM)." # Added from ek-vt3xx-tp.
Ps[80]="Sixel Display Mode (DECSDM)."
Ps[81]="Keyboard sends key position reports instead of character codes (DECKPM)." # Added from ek-520-rm
Ps[90]="Thai Space Compensating Mode (DECTHAISCM), VT382-T" # Added from ek-vt38t-ug
Ps[95]="Do not clear screen when DECCOLM is set/reset (DECNCSM), VT510 and up."
Ps[96]="Perform a copy/paste from right-to-left (DECRLCM), VT520" # Added from ek-520-rm
Nt[96]="Only valid with Hebrew keyboard language, see DEC mode 35"
Ps[97]="CRT Save Mode (DECCRTSM), VT520" # Added from ek-520-rm
Ps[98]="Auto-resize the number of lines-per-page when the page arrangement changes (DECARSM), VT520" # Added from ek-520-rm
Ps[99]="Modem Control Mode: require DSR or CTS before communicating (DECMCM), VT520" # Added from ek-520-rm
Ps[100]="Send automatic answerback message 500ms after a communication line connection is made (DECAAM), VT520" # Added from ek-520-rm
Ps[101]="Conceal Answerback Message (DECCANSM), VT520" # Added from ek-520-rm
Ps[102]="Discard NUL characters upon receipt, or pass them on to the printer (DECNULM)" # Added from ek-520-rm
Ps[103]="Half-Duplex Mode (DECHDPXM), VT520" # Added from ek-520-rm
Ps[104]="Enable Secondary Keyboard Language (DECESKM), VT520" # Added from ek-520-rm
Ps[106]="Overscan mode for monochrome VT520 terminal (DECOSCNM)" # Added from ek-520-rm
Ps[108]="Num Lock Mode of keyboard (DECNUMLK)" # Added from ek-520-rm
Ps[109]="Caps Lock Mode of keyboard (DECCAPSLK)" # Added from ek-520-rm
Ps[110]="Keyboard LED's Host Indicator Mode (DECKLHIM)" # Added from ek-520-rm
Ps[111]="Framed Windows with title bars, borders, and icons (DECFWM), VT520" # Added from ek-520-rm
Ps[112]="Allow user to Review Previous Lines that have scrolled off the top (DECRPL)" # Added from ek-520-rm
Ps[113]="Host Wake-up Mode, CRT and Energy Saver (DECHWUM), VT520" # Added from ek-520-rm
Ps[114]="Use an alternate text color for underlined text (DECATCUM), VT520" # Added from ek-520-rm
Ps[115]="Use an alternate text color for blinking text (DECATCMB), VT520" # Added from ek-520-rm
Ps[116]="Bold and blink styles affect background as well as foreground (DECBSM), VT520" # Added from ek-520-rm
Ps[117]="Erase Color is screen background (VT) or text background (PC) (DECECM), VT520" # Added from ek-520-rm
Nt[117]="Background color used when text is erased or new text is scrolled on to the screen"
Ps[1000]="Send Mouse X & Y on button press and release. (X11 XTerm mouse)."
Ps[1001]="Use Hilite Mouse Tracking, xterm."
Ps[1002]="Use Cell Motion Mouse Tracking, xterm."
Ps[1003]="Use All Motion Mouse Tracking, xterm."
Ps[1004]="Send FocusIn/FocusOut events, xterm."
Ps[1005]="UTF-8 Mouse Mode, xterm."
Ps[1006]="SGR Mouse Mode, xterm."
Ps[1007]="Alternate Scroll Mode, xterm."
Ps[1010]="Scroll to bottom on tty output, rxvt."
Ps[1011]="Scroll to bottom on key press, rxvt."
Ps[1015]="Urxvt Mouse Mode, rxvt."
Ps[1016]="SGR Mouse PixelMode, xterm."
Ps[1021]="High intensity bold/blink color, rxvt." # From VTE modes.py
Ps[1034]="Interpret 'Meta' key, xterm."
Nt[1034]="This sets the eighth bit of keyboard input."
Ps[1035]="Enable special modifiers for Alt and NumLock keys, xterm."
Ps[1036]="Send ESC when Meta modifies a key, xterm."
Ps[1037]="Send DEL from the editing-keypad Delete key, xterm."
Ps[1039]="Send ESC when Alt modifies a key, xterm."
Ps[1040]="Keep selection even if not highlighted, xterm."
Ps[1041]="Use the CLIPBOARD selection, xterm."
Ps[1042]="Enable Urgency windowmanager hint when Control-G received, xterm."
Ps[1043]="Enable raising of the window when Control-G is received, xterm."
Ps[1044]="Reuse the most recent data copied to CLIPBOARD, xterm"
Ps[1046]="Enable switching to/from Alternate Screen Buffer, xterm."
Ps[1047]="Use Alternate Screen Buffer, xterm."
Ps[1048]="Save cursor as in DECSC, xterm."
Ps[1049]="Save cursor as in DECSC, switch to the Alternate Screen Buffer."
Ps[1050]="Set terminfo/termcap function-key mode, xterm."
Ps[1051]="Set Sun function-key mode, xterm."
Ps[1052]="Set HP function-key mode, xterm."
Ps[1053]="Set SCO function-key mode, xterm."
Ps[1060]="Set legacy keyboard emulation, i.e, X11R6, xterm."
Ps[1061]="Set VT220 keyboard emulation, xterm."
Ps[1070]="Use private color registers for each graphic, xterm."
Nt[1070]="When SET, each Sixel/ReGIS graphic gets a fresh palette. When RESET, colormap changes persist just like on a true VT340. SET is the default for XTerm."
Ps[2004]="Set bracketed paste mode, xterm."
Ps[2026]="Synchronized output. iTerm2, Contour, Kitty." # From https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
Nt[2026]="When SET, new data is not displayed until the mode is RESET. Can be used by applications for double-buffering & page flipping to prevent screen tearing."
Ps[8452]="Sixel leaves cursor right of image, RLogin, xterm."
# Okay, all the definitions are set. Topple them dominos!
main "$@"
# Sources (most frequently used first) for DEC private modes:
# XTerm ctlseqs.pdf (default if not otherwise marked)
# VT520/525 Reference Manual ek-520-rm
# VT300 Text Programming ek-vt3xx-tp
# DEC STD 070 std-070
# VK100 Technical Manual ek-vk100-tm
# VT382-J (Japanese) Reference Manual ek-vt382-rm
# VT382-T (Thai) User Guide ek-vt38t-ug
# VT100 User Guide VT100-UG
# DEC Printing Protocol Level 2 quickref ppl2
# LG06/LG12 Companion Printer lg12
# Missing manuals:
# VT382-K (Korean)
# VT382-D (Traditional Chinese)
# VT382-C (Simplified Chinese))
# VT282-J, VT382-J, VT383-J, VT284-J, VT286-J (Japanese terminals)