Beispiel #1
0
func (b *Battery) Generate() (out []i3.Output, err error) {
	err = b.update()
	if err != nil {
		return
	}

	o := i3.Output{Separator: true}
	out = make([]i3.Output, 1)
	defer func() {
		out[0] = o
	}()

	if !b.Present {
		o.FullText = fmt.Sprintf("Battery %v not present", b.Identifier)
		o.Color = "#FF0000"
		return
	}

	text := fmt.Sprintf("%v %v %v%% %v", b.Name, b.Status, b.Level, b.Remaining)
	switch {
	case !b.Present || b.Level < 15:
		o.Color = "#FF0000"
	case b.Status == "Charging" || b.Status == "Full" || b.Status == "Discharging" && b.Level >= 35:
		o.Color = "#00FF00"
	default:
		o.Color = "#FFA500"
	}

	o.FullText = text

	return
}
Beispiel #2
0
// Generate implements Generator
func (b *Battery) Generate() (out []i3.Output, err error) {
	err = b.update()
	if err != nil {
		return
	}

	o := i3.Output{
		Name:      b.Name,
		Instance:  b.Identifier,
		Separator: true,
	}

	out = make([]i3.Output, 1)
	defer func() {
		out[0] = o
	}()

	if !b.present {
		o.FullText = fmt.Sprintf("Battery %v not present", b.Identifier)
		o.Color = i3.DefaultColors.Crit
		return
	}

	var remain interface{}
	switch b.remaining {
	case time.Duration(0):
		remain = "N/A"
	default:
		remain = b.remaining
	}

	text := fmt.Sprintf("%v %v %v%% %v", b.Name, b.status, b.level, remain)
	switch {
	case b.Crit():
		o.Color = i3.DefaultColors.Crit
	case b.Warn():
		o.Color = i3.DefaultColors.Warn
	default:
		o.Color = i3.DefaultColors.OK
	}

	o.FullText = text

	return
}