Skip to content

Commit acdd17d

Browse files
committed
feat: add infixWriter for formatted output
Changes: - Introduced a new `infixWriter` struct that allows for custom prefix and suffix when writing output. - Implemented the `Write` method to format the output by applying the prefix and suffix around the written buffer each time a new line is encountered. - This new functionality aids in creating more structured output for logging or display purposes.
1 parent d7e240d commit acdd17d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

internal/infix_writer.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package internal
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
)
7+
8+
type infixWriter struct {
9+
prefix string
10+
suffix string
11+
buffer bytes.Buffer
12+
}
13+
14+
func (w *infixWriter) Write(p []byte) (int, error) {
15+
for _, b := range p {
16+
if b == '\n' {
17+
fmt.Printf("%s%s%s\n", w.prefix, w.buffer.String(), w.suffix)
18+
w.buffer.Reset()
19+
} else {
20+
w.buffer.WriteByte(b)
21+
}
22+
}
23+
24+
return len(p), nil
25+
}

0 commit comments

Comments
 (0)