@@ -2,11 +2,12 @@ package lipgloss
2
2
3
3
import (
4
4
"io"
5
+ "os"
5
6
6
7
"github.com/muesli/termenv"
7
8
)
8
9
9
- var renderer = NewRenderer ()
10
+ var renderer = NewRenderer (os . Stdout )
10
11
11
12
// Renderer is a lipgloss terminal renderer.
12
13
type Renderer struct {
@@ -22,43 +23,29 @@ func DefaultRenderer() *Renderer {
22
23
return renderer
23
24
}
24
25
26
+ // SetDefaultRenderer sets the default global renderer.
27
+ func SetDefaultRenderer (r * Renderer ) {
28
+ renderer = r
29
+ }
30
+
25
31
// NewRenderer creates a new Renderer.
26
- func NewRenderer (options ... RendererOption ) * Renderer {
32
+ //
33
+ // w will be used to determine the terminal's color capabilities.
34
+ func NewRenderer (w io.Writer , opts ... termenv.OutputOption ) * Renderer {
27
35
r := & Renderer {
28
- output : termenv .DefaultOutput (),
29
- }
30
- for _ , option := range options {
31
- option (r )
36
+ output : termenv .NewOutput (w , opts ... ),
32
37
}
33
38
return r
34
39
}
35
40
36
- // WithOutput sets the io.Writer to be used for rendering .
37
- func WithOutput ( w io. Writer ) RendererOption {
38
- return WithTermenvOutput ( termenv . NewOutput ( w ))
41
+ // Output returns the termenv output .
42
+ func ( r * Renderer ) Output () * termenv. Output {
43
+ return r . output
39
44
}
40
45
41
- // WithTermenvOutput sets the termenv Output to use for rendering.
42
- func WithTermenvOutput (output * termenv.Output ) RendererOption {
43
- return func (r * Renderer ) {
44
- r .output = output
45
- }
46
- }
47
-
48
- // WithDarkBackground can force the renderer to use a light/dark background.
49
- func WithDarkBackground (dark bool ) RendererOption {
50
- return func (r * Renderer ) {
51
- r .SetHasDarkBackground (dark )
52
- }
53
- }
54
-
55
- // WithColorProfile sets the color profile on the renderer. This function is
56
- // primarily intended for testing. For details, see the note on
57
- // [Renderer.SetColorProfile].
58
- func WithColorProfile (p termenv.Profile ) RendererOption {
59
- return func (r * Renderer ) {
60
- r .SetColorProfile (p )
61
- }
46
+ // SetOutput sets the termenv output.
47
+ func (r * Renderer ) SetOutput (o * termenv.Output ) {
48
+ r .output = o
62
49
}
63
50
64
51
// ColorProfile returns the detected termenv color profile.
0 commit comments