Index | Files

package modal

import ""

Package modal provides a group with various "modes", each mode identified by a string key and containing multiple modules. It switches between the modes using a control similar to the workspace switcher.

When adding modules to a mode, certain modules can be marked as "summary" modules, to be displayed when no mode is active. When a mode is active, only the modules associated with it are displayed.

For example, if a modal group is constructed with the following sets, where uppercase letters indicate summary modules:

- "A" => "A0", "a1", "a2", "a3"
- "B" => "b0", "B1", "B2"
- "C" => "c0", "c1", "c2"

Then by default the modules displayed will be ["A0", "B1", "B2"]. Activating "A" will replace that with ["A0", "a1", "a2", "a3"], "B" will show ["b0", "B1", "B2"], and "C" will show ["c0", "c1", "c2"].


Package Files


type Controller Uses

type Controller interface {
    // Modes returns all the modes in this modal group.
    Modes() []string
    // Current returns the currently active mode, or an empty string if no mode
    // is active.
    Current() string
    // Activate activates the given mode.
    // Toggle toggles between the given mode and no active mode.
    // Reset clears the active mode.
    // AutoReset automatically resets the active mode after a given duration.
    // SetOutput sets the output segment for a given mode. The default output
    // is a plain text segment with the mode name.
    SetOutput(string, *bar.Segment)

Controller provides an interface to control a modal group.

type Modal struct {
    // contains filtered or unexported fields

Modal represents a partially constructed modal group. Modes and modules can only be added to a Modal before it is finalised, and can only be added to the bar after it is finalised.

func New Uses

func New() *Modal

New creates a new modal group.

func (*Modal) AutoReset Uses

func (m *Modal) AutoReset(interval time.Duration) *Modal

AutoReset automatically resets the active mode after a given duration.

func (*Modal) Build Uses

func (m *Modal) Build() (bar.Module, Controller)

Build constructs the modal group, and returns a linked controller.

func (*Modal) Mode Uses

func (m *Modal) Mode(label string) *Mode

Mode creates a new mode.

type Mode Uses

type Mode struct {
    // contains filtered or unexported fields

Mode represents a mode added to an existing modal group. It provides methods to add additional outputs and optionally set the default output.

func (*Mode) Add Uses

func (m *Mode) Add(modules *Mode

Add adds a module in both summary and detail modes. Modules added here are shown both when the current mode is active and when no mode is active. They are only hidden when a different mode is active.

func (*Mode) Detail Uses

func (m *Mode) Detail(modules *Mode

Detail adds a detail module to a mode. Modules added here are only shown when this mode is active.

func (*Mode) SetOutput Uses

func (m *Mode) SetOutput(s *bar.Segment) *Mode

SetOutput sets the output shown in the mode switcher. The default output is just the name of the mode.

func (*Mode) Summary Uses

func (m *Mode) Summary(modules *Mode

Summary adds a summary module to the mode. Summary modules are shown when the no mode is active.

Package modal imports 11 packages (graph) and is imported by 1 packages. Updated 2019-01-22. Refresh now. Tools for package owners.