aboutsummaryrefslogtreecommitdiff
path: root/pkg/writer/writer.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/writer/writer.go')
-rw-r--r--pkg/writer/writer.go50
1 files changed, 29 insertions, 21 deletions
diff --git a/pkg/writer/writer.go b/pkg/writer/writer.go
index f3af2fc..abfbf3d 100644
--- a/pkg/writer/writer.go
+++ b/pkg/writer/writer.go
@@ -5,43 +5,51 @@ import (
5 "strings" 5 "strings"
6) 6)
7 7
8var output strings.Builder 8type Writer struct {
9 output strings.Builder
10 temp strings.Builder
11}
9 12
10var temp strings.Builder 13func NewWriter() *Writer {
14 return &Writer{
15 output: strings.Builder{},
16 temp: strings.Builder{},
17 }
18}
11 19
12func Append(str string, a ...any) { 20func (w *Writer) Append(str string, a ...any) {
13 _, err := output.WriteString(fmt.Sprintf(str, a...)) 21 _, err := w.output.WriteString(fmt.Sprintf(str, a...))
14 if err != nil { 22 if err != nil {
15 output.WriteString(err.Error()) 23 w.output.WriteString(err.Error())
16 } 24 }
17} 25}
18 26
19func AppendLine(str string, a ...any) { 27func (w *Writer) AppendLine(str string, a ...any) {
20 Append(str, a...) 28 w.Append(str, a...)
21 output.WriteString("\n") 29 w.output.WriteString("\n")
22} 30}
23 31
24func GetWriter() strings.Builder { 32func (w *Writer) GetOutputString() string {
25 return output 33 return w.output.String()
26} 34}
27 35
28func TempAppend(str string, a ...any) { 36func (w *Writer) TempAppend(str string, a ...any) {
29 _, err := temp.WriteString(fmt.Sprintf(str, a...)) 37 _, err := w.temp.WriteString(fmt.Sprintf(str, a...))
30 if err != nil { 38 if err != nil {
31 temp.WriteString(err.Error()) 39 w.temp.WriteString(err.Error())
32 } 40 }
33} 41}
34 42
35func TempAppendLine(str string, a ...any) { 43func (w *Writer) TempAppendLine(str string, a ...any) {
36 TempAppend(str, a...) 44 w.TempAppend(str, a...)
37 temp.WriteString("\n") 45 w.temp.WriteString("\n")
38} 46}
39 47
40func TempGetString() string { 48func (w *Writer) TempGetString() string {
41 return temp.String() 49 return w.temp.String()
42} 50}
43 51
44func AppendOutputFromTemp() { 52func (w *Writer) AppendOutputFromTemp() {
45 output.WriteString(temp.String()) 53 w.output.WriteString(w.temp.String())
46 temp.Reset() 54 w.temp.Reset()
47} 55}