Codebase list golang-github-muesli-termenv / d1b90ad
Support backslash-less report termination, as used by rxvt Christian Muehlhaeuser 3 years ago
3 changed file(s) with 26 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
159159 switch {
160160 case strings.HasSuffix(s, "\a"):
161161 s = strings.TrimSuffix(s, "\a")
162 case strings.HasSuffix(s, "\033"):
163 s = strings.TrimSuffix(s, "\033")
162164 case strings.HasSuffix(s, "\033\\"):
163165 s = strings.TrimSuffix(s, "\033\\")
164166 default:
77 color RGBColor
88 valid bool
99 }{
10 {
11 "\033]11;rgb:fafa/fafa/fafa\033",
12 RGBColor("#fafafa"),
13 true,
14 },
1015 {
1116 "\033]11;rgb:fafa/fafa/fafa\033\\",
1217 RGBColor("#fafafa"),
100100 // * OSC response: "\x1b]11;rgb:1111/1111/1111\x1b\\"
101101 // * cursor position response: "\x1b[42;1R"
102102 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
103117 // first byte must be ESC
104 start, err := readNextByte(fd)
105 if err != nil {
106 return "", false, err
107 }
108
109118 if start != '\033' {
110119 return "", false, ErrStatusReport
111120 }
139148 response += string(b)
140149
141150 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") {
144153 return response, true, nil
145154 }
146155 } else {
160169 }
161170
162171 func termStatusReport(sequence int) (string, error) {
172 // screen/tmux can't support OSC, because they can be connected to multiple
173 // terminals concurrently.
163174 term := os.Getenv("TERM")
164175 if strings.HasPrefix(term, "screen") {
165176 return "", ErrStatusReport
201212 return "", err
202213 }
203214
204 // fmt.Println("Rcvd", s[1:])
215 // fmt.Println("Rcvd", res[1:])
205216 return res, nil
206217 }