Ejemplo n.º 1
0
func showStatus(s *rest.ServiceInfo) {
	d := time.Since(s.TimeStamp)
	// for printing second resolution is sufficient
	d -= d % time.Second
	fmt.Printf("%-20s %-10s  %10s    %s\n", s.Name,
		util.Status(s), util.FormatDuration(d), s.Status)
}
Ejemplo n.º 2
0
// update is called to update content, e.g. in response to Draw() or
// as part of another update.  It is called with the AppLock held.
func (m *MainPanel) update() {

	items, err := m.app.GetItems()
	m.items = items

	// preserve selected item
	if sel := m.selected; sel != nil {
		m.selected = nil
		cury := 0
		for _, item := range m.items {
			if item.Name == sel.Name {
				m.selected = item
				m.cury = cury
			}
			cury++
		}
	}
	if err != nil {
		m.statusbar.SetFail()
		m.statusbar.SetStatus(fmt.Sprintf("Cannot load items: %v", err))
		m.lines = []string{}
		m.styles = []topsl.Style{}
		return
	}

	lines := make([]string, 0, len(m.items))
	styles := make([]topsl.Style, 0, len(m.items))

	m.ndisabled = 0
	m.nfailed = 0
	m.nstopped = 0
	m.nrunning = 0

	m.height = 0
	m.width = 0

	for _, info := range items {
		d := time.Since(info.TimeStamp)
		d -= d % time.Second
		line := fmt.Sprintf("%-20s %-10s %10s   %-10s",
			info.Name, util.Status(info), util.FormatDuration(d),
			info.Status)

		if len(line) > m.width {
			m.width = len(line)
		}
		m.height++

		lines = append(lines, line)
		var style topsl.Style
		if !info.Enabled {
			style = topsl.StyleText
			m.ndisabled++
		} else if info.Failed {
			style = topsl.StyleError
			m.nfailed++
		} else if !info.Running {
			style = topsl.StyleWarn
			m.nstopped++
		} else {
			style = topsl.StyleGood
			m.nrunning++
		}
		styles = append(styles, style)
	}

	m.lines = lines
	m.styles = styles

	m.statusbar.SetStatus(fmt.Sprintf(
		"%6d Services %6d Faulted %6d Running %6d Standby %6d Disabled",
		len(m.items),
		m.nfailed, m.nrunning, m.nstopped, m.ndisabled))

	if m.nfailed > 0 {
		m.statusbar.SetFail()
	} else if m.nstopped > 0 {
		m.statusbar.SetWarn()
	} else if m.nrunning > 0 {
		m.statusbar.SetGood()
	} else {
		m.statusbar.SetNormal()
	}

	words := []string{"[Q] Quit", "[H] Help"}

	if item := m.selected; item != nil {
		words = append(words, "[I] Info")
		words = append(words, "[L] Log")
		if !item.Enabled {
			words = append(words, "[E] Enable")
		} else {
			words = append(words, "[D] Disable")
			if item.Failed {
				words = append(words, "[C] Clear")
			}
			words = append(words, "[R] Restart")
		}
	} else {
		words = append(words, "[L] Log")
	}
	m.keybar.SetKeys(words)
}