mirror of
https://github.com/charmbracelet/lipgloss.git
synced 2024-08-17 01:40:36 +03:00
feat(renderer): add WithTermenvOutput option
This commit is contained in:
parent
4aa1f38785
commit
e5401eb8b8
@ -80,7 +80,7 @@ func main() {
|
||||
}
|
||||
w, _ := pty.Window.Width, pty.Window.Height
|
||||
|
||||
renderer := lipgloss.NewRenderer(lipgloss.WithOutput(output))
|
||||
renderer := lipgloss.NewRenderer(lipgloss.WithTermenvOutput(output))
|
||||
str := strings.Builder{}
|
||||
fmt.Fprintf(&str, "\n%s %s %s %s %s",
|
||||
renderer.NewStyle("bold").Bold(true),
|
||||
|
13
renderer.go
13
renderer.go
@ -1,6 +1,8 @@
|
||||
package lipgloss
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
@ -21,7 +23,7 @@ func DefaultRenderer() *Renderer {
|
||||
}
|
||||
|
||||
// NewRenderer creates a new Renderer.
|
||||
func NewRenderer(options ...func(r *Renderer)) *Renderer {
|
||||
func NewRenderer(options ...RendererOption) *Renderer {
|
||||
r := &Renderer{
|
||||
output: termenv.DefaultOutput(),
|
||||
}
|
||||
@ -31,8 +33,13 @@ func NewRenderer(options ...func(r *Renderer)) *Renderer {
|
||||
return r
|
||||
}
|
||||
|
||||
// WithOutput sets the termenv Output to use for rendering.
|
||||
func WithOutput(output *termenv.Output) RendererOption {
|
||||
// WithOutput sets the io.Writer to be used for rendering.
|
||||
func WithOutput(w io.Writer) RendererOption {
|
||||
return WithTermenvOutput(termenv.NewOutput(w))
|
||||
}
|
||||
|
||||
// WithTermenvOutput sets the termenv Output to use for rendering.
|
||||
func WithTermenvOutput(output *termenv.Output) RendererOption {
|
||||
return func(r *Renderer) {
|
||||
r.output = output
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func TestRendererWithOutput(t *testing.T) {
|
||||
defer f.Close()
|
||||
defer os.Remove(f.Name())
|
||||
output := termenv.NewOutput(f, termenv.WithProfile(termenv.TrueColor))
|
||||
r := NewRenderer(WithOutput(output))
|
||||
r := NewRenderer(WithTermenvOutput(output))
|
||||
if r.output.Profile != termenv.TrueColor {
|
||||
t.Error("Expected renderer to use true color")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user