1package main 2 3import ( 4 "fmt" 5 "strconv" 6 "text/template" 7 8 "github.com/jroimartin/gocui" 9) 10 11type StatusLine struct { 12 tpl *template.Template 13} 14 15type StatusLineFunctions struct { 16 app *App 17} 18 19func (_ *StatusLineFunctions) Version() string { 20 return VERSION 21} 22 23func (s *StatusLineFunctions) Duration() string { 24 if len(s.app.history) == 0 { 25 return "" 26 } 27 return s.app.history[s.app.historyIndex].Duration.String() 28} 29 30func (s *StatusLineFunctions) HistorySize() string { 31 return strconv.Itoa(len(s.app.history)) 32} 33 34func (s *StatusLineFunctions) RequestNumber() string { 35 i := s.app.historyIndex 36 if len(s.app.history) > 0 { 37 i += 1 38 } 39 return strconv.Itoa(i) 40} 41 42func (s *StatusLineFunctions) SearchType() string { 43 if len(s.app.history) > 0 && !s.app.history[s.app.historyIndex].Formatter.Searchable() { 44 return "none" 45 } 46 if s.app.config.General.ContextSpecificSearch { 47 return "response specific" 48 } 49 return "regex" 50} 51 52func (s *StatusLine) Update(v *gocui.View, a *App) { 53 v.Clear() 54 err := s.tpl.Execute(v, &StatusLineFunctions{app: a}) 55 if err != nil { 56 fmt.Fprintf(v, "StatusLine update error: %v", err) 57 } 58} 59 60func (s *StatusLineFunctions) DisableRedirect() string { 61 if s.app.config.General.FollowRedirects { 62 return "" 63 } 64 return "Activated" 65} 66 67func NewStatusLine(format string) (*StatusLine, error) { 68 tpl, err := template.New("status line").Parse(format) 69 if err != nil { 70 return nil, err 71 } 72 return &StatusLine{ 73 tpl: tpl, 74 }, nil 75} 76