Skip to content

How can you prevent ANSI escape sequences from being written to a debug file in a Bash script? #3792

Answered by junegunn
LangLangBart asked this question in Q&A
Discussion options

You must be logged in to vote

It's currently not possible. However, come to think of it, we can choose to write directly to /dev/tty instead of to stderr like so

diff --git a/src/tui/light.go b/src/tui/light.go
index 3ef8b60..4d3f58a 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -73,7 +73,7 @@ func (r *LightRenderer) csi(code string) string {
 
 func (r *LightRenderer) flush() {
 	if r.queued.Len() > 0 {
-		fmt.Fprint(os.Stderr, "\x1b[?7l\x1b[?25l"+r.queued.String()+"\x1b[?25h\x1b[?7h")
+		fmt.Fprint(r.ttyout, "\x1b[?7l\x1b[?25l"+r.queued.String()+"\x1b[?25h\x1b[?7h")
 		r.queued.Reset()
 	}
 }
@@ -88,6 +88,7 @@ type LightRenderer struct {
 	prevDownTime  time.Time
 	clicks        [][2]int
 	ttyin         *o…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@LangLangBart
Comment options

Answer selected by LangLangBart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants