2017-03-04 02:18:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-03-07 00:09:25 +00:00
|
|
|
"strconv"
|
2017-03-04 02:18:48 +00:00
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StatusLine struct {
|
|
|
|
tpl *template.Template
|
|
|
|
}
|
|
|
|
|
|
|
|
type StatusLineFunctions struct {
|
2017-03-04 03:13:53 +00:00
|
|
|
app *App
|
2017-03-04 02:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *StatusLineFunctions) Version() string {
|
|
|
|
return VERSION
|
|
|
|
}
|
|
|
|
|
2017-03-04 03:13:53 +00:00
|
|
|
func (s *StatusLineFunctions) Duration() string {
|
|
|
|
if len(s.app.history) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return s.app.history[s.app.historyIndex].Duration.String()
|
|
|
|
}
|
|
|
|
|
2017-03-07 00:09:25 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-03-04 03:13:53 +00:00
|
|
|
func (s *StatusLine) Update(v *gocui.View, a *App) {
|
2017-03-04 02:18:48 +00:00
|
|
|
v.Clear()
|
2017-03-04 03:13:53 +00:00
|
|
|
err := s.tpl.Execute(v, &StatusLineFunctions{app: a})
|
2017-03-04 02:18:48 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(v, "StatusLine update error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|