widget

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package widget implements more complex user interface components on top of the primitives offered in the ui package.

Index

Constants

This section is empty.

Variables

View Source
var DefaultBranchSelectKeyMap = BranchSelectKeyMap{
	Up: key.NewBinding(
		key.WithKeys("up"),
		key.WithHelp("up", "go up"),
	),
	Down: key.NewBinding(
		key.WithKeys("down"),
		key.WithHelp("down", "go down"),
	),
	Accept: key.NewBinding(
		key.WithKeys("enter", "tab"),
		key.WithHelp("enter/tab", "accept"),
	),
	Delete: key.NewBinding(
		key.WithKeys("backspace", "ctrl+h"),
		key.WithHelp("backspace", "delete filter character"),
	),
}

DefaultBranchSelectKeyMap is the default key map for a [Select].

View Source
var DefaultBranchSplitStyle = BranchSplitStyle{
	Commit:      DefaultCommitSummaryStyle,
	HeadCommit:  DefaultCommitSummaryStyle.Faint(true),
	SplitMarker: ui.NewStyle().SetString("□"),
	HeadMarker:  ui.NewStyle().SetString("■"),
}

DefaultBranchSplitStyle is the default style for a BranchSplit.

View Source
var DefaultBranchTreeSelectStyle = BranchTreeSelectStyle{
	Name:            ui.NewStyle(),
	SelectedName:    ui.NewStyle().Bold(true).Foreground(ui.Yellow),
	DisabedName:     ui.NewStyle().Foreground(ui.Gray),
	HighlightedName: ui.NewStyle().Foreground(ui.Cyan),
	Marker:          ui.NewStyle().Foreground(ui.Yellow).Bold(true).SetString("◀"),
}

DefaultBranchTreeSelectStyle is the default style for a BranchTreeSelect widget.

View Source
var DefaultCommitSummaryStyle = CommitSummaryStyle{
	Hash:    ui.NewStyle().Foreground(ui.Yellow),
	Subject: ui.NewStyle().Foreground(ui.Plain),
	Time:    ui.NewStyle().Foreground(ui.Gray),
}

DefaultCommitSummaryStyle is the default style for rendering a CommitSummary.

Functions

This section is empty.

Types

type BranchSelectKeyMap

type BranchSelectKeyMap struct {
	Up   key.Binding // move up the list
	Down key.Binding // move down the list

	Accept key.Binding // accept the focused option
	Delete key.Binding // delete the last character in the filter
}

BranchSelectKeyMap defines the key bindings for [Select].

type BranchSplit

type BranchSplit struct {
	Style BranchSplitStyle
	// contains filtered or unexported fields
}

BranchSplit is a widget that allows users to pick out commits to split from the current branch.

It displays a list of commits, the last of which is not selectable.

func NewBranchSplit

func NewBranchSplit() *BranchSplit

NewBranchSplit creates a new BranchSplit widget.

func (*BranchSplit) Description

func (b *BranchSplit) Description() string

Description returns the description of the widget.

func (*BranchSplit) Err

func (b *BranchSplit) Err() error

Err returns nil.

func (*BranchSplit) Init

func (b *BranchSplit) Init() tea.Cmd

Init initializes the widget.

func (*BranchSplit) Render

func (b *BranchSplit) Render(w ui.Writer)

Render renders the widget to the given writer.

func (*BranchSplit) Selected

func (b *BranchSplit) Selected() []int

Selected returns the indexes of the selected commits.

func (*BranchSplit) Title

func (b *BranchSplit) Title() string

Title returns the title of the widget.

func (*BranchSplit) Update

func (b *BranchSplit) Update(msg tea.Msg) tea.Cmd

Update updates the widget based on the message.

func (*BranchSplit) WithCommits

func (b *BranchSplit) WithCommits(commits ...CommitSummary) *BranchSplit

WithCommits sets the commits to be listed in a branch split widget.

func (*BranchSplit) WithDescription

func (b *BranchSplit) WithDescription(desc string) *BranchSplit

WithDescription sets the description of the widget.

func (*BranchSplit) WithHEAD

func (b *BranchSplit) WithHEAD(head string) *BranchSplit

WithHEAD sets the name of the head commit: the last commit in the branch. This name, if present, is shown next to the head commit.

