From 1d5ca110d40682a08eca54d4b7adeb5a2f0b7fd5 Mon Sep 17 00:00:00 2001 From: theimpostor Date: Sun, 20 Feb 2022 10:43:27 -0600 Subject: Buffer output and flush only if no errors --- main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 938fb84..7df77f6 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "encoding/base64" "flag" "fmt" @@ -45,14 +46,20 @@ func main() { fnames = []string{"-"} } + // Open buffered output, using default max OSC52 length as buffer size + out := bufio.NewWriterSize(os.Stdout, 1000000) + // Start OSC52 - fmt.Print("\033]52;c;") - b64 := base64.NewEncoder(base64.StdEncoding, os.Stdout) + fmt.Fprintf(out, "\033]52;c;") + + b64 := base64.NewEncoder(base64.StdEncoding, out) for _, fname := range fnames { encode(fname, b64) } b64.Close() // End OSC52 - fmt.Print("\a") + fmt.Fprintf(out, "\a") + + out.Flush() } -- cgit v1.2.3