Using hints from the answers to this question, I can easily get the color value of the current terminal if I run the command directly in shell
But I need to get this value inside the Go program
Apparently, the problem is that the command from the answer calls a subprocess from which the result should appear in stdout, but I can’t capture it in any way
System info
macOS Monterey 12.6 (21G115)
Apple M1 Pro
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
go version go1.19.1 darwin/arm64
I am trying to do it with this code
cmd := exec.Command("sh", "-c", `echo '\033]11;?\007'`)
out := &bytes.Buffer{}
stderr := &bytes.Buffer{}
cmd.Stdout = out
cmd.Stderr = stderr
err := cmd.Run()
if err != nil {
panic(err)
}
println("result", out.String(), "end")
output is
bash-3.2$ go run .
result
end
^\[\]11;rgb:2b2b/2b2b/2b2b^Gbash-3.2$ 11;rgb:2b2b/2b2b/2b2b
I tried to add sleep time in bash and in go code. I tried to use stdout scanning. I tried to use script from the answer as executable
bash-3.2$ ./test.sh
rgb:2b2b/2b2b/2b2b
bash-3.2$ ./test.sh > test.log; cat test.log
bash-3.2$ 11;rgb:2b2b/2b2b/2b2b
bash-3.2$ ./test.sh > test.log; cat test.log
bash-3.2$ ./test.sh > test.log; cat test.log | grep 2b
bash-3.2$ ./test.sh | grep 2b
bash-3.2$ ./test.sh | grep rgb
bash-3.2$ cat test.log
^[]11;rgb:2b2b/2b2b/2b2b^[\bash-3.2$ 11;rgb:2b2b/2b2b/2b2b
bash-3.2$ cat test.log | grep 2b