radio

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultUnfocusedColor             = gloss.AdaptiveColor{Light: "#3a3a3a", Dark: "#b0b0b0"}
	DefaultActiveButtonIndicatorColor = gloss.AdaptiveColor{Light: "#bb99fe", Dark: "#997bf6"}

	// ╭───╮
	// │foo│
	// ╰───╯
	DefaultPillBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "╭",
		TopRight:    "╮",
		BottomLeft:  "╰",
		BottomRight: "╯",
	}

	// ╭───┬
	// │foo│
	// ╰───┴
	DefaultGroupedHorizontalFirstBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "╭",
		TopRight:    "┬",
		BottomLeft:  "╰",
		BottomRight: "┴",
	}
	//  ───┬
	//  foo│
	//  ───┴
	DefaultGroupedHorizontalBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "",
		Right:       "│",
		TopLeft:     "",
		TopRight:    "┬",
		BottomLeft:  "",
		BottomRight: "┴",
	}
	//  ───╮
	//  foo│
	//  ───╯
	DefaultGroupedHorizontalLastBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "",
		Right:       "│",
		TopLeft:     "",
		TopRight:    "╮",
		BottomLeft:  "",
		BottomRight: "╯",
	}

	// ┌───┐
	// │foo│
	// ├───┤
	DefaultGroupedVerticalFirstBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "╭",
		TopRight:    "╮",
		BottomLeft:  "├",
		BottomRight: "┤",
	}
	// │foo│
	// ├───┤
	DefaultGroupedVerticalBorder = gloss.Border{
		Top:         "",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "",
		TopRight:    "",
		BottomLeft:  "├",
		BottomRight: "┤",
	}
	// │foo│
	// ╰───╯
	DefaultGroupedVerticalLastBorder = gloss.Border{
		Top:         "",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "",
		TopRight:    "",
		BottomLeft:  "╰",
		BottomRight: "╯",
	}
)

Functions

This section is empty.

Types

type Button

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

Button represents a single radio button. It provides basic handling of radio-button-state. However, a user-defined model may be passed into the Model instead if custom behavior is needed.

func NewButton

func NewButton(label string) Button

NewButton creates a new Button.

func (Button) Init

func (m Button) Init() tea.Cmd

Init the Button.

func (Button) Styles

func (m Button) Styles(styles ButtonStyles) Button

Styles sets custom styling.

func (Button) Update

func (m Button) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update the Button.

func (Button) View

func (m Button) View() string

View renders the Button.

type ButtonStyles

type ButtonStyles struct {
	// Character(s) to left of the button label/content
	LeftIndicatorCharacter string

	// Character(s) to left of the action button label/content
	ActiveLeftIndicatorCharacter string

	// Character(s) to right of the button label/content
	RightIndicatorCharacter string

	// Character(s) to right of the active button label/content
	ActiveRightIndicatorCharacter string

	// Area to the left of the button label/content
	LeftIndicator gloss.Style

	// Area to the left of the active button label/content
	ActiveLeftIndicator gloss.Style

	// Area to the right of the button label/content
	RightIndicator gloss.Style

	// Area to the right of the active button label/content
	ActiveRightIndicator gloss.Style

	// Label/content for the button
	Label gloss.Style

	// Label/content for the active button
	ActiveLabel gloss.Style
}

Styles for rendering the interior of the button itself.

func DefaultButtonStyles

func DefaultButtonStyles() ButtonStyles

DefaultButtonStyles provides default styles for a button.

type KeyMap

type KeyMap struct {
	Select key.Binding

	Previous key.Binding
	Next     key.Binding
}

KeyMap contains relevant keys for button navigation.

func DefaultKeyMap

func DefaultKeyMap(vertical bool) KeyMap

defaultKeyMap contains default key mappings for radio group navigation.

type Model

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

Model represents a group of radio buttons.

func New

func New(vertical bool, buttons ...tea.Model) Model

New creates a new Model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init the Model.

func (Model) NextButton

func (m Model) NextButton() Model

NextButton moves the active button forward.

func (Model) PreviousButton

func (m Model) PreviousButton() Model

PreviousButton moves the active button backward.

func (Model) SetButton

func (m Model) SetButton(i int) Model

SetButton sets the active button.

func (Model) Styles

func (m Model) Styles(styles Styles) Model

Styles sets custom styling.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update the Model.

func (Model) View

func (m Model) View() string

View renders the Model.

func (Model) Wraparound

func (m Model) Wraparound(w bool) Model

Wraparound enables or disables wraparound navigation from the last button to the first button and from the first button back to the last button.

type RadioButtonMsg

type RadioButtonMsg struct {
	// State is whether or not the radio button is active
	State bool

	// User-defined data to pass down into the button
	Data any
}

RadioButtonMsg enables communication down into radio buttons

type Styles

type Styles struct {
	FirstButton gloss.Style
	Button      gloss.Style
	LastButton  gloss.Style
}

Styles for button rendering.

DefaultStyles and DefaultPillStyles only really use Button. DefaultGroupedStyles uses all three button styles for grouped rendering.

func DefaultGroupedStyles

func DefaultGroupedStyles(vertical bool) Styles

DefaultGroupedStyles provides default button grouped styles.

func DefaultPillStyles

func DefaultPillStyles(vertical bool) Styles

DefaultPillStyles provides default button pill styles.

func DefaultStyles

func DefaultStyles(vertical bool) Styles

DefaultStyles provides default button styles.

Jump to

Keyboard shortcuts

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