-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy pathwriter.go
More file actions
160 lines (148 loc) Β· 3.89 KB
/
writer.go
File metadata and controls
160 lines (148 loc) Β· 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package lipgloss
import (
"bytes"
"fmt"
"io"
"os"
"github.com/charmbracelet/colorprofile"
)
// Writer is the default writer that prints to stdout, automatically
// downsampling colors when necessary.
var Writer = colorprofile.NewWriter(os.Stdout, os.Environ())
// Println to stdout, automatically downsampling colors when necessary, ending
// with a trailing newline.
//
// Example:
//
// str := NewStyle().
// Foreground(lipgloss.Color("#6a00ff")).
// Render("breakfast")
//
// Println("Time for a", str, "sandwich!")
func Println(v ...any) (int, error) {
return fmt.Fprintln(Writer, v...) //nolint:wrapcheck
}
// Printf prints formatted text to stdout, automatically downsampling colors
// when necessary.
//
// Example:
//
// str := NewStyle().
// Foreground(lipgloss.Color("#6a00ff")).
// Render("knuckle")
//
// Printf("Time for a %s sandwich!\n", str)
func Printf(format string, v ...any) (int, error) {
return fmt.Fprintf(Writer, format, v...) //nolint:wrapcheck
}
// Print to stdout, automatically downsampling colors when necessary.
//
// Example:
//
// str := NewStyle().
// Foreground(lipgloss.Color("#6a00ff")).
// Render("Who wants marmalade?\n")
//
// Print(str)
func Print(v ...any) (int, error) {
return fmt.Fprint(Writer, v...) //nolint:wrapcheck
}
// Fprint pritnts to the given writer, automatically downsampling colors when
// necessary.
//
// Example:
//
// str := NewStyle().
// Foreground(lipgloss.Color("#6a00ff")).
// Render("guzzle")
//
// Fprint(os.Stderr, "I %s horchata pretty much all the time.\n", str)
func Fprint(w io.Writer, v ...any) (int, error) {
return fmt.Fprint(colorprofile.NewWriter(w, os.Environ()), v...) //nolint:wrapcheck
}
// Fprintln prints to the given writer, automatically downsampling colors when
// necessary, and ending with a trailing newline.
//
// Example:
//
// str := NewStyle().
// Foreground(lipgloss.Color("#6a00ff")).
// Render("Sandwich time!")
//
// Fprintln(os.Stderr, str)
func Fprintln(w io.Writer, v ...any) (int, error) {
return fmt.Fprintln(colorprofile.NewWriter(w, os.Environ()), v...) //nolint:wrapcheck
}
// Fprintf prints text to a writer, against the given format, automatically
// downsampling colors when necessary.
//
// Example:
//
// str := NewStyle().
// Foreground(lipgloss.Color("#6a00ff")).
// Render("artichokes")
//
// Fprintf(os.Stderr, "I really love %s!\n", food)
func Fprintf(w io.Writer, format string, v ...any) (int, error) {
return fmt.Fprintf(colorprofile.NewWriter(w, os.Environ()), format, v...) //nolint:wrapcheck
}
// Sprint returns a string for stdout, automatically downsampling colors when
// necessary.
//
// Example:
//
// str := NewStyle().
// Faint(true).
// Foreground(lipgloss.Color("#6a00ff")).
// Render("I love to eat")
//
// str = Sprint(str)
func Sprint(v ...any) string {
var buf bytes.Buffer
w := colorprofile.Writer{
Forward: &buf,
Profile: Writer.Profile,
}
fmt.Fprint(&w, v...) //nolint:errcheck
return buf.String()
}
// Sprintln returns a string for stdout, automatically downsampling colors when
// necessary, and ending with a trailing newline.
//
// Example:
//
// str := NewStyle().
// Bold(true).
// Foreground(lipgloss.Color("#6a00ff")).
// Render("Yummy!")
//
// str = Sprintln(str)
func Sprintln(v ...any) string {
var buf bytes.Buffer
w := colorprofile.Writer{
Forward: &buf,
Profile: Writer.Profile,
}
fmt.Fprintln(&w, v...) //nolint:errcheck
return buf.String()
}
// Sprintf returns a formatted string for stdout, automatically downsampling
// colors when necessary.
//
// Example:
//
// str := NewStyle().
// Bold(true).
// Foreground(lipgloss.Color("#fccaee")).
// Render("Cantaloupe")
//
// str = Sprintf("I really love %s!", str)
func Sprintf(format string, v ...any) string {
var buf bytes.Buffer
w := colorprofile.Writer{
Forward: &buf,
Profile: Writer.Profile,
}
fmt.Fprintf(&w, format, v...) //nolint:errcheck
return buf.String()
}