Multicast
godocimport "barista.run/modules/meta/multicast"
Most modules can only be added once, since they maintain internal state.
Multicast provides a simple wrapper that allows multiple copies. Combined with
group.Simple()
, this can create many different
combinations of modules without needing multiple instances of any module.
Multicasting a module: multi := multicast.New(existingModule)
.
Important: The original module must NOT be added to the bar. Only the returned module can be added, although it can be added multiple times.
Example
<00:4035 deg845 MiB>
<00:40Mon, Jan 2135 deg>
Using a switching group to show different bar layouts:
// simple modules
date := clock.Local().Format("Mon, Jan 2")
mem := sysinfo.New().Output(/* free memory */)
// multicasted modules
time := multicast.New(clock.Local().Format("15:04"))
wthr := multicast.New(weather.New(/* provider */).Output(/* formatter */))
layoutA := group.Simple(time, wthr, mem)
layoutB := group.Simple(time, date, wthr)
layoutC := group.Simple(time, wthr)
grp, _ := switching.Group(layoutA, layoutB, layoutC)
barista.Run(grp)