mirror of
https://github.com/walles/moar.git
synced 2024-09-11 20:17:13 +03:00
Support another terminal color response format
Related to (but I can't see how this would fix) #190.
This commit is contained in:
parent
35b0ffca2b
commit
cc665778e1
@ -526,10 +526,12 @@ func (screen *UnixScreen) Size() (width int, height int) {
|
||||
|
||||
func parseTerminalBgColorResponse(responseBytes []byte) *Color {
|
||||
prefix := "\x1b]11;rgb:"
|
||||
suffix := "\x07"
|
||||
sampleResponse := prefix + "0000/0000/0000" + suffix
|
||||
suffix1 := "\x07"
|
||||
suffix2 := "\x1b\\"
|
||||
sampleResponse1 := prefix + "0000/0000/0000" + suffix1
|
||||
sampleResponse2 := prefix + "0000/0000/0000" + suffix2
|
||||
|
||||
if len(responseBytes) != len(sampleResponse) {
|
||||
if len(responseBytes) != len(sampleResponse1) && len(responseBytes) != len(sampleResponse2) {
|
||||
// Not a bg color response
|
||||
return nil
|
||||
}
|
||||
@ -541,11 +543,12 @@ func parseTerminalBgColorResponse(responseBytes []byte) *Color {
|
||||
}
|
||||
response = strings.TrimPrefix(response, prefix)
|
||||
|
||||
if !strings.HasSuffix(response, suffix) {
|
||||
if !strings.HasSuffix(response, suffix1) && !strings.HasSuffix(response, suffix2) {
|
||||
log.Debug("Got unexpected suffix in bg color response from terminal: ", string(responseBytes))
|
||||
return nil
|
||||
}
|
||||
response = strings.TrimSuffix(response, suffix)
|
||||
response = strings.TrimSuffix(response, suffix1)
|
||||
response = strings.TrimSuffix(response, suffix2)
|
||||
|
||||
// response is now "RRRR/GGGG/BBBB"
|
||||
red, err := strconv.ParseUint(response[0:4], 16, 16)
|
||||
|
Loading…
Reference in New Issue
Block a user