func (*BranchSplit) WithTitle

func (b *BranchSplit) WithTitle(title string) *BranchSplit

WithTitle sets the title of the widget.

type BranchSplitStyle

type BranchSplitStyle struct {
	Commit     CommitSummaryStyle
	HeadCommit CommitSummaryStyle

	SplitMarker lipgloss.Style
	HeadMarker  lipgloss.Style
}

BranchSplitStyle defines the styles for BranchSplit.

type BranchTreeItem

type BranchTreeItem struct {
	// Branch is the name of the branch.
	Branch string

	// Base is the name of the branch this branch is on top of.
	// This will be used to create a tree view of branches.
	// Branches with no base are considered root branches.
	Base string

	// Disabled indicates that this branch cannot be selected.
	// It will appear grayed out in the list.
	Disabled bool
}

BranchTreeItem is a single item in a BranchTreeSelect.

type BranchTreeSelect

type BranchTreeSelect struct {
	Style  BranchTreeSelectStyle
	KeyMap BranchSelectKeyMap
	// contains filtered or unexported fields
}

BranchTreeSelect is a prompt that allows selecting a branch from a tree-view of branches. The trunk branch is shown at the bottom of the tree similarly to 'gs ls'.

In addition to arrow-based navigation, it allows fuzzy filtering branches by typing the branch name.

func NewBranchTreeSelect

func NewBranchTreeSelect() *BranchTreeSelect

NewBranchTreeSelect creates a new BranchTreeSelect widget.

func (*BranchTreeSelect) Description

func (b *BranchTreeSelect) Description() string

Description returns the description of the widget.

func (*BranchTreeSelect) Err

func (b *BranchTreeSelect) Err() error

Err reports any errors in the current state of the widget.

func (*BranchTreeSelect) Init

func (b *BranchTreeSelect) Init() tea.Cmd

Init initializes the widget.

func (*BranchTreeSelect) Render

func (b *BranchTreeSelect) Render(w ui.Writer)

Render renders the widget.

func (*BranchTreeSelect) Title

func (b *BranchTreeSelect) Title() string

Title returns the title of the widget.

func (*BranchTreeSelect) Update

func (b *BranchTreeSelect) Update(msg tea.Msg) tea.Cmd

Update updates the state of the widget based on a bubbletea message.

func (*BranchTreeSelect) Value

func (b *BranchTreeSelect) Value() string

Value returns the selected branch name.

func (*BranchTreeSelect) WithDescription

func (b *BranchTreeSelect) WithDescription(description string) *BranchTreeSelect

WithDescription sets the description of the widget.

func (*BranchTreeSelect) WithItems

func (b *BranchTreeSelect) WithItems(items ...BranchTreeItem) *BranchTreeSelect

WithItems adds a branch and its base to the widget with the given base. The named branch can be selected, but the base cannot.

func (*BranchTreeSelect) WithTitle

func (b *BranchTreeSelect) WithTitle(title string) *BranchTreeSelect

WithTitle sets the title of the widget.

func (*BranchTreeSelect) WithValue

func (b *BranchTreeSelect) WithValue(value *string) *BranchTreeSelect

WithValue specifies the destination for the selected branch. If the existing value matches a branch name, it will be selected.

type BranchTreeSelectStyle

type BranchTreeSelectStyle struct {
	Name            lipgloss.Style
	DisabedName     lipgloss.Style
	SelectedName    lipgloss.Style
	HighlightedName lipgloss.Style

	Marker lipgloss.Style
}

BranchTreeSelectStyle defines the styling for a BranchTreeSelect widget.

type CommitSummary

type CommitSummary struct {
	ShortHash  git.Hash
	Subject    string
	AuthorDate time.Time
}

CommitSummary is the summary of a single commit.

func (*CommitSummary) Render

func (c *CommitSummary) Render(w ui.Writer, style CommitSummaryStyle)

Render renders a CommitSummary to the given writer.

type CommitSummaryStyle

type CommitSummaryStyle struct {
	Hash    lipgloss.Style
	Subject lipgloss.Style
	Time    lipgloss.Style
}

CommitSummaryStyle is the style for rendering a CommitSummary.

func (CommitSummaryStyle) Faint

Faint returns a copy of the style with the faint attribute set to f.

Jump to

Keyboard shortcuts

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