Enable ANSI compressor

With this change all ANSI output will be piped through an ANSI compressor that
eliminates redundant ANSI sequences. As such the compressor can be considered
"lossless".
This commit is contained in:
Christian Muehlhaeuser
2021-10-18 11:40:08 +02:00
committed by Christian Rocha
parent 1f12bda862
commit c29912c179
5 changed files with 15 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/muesli/ansi/compressor"
"github.com/muesli/reflow/truncate"
)
@@ -22,7 +23,7 @@ const (
// In cases where very high performance is needed the renderer can be told
// to exclude ranges of lines, allowing them to be written to directly.
type standardRenderer struct {
out io.Writer
out io.WriteCloser
buf bytes.Buffer
framerate time.Duration
ticker *time.Ticker
@@ -46,7 +47,7 @@ type standardRenderer struct {
// with os.Stdout as the first argument.
func newRenderer(out io.Writer, mtx *sync.Mutex) renderer {
return &standardRenderer{
out: out,
out: &compressor.Writer{Forward: out},
mtx: mtx,
framerate: defaultFramerate,
}
@@ -66,6 +67,7 @@ func (r *standardRenderer) stop() {
r.flush()
clearLine(r.out)
close(r.done)
r.out.Close()
}
// kill halts the renderer. The final frame will not be rendered.