-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprint.go
More file actions
41 lines (35 loc) · 821 Bytes
/
print.go
File metadata and controls
41 lines (35 loc) · 821 Bytes
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
package shandler
import (
"fmt"
"io"
"strings"
)
func printer(src []io.Writer, data ...any) {
for _, s := range src {
_, _ = fmt.Fprintln(s, data...)
}
}
func printerf(src []io.Writer, pid string, format string, data ...any) {
for _, s := range src {
if pid == "" {
_, _ = fmt.Fprintf(s, format, data...)
} else {
_, _ = fmt.Fprintf(s, "["+pid+"] "+format, data...)
}
}
}
func printerrj(src []io.Writer, g, pid, format string, data ...any) {
var left string
if pid == "" {
left = fmt.Sprintf(strings.TrimSpace(format), data...)
} else {
left = fmt.Sprintf("["+pid+"] "+strings.TrimSpace(format), data...)
}
rightWidth := width - len(left)
if rightWidth < 0 {
rightWidth = 0
}
for _, s := range src {
_, _ = fmt.Fprintf(s, "%s%*s\n", strings.TrimSpace(left), rightWidth, g)
}
}