100 | 100 |
// * OSC response: "\x1b]11;rgb:1111/1111/1111\x1b\\"
|
101 | 101 |
// * cursor position response: "\x1b[42;1R"
|
102 | 102 |
func readNextResponse(fd *os.File) (response string, isOSC bool, err error) {
|
|
103 |
start, err := readNextByte(fd)
|
|
104 |
if err != nil {
|
|
105 |
return "", false, err
|
|
106 |
}
|
|
107 |
|
|
108 |
// if we encounter a backslash, this is a left-over from the previous OSC
|
|
109 |
// response, which can be terminated by an optional backslash
|
|
110 |
if start == '\\' {
|
|
111 |
start, err = readNextByte(fd)
|
|
112 |
if err != nil {
|
|
113 |
return "", false, err
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
103 | 117 |
// first byte must be ESC
|
104 | |
start, err := readNextByte(fd)
|
105 | |
if err != nil {
|
106 | |
return "", false, err
|
107 | |
}
|
108 | |
|
109 | 118 |
if start != '\033' {
|
110 | 119 |
return "", false, ErrStatusReport
|
111 | 120 |
}
|
|
139 | 148 |
response += string(b)
|
140 | 149 |
|
141 | 150 |
if oscResponse {
|
142 | |
// OSC can be terminated by BEL (\a) or ST (ESC \)
|
143 | |
if b == '\a' || strings.HasSuffix(response, "\033\\") {
|
|
151 |
// OSC can be terminated by BEL (\a) or ST (ESC)
|
|
152 |
if b == '\a' || strings.HasSuffix(response, "\033") {
|
144 | 153 |
return response, true, nil
|
145 | 154 |
}
|
146 | 155 |
} else {
|
|
160 | 169 |
}
|
161 | 170 |
|
162 | 171 |
func termStatusReport(sequence int) (string, error) {
|
|
172 |
// screen/tmux can't support OSC, because they can be connected to multiple
|
|
173 |
// terminals concurrently.
|
163 | 174 |
term := os.Getenv("TERM")
|
164 | 175 |
if strings.HasPrefix(term, "screen") {
|
165 | 176 |
return "", ErrStatusReport
|
|
201 | 212 |
return "", err
|
202 | 213 |
}
|
203 | 214 |
|
204 | |
// fmt.Println("Rcvd", s[1:])
|
|
215 |
// fmt.Println("Rcvd", res[1:])
|
205 | 216 |
return res, nil
|
206 | 217 |
}
|