mirror of
https://github.com/divan/expvarmon.git
synced 2025-05-10 19:29:17 +08:00
Added pars to ui_single
This commit is contained in:
parent
44d77e4df4
commit
d6ccd1cc61
36
ui_single.go
36
ui_single.go
@ -13,6 +13,7 @@ type TermUISingle struct {
|
|||||||
Status *termui.Par
|
Status *termui.Par
|
||||||
Sparklines map[VarName]*termui.Sparkline
|
Sparklines map[VarName]*termui.Sparkline
|
||||||
Sparkline *termui.Sparklines
|
Sparkline *termui.Sparklines
|
||||||
|
Pars []*termui.Par
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init creates widgets, sets sizes and labels.
|
// Init creates widgets, sets sizes and labels.
|
||||||
@ -43,6 +44,16 @@ func (t *TermUISingle) Init(data UIData) error {
|
|||||||
return p
|
return p
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
t.Pars = make([]*termui.Par, len(data.Vars))
|
||||||
|
for i, name := range data.Vars {
|
||||||
|
par := termui.NewPar("")
|
||||||
|
par.TextFgColor = colorByKind(name.Kind())
|
||||||
|
par.Border.Label = name.Short()
|
||||||
|
par.Border.LabelFgColor = termui.ColorGreen
|
||||||
|
par.Height = 3
|
||||||
|
t.Pars[i] = par
|
||||||
|
}
|
||||||
|
|
||||||
var sparklines []termui.Sparkline
|
var sparklines []termui.Sparkline
|
||||||
for _, name := range data.Vars {
|
for _, name := range data.Vars {
|
||||||
spl := termui.NewSparkline()
|
spl := termui.NewSparkline()
|
||||||
@ -74,6 +85,11 @@ func (t *TermUISingle) Update(data UIData) {
|
|||||||
t.Title.Text = fmt.Sprintf("monitoring %s every %v, press q to quit", service.Name, *interval)
|
t.Title.Text = fmt.Sprintf("monitoring %s every %v, press q to quit", service.Name, *interval)
|
||||||
t.Status.Text = fmt.Sprintf("Last update: %v", data.LastTimestamp.Format(time.Stamp))
|
t.Status.Text = fmt.Sprintf("Last update: %v", data.LastTimestamp.Format(time.Stamp))
|
||||||
|
|
||||||
|
// Pars
|
||||||
|
for i, name := range data.Vars {
|
||||||
|
t.Pars[i].Text = service.Value(name)
|
||||||
|
}
|
||||||
|
|
||||||
// Sparklines
|
// Sparklines
|
||||||
for i, name := range data.Vars {
|
for i, name := range data.Vars {
|
||||||
spl := &t.Sparkline.Lines[i]
|
spl := &t.Sparkline.Lines[i]
|
||||||
@ -93,6 +109,9 @@ func (t *TermUISingle) Update(data UIData) {
|
|||||||
|
|
||||||
var widgets []termui.Bufferer
|
var widgets []termui.Bufferer
|
||||||
widgets = append(widgets, t.Title, t.Status, t.Sparkline)
|
widgets = append(widgets, t.Title, t.Status, t.Sparkline)
|
||||||
|
for _, par := range t.Pars {
|
||||||
|
widgets = append(widgets, par)
|
||||||
|
}
|
||||||
termui.Render(widgets...)
|
termui.Render(widgets...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +137,22 @@ func (t *TermUISingle) Relayout() {
|
|||||||
t.Status.X = t.Title.X + t.Title.Width
|
t.Status.X = t.Title.X + t.Title.Width
|
||||||
h -= firstRowH
|
h -= firstRowH
|
||||||
|
|
||||||
// Second row: Sparklines
|
// Second row: lists
|
||||||
|
secondRowH := 3
|
||||||
|
num := len(t.Pars)
|
||||||
|
parW := tw / num
|
||||||
|
for i, par := range t.Pars {
|
||||||
|
par.Y = th - h
|
||||||
|
par.Width = parW
|
||||||
|
par.Height = secondRowH
|
||||||
|
par.X = i * parW
|
||||||
|
}
|
||||||
|
if num*parW < tw {
|
||||||
|
t.Pars[num-1].Width = tw - ((num - 1) * parW)
|
||||||
|
}
|
||||||
|
h -= secondRowH
|
||||||
|
|
||||||
|
// Third row: Sparklines
|
||||||
t.Sparkline.Width = tw
|
t.Sparkline.Width = tw
|
||||||
t.Sparkline.Height = h
|
t.Sparkline.Height = h
|
||||||
t.Sparkline.Y = th - h
|
t.Sparkline.Y = th - h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user