ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Primary   = lipgloss.Color("207")
	Secondary = lipgloss.Color("135")

	Red      = lipgloss.Color("203")
	Blue     = lipgloss.Color("039")
	Green    = lipgloss.Color("040")
	Yellow   = lipgloss.Color("214")
	White    = lipgloss.Color("231")
	DarkGray = lipgloss.Color("237")
	Black    = lipgloss.Color("016")
)
View Source
const PoggersAnimationInterval = 80 * time.Millisecond

Designed rendering rate of the PoggersAnimationFrame animation.

Variables

View Source
	`   __             _ `,
	`  / /________  __(_)`,
	` / __/ ___/ / / / / `,
	`/ /_(__  ) /_/ / /  `,
	`\__/____/\__,_/_/   `,
	`    by neuralink    `,
}, "\n")

Functions

func FormatBytes

func FormatBytes(bytes int64) string

Formate a byte count to a human-friendly string.

func FormatDuration

func FormatDuration(duration time.Duration) string

Format a Duration to a human-friendly string.

func PoggersAnimationFrame

func PoggersAnimationFrame(t int) string

Render a frame of the cool loading animation I designed.

func RenderSplit

func RenderSplit(left string, right string, width int, style lipgloss.Style) string

Combine a left-aligned and a right-aligned string into one fixed-width line. Takes a style which is used for formatting the left-side padding, in case a uniform background is required.

Types

type Appmenu

type Appmenu struct {
	// contains filtered or unexported fields
}

A state container for the main application menu. Each menu item contains a submenu which can be opened and closed.

func (*Appmenu) Activate

func (appmenu *Appmenu) Activate() tea.Cmd

If a submenu is open, activate the item in the submenu. Otherwise, open the currently selected submenu.

func (*Appmenu) CloseSubmenu

func (appmenu *Appmenu) CloseSubmenu()

Close the submenu.

func (*Appmenu) CursorDown

func (appmenu *Appmenu) CursorDown()

Move the cursor to the next selectable item in the currently active menu.

func (*Appmenu) CursorUp

func (appmenu *Appmenu) CursorUp()

Move the cursor to the previous selectable item in the currently active menu.

func (*Appmenu) IsSubmenuOpen

func (appmenu *Appmenu) IsSubmenuOpen() bool

Returns true if a submenu is currently open.

func (*Appmenu) Render

func (appmenu *Appmenu) Render(height int) string

Render the menu to a string.

func (*Appmenu) SetItems

func (appmenu *Appmenu) SetItems(items []*AppmenuItem)

Set the items list and ensure the cursor is within bounds.

type AppmenuItem

type AppmenuItem struct {
	// The text to be displayed for this menu item.
	Label string
	// An extra label shown on the right side. Will be shown in a muted color.
	AdditionalLabel string
	// Submenu that this item reveals.
	Submenu Submenu
}

An item in the main menu, containing a submenu.

type ComputedSubmenuItem added in v0.2.0

type ComputedSubmenuItem struct {
	// contains filtered or unexported fields
}

A rendered submenu item and its computed layout info.

type DividerSubmenuItem

type DividerSubmenuItem struct{}

A divider in a menu.

type LabeledSubmenuItem

type LabeledSubmenuItem struct {
	// The text to be displayed for this menu item.
	Label string
	// An extra label shown on the right side. Will be shown in a muted color.
	AdditionalLabel string
	// Visual variant.
	Variant SubmenuItemVariant
	// Callback when the item is activated.
	OnActivate tea.Cmd
	// Whether this item is visibly de-emphasized.
	IsDim bool
}

A menu item with a label.

type SettingSubmenuItem

type SettingSubmenuItem struct {
	// Name of this setting.
	Label string
	// Callback when a new value is selected.
	OnChange func(newLabel string) tea.Msg
	// contains filtered or unexported fields
}

A submenu item for a "settings control" that can have multiple values and activated to switch between them.

func NewSettingsSubmenuItem

func NewSettingsSubmenuItem(label string, options []string, initialOption string, onChange func(newLabel string) tea.Msg) *SettingSubmenuItem

Create a new SettingsSubmenuItem. initialOption must be one of the options.

func NewYesNoSettingsSubmenuItem

func NewYesNoSettingsSubmenuItem(label string, initialValue bool, onChange func(newValue bool) tea.Msg) *SettingSubmenuItem

Create a new SettingsSubmenuItem that is just a yes/no toggle.

type SpacerSubmenuItem

type SpacerSubmenuItem struct{}

An empty spacer line.

type Submenu struct {
	// Controls exclusivity behavior of eager updates:
	//   SubmenuExclusivityNone, SubmenuExclusivityOne
	Exclusivity SubmenuExclusivity
	// contains filtered or unexported fields
}

State container for a submenu with its cursor and items.

func (submenu *Submenu) Activate() tea.Cmd

Call the currently selected item's activate callback. Returns a bubbletea command that can be run asynchronously.

func (submenu *Submenu) CursorDown()

Move the cursor to the next selectable item.

func (submenu *Submenu) CursorUp()

Move the cursor to the previous selectable item.

func (submenu *Submenu) Render(isSubmenuOpen bool, height int) string

Render the submenu to a fixed-height string with scrolling.

func (submenu *Submenu) ResetCursor()

Reset the cursor to the first selectable item.

func (submenu *Submenu) SetItems(items []SubmenuItem)

Set the items list and ensure the cursor is within bounds and on a selectable item.

type SubmenuExclusivity int
const (
	// No exclusivity, all updates just toggle the new item.
	SubmenuExclusivityNone SubmenuExclusivity = iota
	// All updates first clear the active state of all other items.
	SubmenuExclusivityOne
)
type SubmenuItem interface {
	// contains filtered or unexported methods
}

A generic submenu item.

type SubmenuItemVariant int

Visual variant of a submenu item:

SubmenuItemVariantDefault, SubmenuItemVariantDanger
const (
	SubmenuItemVariantDefault SubmenuItemVariant = iota
	SubmenuItemVariantAccent
	SubmenuItemVariantDanger
)

type TitleSubmenuItem

type TitleSubmenuItem struct {
	// The text to be displayed for this menu item.
	Label string
}

A title for a section of a menu.

type ToggleableSubmenuItem

type ToggleableSubmenuItem struct {
	LabeledSubmenuItem
	// Whether this item is currently active.
	IsActive bool
}

A menu item with a label that can be toggled active or inactive.

Jump to

Keyboard shortcuts

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