forked from hackerb9/vt340test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colortable.sh
executable file
·163 lines (150 loc) · 4.99 KB
/
colortable.sh
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
#!/bin/bash
CSI=$'\e[' # Control Sequence Introducer
DCS=$'\eP' # Device Control String
ST=$'\e\\' # String Terminator
# Request Color Table Report
# NB: at 9600 bps, it takes over 1.25s for a genuine VT340 to respond.
if ! IFS=$'/\es' read -a REPLY -t 2 -s -p ${CSI}'2;2$u' -r -d '\\'; then
echo Terminal did not respond.
exit 1
fi
showargs "${REPLY[@]}" | cat -v
# Response prefix is ESC P 2 $ s and suffix is ESC \.
# However, since we have IFS cutting on ESC and the letter s,
# we can simply ignore first two elements of the REPLY array.
# Response data is separated by slashes, which we used IFS to cut on.
# Now, each element is of the form Pc ; Pu ; Px ; Py ; Pz where
# Pc is color index (0 to 15)
# Pu is universal color space (1 for HLS, 2 for RGB)
# Px,Py,Pz are either Hue, Lightness, Saturation or Red, Green, Blue.
#
# Note that Hue ranges from 0 to 360. All other values range from 0 to 100.
# (Also note that Hue 0 == Hue 360.)
#
######################################################################
# Documentation
## From DEC VTxxx Text Programming, page 206, "VT300 Reports"
#
# Use the following format to request a color table report.
#
# - DECRQTSR Request Color Table Report
#
# CSI 2 ; Ps2 $ u
# 9/11 3/2 3/11 3/? 2/4 7/5
#
# where
#
# CSI, the Control Sequence Introducer, is 0x9B or ESC [ in a 7-bit environment.
#
# Ps2 indicates the color coordinate system the terminal uses to send
# the report.
#
# Ps2 Color Coordinate System
# 0 or none HLS (default)
# 1 HLS
# 2 RGB
## From DEC VTxxx Text Programming, page 307, "VT300 Reports"
#
# DECCTR: Color Table Report from VT300 to Host the terminal sends
# this sequence is response to a Request Terminal State Report
# (DECRQTSR). DECCTR informs the host of the terminal's current color
# settings.
#
# PROGRAMMING TIP: Applications can use the information in the color
# table report to save the current color map. Later, the application
# can restore the saved color map.
#
## From DEC VTxxx Text Programming, page 308, "VT300 Reports"
#
# This operation is useful for applications that need to temporarily
# change the terminal's color map. When the application is finished,
# it can restore the color map that was in effect before the
# application changed it. You use the restore terminal state (DECRSTS)
# function to restore the color map. DECRSTS is described in the next
# section.
#
# DCS 2 $ s D...D ST
# 9/0 3/2 2/4 7/3 ... 9/12
#
#
# where
#
# DCS is the Device Control String (0x90 or ESC P in 7-bit environments),
#
# D...D is the data string containing the color table information.
#
# ST is the String Terminator (0x9C or ESC \ in 7-bit environments).
#
# The data string is divided into groups of five values, as follows.
#
# Pc;Pu;Px;Py;Pz / Pc;Pu;Px;Py;Pz / ...
#
# where
#
# Pc is the color number (0 through 255).
#
# ; (semicolon, 3/11) separates the parameters.
#
# Pu indicates the universal coordinate system used.
# Pu Coordinate System
# 1 HLS (hue, lightness, saturation)
# 2 RGB (red, green, blue)
#
# Px; Py; Pz are color coordinates in the specified coordinate system.
#
# Parameter HLS Values RGB Values
# Px 0 to 360 (hue angle) 0 to 100 (red intensity)
# Py 0 to 100 (lightness) 0 to 100 (green intensity)
# Pz 0 to 100 (saturation) 0 to 100 (blue intensity)
#
## From DEC VTxxx Text Programming, page 309, "VT300 Reports"
#
# Restore Terminal State (DECRSTS) — VT300 Mode Only
#
# This sequence restores the terminal to a previous state specified in
# a terminal state report (DECTSR). There are two terminal state
# reports.
#
# Terminal state report (DECTSR)
# Color table report (DECCTR)
#
# PROGRAMMING TIP: Applications can use DECRSTS to restore the
# terminal to a previous operating state specified in a terminal state
# report. See the "Terminal State Report (DECTSR)" and "Color Table
# Report (DECCTR)" sections in this chapter.
# Available in: VT300 mode
#
# DCS Ps $ p D...D ST
# 9/0 3/? 2/4 7/0 ... 9/12
#
# where
#
# DCS Device Control String, 0x90 or ESC P in 7-bit environments.
#
# Ps indicates the format of the data string (D...D).
# You can use one of the two following formats for the
# the data string. These formats correspond to the
# formats used by the two terminal state reports
# (DECTSR). Make sure you use the format used by the
# report you are restoring.
#
# Ps Data String Format
# 0 Error, restore ignored.
# 1 Selects the format of the terminal state report (DECTSR)
# 2 Selects the format of the color table report (DECCTR)
#
# D...D is a data string that contains the restored information.
# This string is identical to the data string used by the
# report you are restoring.
#
# ST String Terminator, 0x9C or ESC \ in 7-bit environments.
#
# Notes on DECRSTS
#
# • If there is an invalid value in the DECRSTS sequence, the terminal
# ignores the rest of the sequence. This action may leave the
# terminal in a partially restored state.
#
# • Software should not expect the format of the terminal state report
# (DECTSR) to be the same for all VT300 family members.
#