The Barista Logo

barista

An i3status alternative in golang

Download sample-bar Download i3status example View on GitHub

group/Modal

godoc
import "barista.run/group/modal"

Create a group that switches between several different “modes”.

Start with a new modal: builder := modal.New().

Add new modes, optionally specifying a segment to use in the switcher, and add modules to it:

builder.Mode("mode-name").Output(bar.TextSegment("MN")).
	Add(moduleShownWhenInactiveOrActive).
	Summary(moduleShownOnlyWhenInactive).
	Detail(moduleShownOnlyWhenActive)

Once all the modes are set up, build the modal group and get a controller: barModule, ctrl := builder.Build().

The returned bar.Module will display modules according to the active mode (none on start), and will display a “switcher” at the end of the group. The switcher will show a segment for each mode, using a text segment with the mode’s name if not specified explicitly. Clicking on an inactive mode will switch to it, clicking on the active mode will revert to the “summary” mode (no active mode).

In summary mode, only the summary modules from each mode are displayed. When a mode is active, modules from all other modes are hidden, and all detail modules from the active mode are visible.

Modules added using Add are shown both in summary and detail modes.

Example

d0A B %
c0c1c2A B %
b0B2A B %
A0a1a2a3A B %
A0B1B2A B %

Setting up some modes, and switching between them by using the mode switcher:

// For simplicity, assuming mod("a") returns a static module that outputs 'a'.

builder := modal.New()
builder.Mode("A").Add(mod("A0")).Detail(mod("a1"), mod("a2"), mod("a3"))
builder.Mode("B").Detail(mod("b0")).Summary(mod("B1")).Add(mod("B2"))
builder.Mode("C").Detail(mod("c0"), mod("c1"), mod("c2")).Output(bar.TextSegment("%"))
builder.Mode("D").Detail(mod("d0")).Output(nil)

grp, ctrl := builder.Build()
barista.Run(grp)