// Init creates widgets, sets sizes and labels. func (t *TermUI) Init(data UIData) error { err := termui.Init() if err != nil { return err } termui.UseTheme("helloworld") theme := termui.Theme() theme.BodyBg = termui.ColorDefault theme.BlockBg = termui.ColorDefault theme.BorderBg = termui.ColorDefault theme.BorderFg = termui.ColorBlack theme.BorderLabelTextBg = termui.ColorDefault theme.BorderLabelTextFg = termui.ColorCyan theme.ListItemBg = termui.ColorDefault theme.ParTextBg = termui.ColorDefault termui.SetTheme(theme) t.Title = func() *termui.Par { p := termui.NewPar("") p.Height = 3 p.TextFgColor = termui.ColorWhite p.Border.Label = "Services Monitor" p.Border.FgColor = termui.ColorBlack return p }() t.Status = func() *termui.Par { p := termui.NewPar("") p.Height = 3 p.TextFgColor = termui.ColorWhite p.Border.Label = "Status" p.Border.LabelFgColor = termui.ColorCyan p.Border.FgColor = termui.ColorBlack return p }() t.Services = func() *termui.List { list := termui.NewList() list.ItemFgColor = termui.ColorYellow list.Border.LabelFgColor = termui.ColorCyan | termui.AttrBold list.Border.Label = "Services" list.Height = len(data.Services) + 2 return list }() t.Lists = make([]*termui.List, len(data.Vars)) for i, name := range data.Vars { list := termui.NewList() list.ItemFgColor = colorByKind(name.Kind()) list.Border.Label = name.Short() list.Border.LabelFgColor = termui.ColorCyan list.Height = len(data.Services) + 2 t.Lists[i] = list } makeSparkline := func(name VarName) *termui.Sparklines { var sparklines []termui.Sparkline for _, service := range data.Services { spl := termui.NewSparkline() spl.Height = 1 spl.TitleColor = termui.ColorGreen spl.LineColor = termui.ColorGreen spl.Title = service.Name sparklines = append(sparklines, spl) } s := termui.NewSparklines(sparklines...) s.Height = 2*len(data.Services) + 2 s.HasBorder = true s.Border.Label = fmt.Sprintf("Monitoring %s", name.Long()) return s } t.Sparkline1 = makeSparkline(data.Vars[0]) if len(data.Vars) > 1 { t.Sparkline2 = makeSparkline(data.Vars[1]) } t.Relayout() return nil }
// Init creates widgets, sets sizes and labels. func (t *TermUISingle) Init(data UIData) error { err := termui.Init() if err != nil { return err } t.Sparklines = make(map[VarName]*termui.Sparkline) termui.UseTheme("helloworld") theme := termui.Theme() theme.BodyBg = termui.ColorDefault theme.BlockBg = termui.ColorDefault theme.BorderBg = termui.ColorDefault theme.BorderFg = termui.ColorBlack theme.BorderLabelTextBg = termui.ColorDefault theme.BorderLabelTextFg = termui.ColorCyan theme.ListItemBg = termui.ColorDefault theme.ParTextBg = termui.ColorDefault termui.SetTheme(theme) t.Title = func() *termui.Par { p := termui.NewPar("") p.Height = 3 p.BgColor = termui.ColorDefault p.TextBgColor = termui.ColorDefault p.TextFgColor = termui.ColorWhite p.Border.Label = "Services Monitor" p.Border.LabelBgColor = termui.ColorDefault p.Border.LabelFgColor = termui.ColorCyan p.Border.FgColor = termui.ColorBlack p.Border.BgColor = termui.ColorDefault return p }() t.Status = func() *termui.Par { p := termui.NewPar("") p.Height = 3 p.BgColor = termui.ColorDefault p.TextBgColor = termui.ColorDefault p.TextFgColor = termui.ColorWhite p.Border.Label = "Status" p.Border.LabelBgColor = termui.ColorDefault p.Border.LabelFgColor = termui.ColorCyan p.Border.FgColor = termui.ColorBlack p.Border.BgColor = termui.ColorDefault return p }() t.Pars = make([]*termui.Par, len(data.Vars)) for i, name := range data.Vars { par := termui.NewPar("") par.BgColor = termui.ColorDefault par.TextFgColor = colorByKind(name.Kind()) par.TextBgColor = termui.ColorDefault par.Border.FgColor = termui.ColorBlack par.Border.BgColor = termui.ColorDefault par.Border.Label = name.Short() par.Border.LabelFgColor = termui.ColorCyan par.Border.LabelBgColor = termui.ColorDefault par.Height = 3 t.Pars[i] = par } var sparklines []termui.Sparkline for _, name := range data.Vars { spl := termui.NewSparkline() spl.Height = 1 spl.TitleColor = colorByKind(name.Kind()) spl.LineColor = colorByKind(name.Kind()) spl.Title = name.Long() sparklines = append(sparklines, spl) } t.Sparkline = func() *termui.Sparklines { s := termui.NewSparklines(sparklines...) s.Height = 2*len(sparklines) + 2 s.HasBorder = true s.BgColor = termui.ColorDefault s.Border.FgColor = termui.ColorBlack s.Border.BgColor = termui.ColorDefault s.Border.Label = fmt.Sprintf("Monitoring") s.Border.LabelFgColor = termui.ColorCyan s.Border.LabelBgColor = termui.ColorDefault return s }() t.Relayout() return nil }