Add ansi.StyleWriter, which wrap writer's output into a style

This commit is contained in:
Christian Muehlhaeuser
2019-12-16 20:06:18 +01:00
parent 386525047d
commit 300a999be5
+28
View File
@@ -0,0 +1,28 @@
package ansi
import (
"bytes"
"io"
)
type StyleWriter struct {
w io.Writer
buf bytes.Buffer
rules StylePrimitive
}
func NewStyleWriter(ctx RenderContext, w io.Writer, rules StylePrimitive) *StyleWriter {
return &StyleWriter{
w: w,
rules: rules,
}
}
func (w *StyleWriter) Write(b []byte) (int, error) {
return w.buf.Write(b)
}
func (w *StyleWriter) Close() error {
renderText(w.w, w.rules, w.buf.String())
return nil
}