-
Notifications
You must be signed in to change notification settings - Fork 412
/
status-line.go
75 lines (63 loc) · 1.42 KB
/
status-line.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"strconv"
"text/template"
"github.com/jroimartin/gocui"
)
type StatusLine struct {
tpl *template.Template
}
type StatusLineFunctions struct {
app *App
}
func (_ *StatusLineFunctions) Version() string {
return VERSION
}
func (s *StatusLineFunctions) Duration() string {
if len(s.app.history) == 0 {
return ""
}
return s.app.history[s.app.historyIndex].Duration.String()
}
func (s *StatusLineFunctions) HistorySize() string {
return strconv.Itoa(len(s.app.history))
}
func (s *StatusLineFunctions) RequestNumber() string {
i := s.app.historyIndex
if len(s.app.history) > 0 {
i += 1
}
return strconv.Itoa(i)
}
func (s *StatusLineFunctions) SearchType() string {
if len(s.app.history) > 0 && !s.app.history[s.app.historyIndex].Formatter.Searchable() {
return "none"
}
if s.app.config.General.ContextSpecificSearch {
return "response specific"
}
return "regex"
}
func (s *StatusLine) Update(v *gocui.View, a *App) {
v.Clear()
err := s.tpl.Execute(v, &StatusLineFunctions{app: a})
if err != nil {
fmt.Fprintf(v, "StatusLine update error: %v", err)
}
}
func (s *StatusLineFunctions) DisableRedirect() string {
if s.app.config.General.FollowRedirects {
return ""
}
return "Activated"
}
func NewStatusLine(format string) (*StatusLine, error) {
tpl, err := template.New("status line").Parse(format)
if err != nil {
return nil, err
}
return &StatusLine{
tpl: tpl,
}, nil
}