-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe.go
More file actions
43 lines (32 loc) · 978 Bytes
/
frame.go
File metadata and controls
43 lines (32 loc) · 978 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
42
43
package errors
import (
"strings"
"github.com/yanun0323/errors/internal/colorize"
)
// frame represents a single frame in the stack trace
type frame struct {
File string `json:"file"`
Function string `json:"function"`
Line string `json:"line"`
}
func (f frame) FormatText() string {
buf := stringBuilderPool.Get().(*strings.Builder)
defer stringBuilderPool.Put(buf)
buf.Reset()
buf.Grow(len(f.File) + len(f.Line) + len(f.Function) + 4)
buf.WriteString(f.File)
buf.WriteByte(':')
buf.WriteString(f.Line)
buf.WriteString(" in ")
buf.WriteString(f.Function)
return buf.String()
}
func (f frame) FormatColorized(funcColor, fileColor string) string {
buf := stringBuilderPool.Get().(*strings.Builder)
defer stringBuilderPool.Put(buf)
buf.Reset()
buf.Grow(len(f.File) + len(f.Line) + len(f.Function) + 4)
colorize.WriteString(buf, funcColor, "[", f.Function, "] ")
colorize.WriteString(buf, fileColor, f.File+":"+f.Line)
return buf.String()
}