modal

package
v0.0.0-...-c936f35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 15

Documentation

Overview

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"].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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.
	Activate(string)
	// Toggle toggles between the given mode and no active mode.
	Toggle(string)
	// Reset clears the active mode.
	Reset()
	// AutoReset automatically resets the active mode after a given duration.
	AutoReset(time.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

func New() *Modal

New creates a new modal group.

func (*Modal) AutoReset

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

AutoReset automatically resets the active mode after a given duration.

func (*Modal) Build

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

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

func (*Modal) Mode

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

Mode creates a new mode.

type Mode

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

func (m *Mode) Add(modules ...bar.Module) *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

func (m *Mode) Detail(modules ...bar.Module) *Mode

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

func (*Mode) SetOutput

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

func (m *Mode) Summary(modules ...bar.Module) *Mode

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL