termenv
termenv copied to clipboard
Garbage left in input buffer on urxvt with transparent background color set
urxvt -fg white -bg rgba:0000/0000/0000/C000- Inside the terminal, run
gh --version, or most anything that callstermenv.DefaultOutput().BackgroundColor()I've also personally noticed what seems to be the same issue with https://github.com/numtide/treefmt - Garbage characters are left behind and read by your shell, or whatever next reads from the terminal.
Here's the leftover input buffer contents (with 2 ctrl-d's to flush it through hexdump):
$ gh --version; hexdump -C
^[]11;rgba:0000/0000/0000/c000^[^[[114;1Rgh version 2.72.0 (nixpkgs)
https://github.com/cli/cli/releases/tag/v2.72.0
00000000 5b 31 31 34 3b 31 52 1b 5d 31 31 3b 72 67 62 61 |[114;1R.]11;rgba|
00000010 3a 30 30 30 30 2f 30 30 30 30 2f 30 30 30 30 2f |:0000/0000/0000/|
00000020 63 30 30 30 1b 1b 5b 31 31 34 3b 31 52 |c000..[114;1R|
0000002d
Context: https://github.com/cli/cli/issues/10830
Thanks, @ei-grad for tracking this down.
A simple fix could be:
diff --git a/termenv_unix.go b/termenv_unix.go
index bef49ca..7622e97 100644
--- a/termenv_unix.go
+++ b/termenv_unix.go
@@ -223,7 +223,7 @@ func (o *Output) readNextResponse() (response string, isOSC bool, err error) {
}
// both responses have less than 25 bytes, so if we read more, that's an error
- if len(response) > 25 { //nolint:mnd
+ if len(response) > 64 { //nolint:mnd
break
}
}
However, this will result in incorrect color parsing. I looked deeply into the urxvt color conversion code, but couldn't find a good solution.
I can confirm that patch resolves the input buffer issue. I'm already using it as a local solution.
Properly parsing urxvt's response is obviously ideal, but bad color detection is still a big step up from "gh is unusable." 🙂