-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.go
68 lines (60 loc) · 1.54 KB
/
output.go
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
package main
import (
"fmt"
"io"
"os"
"github.com/charmbracelet/lipgloss"
)
type CommandOutput interface {
io.Writer
StylePrint(style lipgloss.Style, a ...any)
StylePrintln(style lipgloss.Style, a ...any)
StylePrintf(style lipgloss.Style, format string, a ...any)
Print(a ...any)
Println(a ...any)
Printf(format string, a ...any)
Error(a ...any)
Errorln(a ...any)
Errorf(format string, a ...any)
}
type commandStdout struct{}
func (out *commandStdout) Write(data []byte) (int, error) {
return os.Stdout.Write(data)
}
func (out *commandStdout) StylePrint(style lipgloss.Style, a ...any) {
var ss []any
for _, s := range a {
ss = append(ss, style.Render(fmt.Sprint(s)))
}
fmt.Fprint(os.Stdout, ss...)
}
func (out *commandStdout) StylePrintln(style lipgloss.Style, a ...any) {
var ss []any
for _, s := range a {
ss = append(ss, style.Render(fmt.Sprint(s)))
}
fmt.Fprintln(os.Stdout, ss...)
}
func (out *commandStdout) StylePrintf(style lipgloss.Style, format string, a ...any) {
s := fmt.Sprintf(format, a...)
rendered := style.Render(s)
fmt.Fprint(os.Stdout, rendered)
}
func (out *commandStdout) Print(a ...any) {
fmt.Print(a...)
}
func (out *commandStdout) Println(a ...any) {
fmt.Println(a...)
}
func (out *commandStdout) Printf(format string, a ...any) {
fmt.Printf(format, a...)
}
func (out *commandStdout) Error(a ...any) {
fmt.Fprint(os.Stderr, a...)
}
func (out *commandStdout) Errorln(a ...any) {
fmt.Fprintln(os.Stderr, a...)
}
func (out *commandStdout) Errorf(format string, a ...any) {
fmt.Fprintf(os.Stderr, format, a...)
}