-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_context.go
More file actions
62 lines (52 loc) · 1.09 KB
/
Copy patherrors_context.go
File metadata and controls
62 lines (52 loc) · 1.09 KB
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
package liberrors
import (
"fmt"
"io"
"strings"
libescapes "github.com/bbfh-dev/lib-ansi-escapes"
)
type Context struct {
FirstLine uint
Buffer string
Highlighted string
}
func (ctx Context) IsEmpty() bool {
return len(ctx.Buffer) == 0 && len(ctx.Highlighted) == 0
}
func (ctx Context) Print(writer io.Writer) {
writer.Write([]byte("\n" + libescapes.TextColorWhite))
var line_index uint
for line := range strings.SplitSeq(ctx.Buffer, "\n") {
if line_index != 0 {
writer.Write([]byte{'\n'})
}
fmt.Fprintf(
writer,
"%5d | %s",
ctx.FirstLine+line_index,
line,
)
line_index++
}
writer.Write([]byte(libescapes.TextColorBrightRed))
if len(ctx.Highlighted) == 0 {
writer.Write([]byte("←—"))
} else {
i := uint(0)
buffer := strings.TrimSuffix(ctx.Highlighted, "\n")
for line := range strings.SplitSeq(buffer, "\n") {
if i == 0 {
writer.Write([]byte(line))
} else {
fmt.Fprintf(
writer,
"\n%5d | %s",
ctx.FirstLine+line_index+i-1,
line,
)
}
i++
}
}
writer.Write([]byte(libescapes.ColorReset + "\n"))
}