From cc665778e1a2a4f0c506e5b0c8476aceace22ad5 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Thu, 18 Jan 2024 21:36:16 +0100 Subject: [PATCH] Support another terminal color response format Related to (but I can't see how this would fix) #190. --- twin/screen.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/twin/screen.go b/twin/screen.go index 07503272..8ed66e1d 100644 --- a/twin/screen.go +++ b/twin/screen.go @@ -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)