func (m *Modal) Build() (bar.Module, Controller) {
	g := &grouper{
		modeNames: m.modeNames,
		showWhen:  map[int]int{},
		mode:      map[int]string{},
		output:    map[string]*bar.Segment{},
		resetter:  timing.NewScheduler(),
		autoReset: m.autoReset,
	}
	modules := []bar.Module{}
	for _, modeName := range m.modeNames {
		mode := m.modes[modeName]
		start := len(modules)
		g.output[modeName] = mode.output
		modules = append(modules, mode.modules...)
		for k, v := range mode.showWhen {
			g.showWhen[k+start] = v
		}
		for i := start; i < len(modules); i++ {
			g.mode[i] = modeName
		}
	}
	g.current.Store("")
	g.notifyFn, g.notifyCh = notifier.New()
	go g.autoResetWorker()
	return group.New(g, modules...), g
}
Build constructs the modal group, and returns a linked controller.
package modal  
import (
	"sync"
	"sync/atomic"
	"time"
	"barista.run/bar"
	"barista.run/base/click"
	"barista.run/base/notifier"
	"barista.run/colors"
	"barista.run/group"
	l "barista.run/logging"
	"barista.run/outputs"
	"barista.run/timing"
)
const (
	showWhenSummary int = 1 << iota
	showWhenDetail
)
type Controller interface {
	Modes() []string
	Current() string
	Activate(string)
	Toggle(string)
	Reset()
	AutoReset(time.Duration)
	SetOutput(string, *bar.Segment)
}
type grouper struct {
	current   atomic.Value  
	showWhen  map[int]int
	mode      map[int]string
	modeNames []string
	output    map[string]*bar.Segment
	autoReset time.Duration
	resetter  *timing.Scheduler
	sync.Mutex
	notifyCh <-chan struct{}
	notifyFn func()
}
type Modal struct {
	modes     map[string]*Mode
	modeNames []string
	autoReset time.Duration
}
type Mode struct {
	output   *bar.Segment
	modules  []bar.Module
	showWhen map[int]int
}
func New() *Modal {
	return &Modal{modes: map[string]*Mode{}}
}
func (m *Modal) AutoReset(interval time.Duration) *Modal {
	m.autoReset = interval
	return m
}
func (m *Modal) Mode(label string) *Mode {
	md := &Mode{
		output:   outputs.Text(label),
		showWhen: map[int]int{},
	}
	m.modeNames = append(m.modeNames, label)
	m.modes[label] = md
	return md
}
func (m *Mode) Summary(modules ...bar.Module) *Mode {
	return m.add(showWhenSummary, modules)
}
func (m *Mode) Detail(modules ...bar.Module) *Mode {
	return m.add(showWhenDetail, modules)
}
func (m *Mode) Add(modules ...bar.Module) *Mode {
	return m.add(showWhenSummary|showWhenDetail, modules)
}
func (m *Mode) add(flags int, modules []bar.Module) *Mode {
	for _, mod := range modules {
		m.showWhen[len(m.modules)] = flags
		m.modules = append(m.modules, mod)
	}
	return m
}
func (m *Mode) SetOutput(s *bar.Segment) *Mode {
	m.output = s
	return m
}