mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-03 07:27:19 -04:00
Add ansi.StyleWriter, which wrap writer's output into a style
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user