blob: abfbf3d6478cd9819a8fc30119fdc8083413a7d2 (
plain) (
blame)
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
|
package writer
import (
"fmt"
"strings"
)
type Writer struct {
output strings.Builder
temp strings.Builder
}
func NewWriter() *Writer {
return &Writer{
output: strings.Builder{},
temp: strings.Builder{},
}
}
func (w *Writer) Append(str string, a ...any) {
_, err := w.output.WriteString(fmt.Sprintf(str, a...))
if err != nil {
w.output.WriteString(err.Error())
}
}
func (w *Writer) AppendLine(str string, a ...any) {
w.Append(str, a...)
w.output.WriteString("\n")
}
func (w *Writer) GetOutputString() string {
return w.output.String()
}
func (w *Writer) TempAppend(str string, a ...any) {
_, err := w.temp.WriteString(fmt.Sprintf(str, a...))
if err != nil {
w.temp.WriteString(err.Error())
}
}
func (w *Writer) TempAppendLine(str string, a ...any) {
w.TempAppend(str, a...)
w.temp.WriteString("\n")
}
func (w *Writer) TempGetString() string {
return w.temp.String()
}
func (w *Writer) AppendOutputFromTemp() {
w.output.WriteString(w.temp.String())
w.temp.Reset()
}
|