Ejemplo n.º 1
0
func main() {
	cpu := cpu.Cpu{}
	cpuProd := &i3.BaseProducer{
		Generator: cpu,
		Interval:  5 * time.Second,
		Name:      "cpu",
	}
	mem := memory.Memory{}
	batteries := make(map[string]i3.Generator, 2)
	batteries["bat1"] = &battery.Battery{
		Name:       "ext bat",
		Identifier: "BAT1",
	}

	memProd := &i3.BaseProducer{
		Generator: mem,
		Interval:  5 * time.Second,
		Name:      "mem",
	}

	batteries["bat0"] = &battery.Battery{
		Name:       "int bat",
		Identifier: "BAT0",
	}

	batteryOrder := []string{"bat0", "bat1"}

	// bats := battery.NewMultiBattery(batteries, batteryOrder)
	batGen := i3.NewOrderedMultiGenerator(batteries, batteryOrder)

	batProd := &i3.BaseProducer{
		Generator: batGen,
		Interval:  5 * time.Second,
		Name:      "bat",
	}

	clockGen := clock.NewClock("%a %d-%b-%y %I:%M:%S")

	clockProd := &i3.BaseProducer{
		Generator: clockGen,
		Interval:  1 * time.Second,
		Name:      "time",
	}

	bar := i3.NewI3bar(1 * time.Second)

	bar.Register("time", clockProd)
	bar.Register("bat", batProd)
	bar.Register("mem", memProd)
	bar.Register("cpu", cpuProd)

	bar.Order([]string{"cpu", "mem", "bat", "time"})

	bar.Start()
	defer bar.Kill()

	select {}
}
Ejemplo n.º 2
0
// Discovers batteries on your machine, and returns an OrderedMultiGenerator for each.
// Include a map of lowercase interface names to friendly names to display the
// batteries with friendly names.
func BatteryDiscover(names map[string]string, WarnThreshold, CritThreshold int) (i3.Generator, error) {
	interfaces, err := findBatteries()
	if err != nil {
		return nil, err
	}

	// Show a useful message if no batteries were found
	if len(interfaces) == 0 {
		return i3.StaticGenerator(
			[]i3.Output{{
				FullText:  "No battery found",
				Separator: true,
				Color:     "#FF0000",
			}},
		), nil
	}

	batteries := make(map[string]i3.Generator, len(interfaces))
	order := make([]string, len(interfaces))

	for i, in := range interfaces {
		var name string
		if n, ok := names[in]; ok {
			name = n
		} else {
			name = in
		}

		batteries[name] = &Battery{
			Name:       "MultiBattery",
			Identifier: in,

			WarnThreshold: WarnThreshold,
			CritThreshold: CritThreshold,
		}

		order[i] = name
	}

	sort.Strings(order)

	gen := i3.NewOrderedMultiGenerator(batteries, order)

	return gen, nil
}