common

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TabOffset     = 10
	DefaultWidth  = 200
	DefaultHeight = 60
)

Variables

View Source
var (
	ShortHelpList = []key.Binding{
		ListKeys.Select, ListKeys.Up, ListKeys.Down, ListKeys.Filter, ListKeys.Help,
	}
	FullHelpListOneLine = []key.Binding{
		ListKeys.Select, ListKeys.Up, ListKeys.Down, ListKeys.Filter, ListKeys.Cancel, ListKeys.Help,
	}
	FullHelpList = [][]key.Binding{
		{ListKeys.Select}, {ListKeys.Up}, {ListKeys.Down}, {ListKeys.Filter}, {ListKeys.Cancel}, {ListKeys.Help},
	}
)
View Source
var (
	ShortHelpPicker = []key.Binding{
		PickerKeys.Up, PickerKeys.Down, PickerKeys.Select, PickerKeys.Cancel,
	}
	FullHelpPickerOneLine = []key.Binding{
		PickerKeys.Up, PickerKeys.Down, PickerKeys.Select, PickerKeys.Cancel,
	}
	FullHelpPicker = [][]key.Binding{
		{PickerKeys.Up}, {PickerKeys.Down}, {PickerKeys.Select}, {PickerKeys.Cancel},
	}
)
View Source
var (
	ShortHelpEditing = []key.Binding{
		EditKeys.Confirm, EditKeys.NewLine, EditKeys.DeleteWord, EditKeys.Cancel,
	}
	FullHelpEditingOneLine = []key.Binding{
		EditKeys.Confirm, EditKeys.NewLine, EditKeys.DeleteWord, EditKeys.Cancel,
	}
	FullHelpEditing = [][]key.Binding{
		{EditKeys.Confirm}, {EditKeys.NewLine}, {EditKeys.DeleteWord}, {EditKeys.Cancel},
	}
)
View Source
var (
	Subtle     = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"}
	Highlight  = lipgloss.AdaptiveColor{Light: "#6d26fc", Dark: "#7D56F4"}
	Highlight2 = lipgloss.AdaptiveColor{Light: "#8f58fc", Dark: "#8f6ef0"}
	Focused    = lipgloss.AdaptiveColor{Light: "#8378ab", Dark: "#bfb2eb"}
	Special    = lipgloss.AdaptiveColor{Light: "#43BF6D", Dark: "#73F59F"}
	Background = lipgloss.AdaptiveColor{Light: "#c5c6c7", Dark: "#333436"}
	Warning    = lipgloss.AdaptiveColor{Light: "#FFA100", Dark: "#F9A431"}

	HelpKey        = lipgloss.AdaptiveColor{Light: "#909090", Dark: "#626262"}
	HelpDesc       = lipgloss.AdaptiveColor{Light: "#B2B2B2", Dark: "#4A4A4A"}
	HelpSep        = lipgloss.AdaptiveColor{Light: "#DDDADA", Dark: "#3C3C3C"}
	ActiveHelpKey  = Highlight2
	ActiveHelpDesc = Highlight
	ActiveHelpSep  = Highlight

	ActiveTabBorder = lipgloss.Border{
		Top:         "─",
		Bottom:      " ",
		Left:        "│",
		Right:       "│",
		TopLeft:     "╭",
		TopRight:    "╮",
		BottomLeft:  "┘",
		BottomRight: "└",
	}

	TabBorder = lipgloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "╭",
		TopRight:    "╮",
		BottomLeft:  "┴",
		BottomRight: "┴",
	}

	Tab = lipgloss.NewStyle().
		Border(TabBorder, true).
		BorderForeground(Highlight).
		Padding(0, 1)

	ActiveTab = Tab.Border(ActiveTabBorder, true)

	TabGap = Tab.
			BorderTop(false).
			BorderLeft(false).
			BorderRight(false)

	LabelStyle = lipgloss.NewStyle().
				Margin(1).
				Foreground(Highlight)

	DialogBoxStyle = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder(), true).
					BorderForeground(Highlight)

	PanelStyle = lipgloss.NewStyle().
				Padding(0, 1).
				Margin(0, 1).
				Border(lipgloss.RoundedBorder(), false, true, true, true).
				BorderForeground(Highlight)

	PanelTitleStyle = func() lipgloss.Style {
		b := lipgloss.RoundedBorder()
		b.Right = "├"
		return lipgloss.NewStyle().BorderStyle(b).Padding(0, 1).BorderForeground(Highlight).Height(1)
	}()

	HighlightedBorderStyle = lipgloss.NewStyle().Foreground(Highlight)

	OverlayStyle = lipgloss.NewStyle().
					Border(lipgloss.DoubleBorder(), true).
					BorderForeground(Focused).
					Padding(1, 1)

	OverlayWarnStyle = lipgloss.NewStyle().
						Border(lipgloss.DoubleBorder(), true).
						BorderForeground(Warning).
						Padding(1, 1)

	BoxStyle = lipgloss.NewStyle().
				Border(lipgloss.NormalBorder(), true).
				BorderForeground(Highlight).
				Padding(1, 2).
				Margin(1).
				Width(30)

	// Help
	KeyStyle        = lipgloss.NewStyle().Foreground(HelpKey)
	DescStyle       = lipgloss.NewStyle().Foreground(HelpDesc)
	SepStyle        = lipgloss.NewStyle().Foreground(HelpSep)
	ActiveKeyStyle  = lipgloss.NewStyle().Foreground(ActiveHelpKey)
	ActiveDescStyle = lipgloss.NewStyle().Foreground(ActiveHelpDesc)
	ActiveSepStyle  = lipgloss.NewStyle().Foreground(ActiveHelpSep)
)

Style definitions.

View Source
var CommonKeys = Keys{
	Quit: key.NewBinding(
		key.WithKeys("ctrl+c"),
		key.WithHelp("ctrl+c", "quit"),
	),
	Help: key.NewBinding(
		key.WithKeys("?"),
		key.WithHelp("?", "toggle help"),
	),
	ModelRight: key.NewBinding(
		key.WithKeys("tab"),
		key.WithHelp("tab", "model right"),
	),
	ModelLeft: key.NewBinding(
		key.WithKeys("shift+tab"),
		key.WithHelp("shift+tab", "model left"),
	),
	NavigateModels: key.NewBinding(
		key.WithKeys("tab", "shift+tab"),
		key.WithHelp("tab/shift+tab", "switch models"),
	),
	Navigation: key.NewBinding(
		key.WithKeys("left", "h", "right", "l"),
		key.WithHelp("←/h, →/l", "navigation"),
	),
	NavigateLeft: key.NewBinding(
		key.WithKeys("left", "h"),
		key.WithHelp("←/h", "navigate left"),
	),
	NavigateRight: key.NewBinding(
		key.WithKeys("right", "l"),
		key.WithHelp("→/l", "navigate right"),
	),
	Confirm: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("↳", "confirm"),
	),
	Select: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("↳", "select"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "cancel"),
	),
	Edit: key.NewBinding(
		key.WithKeys("e"),
		key.WithHelp("e", "edit"),
	),
	Save: key.NewBinding(
		key.WithKeys("ctrl+s"),
		key.WithHelp("ctrl+s", "save"),
	),
}
View Source
var DumpFile *os.File
View Source
var EditKeys = editorKeys{
	Confirm: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "confirm"),
	),
	NewLine: key.NewBinding(
		key.WithKeys("ctrl+e"),
		key.WithHelp("ctrl+e", "new line"),
	),
	DeleteWord: key.NewBinding(
		key.WithKeys("alt+backspace"),
		key.WithHelp("alt+backspace", "delete word"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "cancel"),
	),
}
View Source
var ListKeys = listKeys{
	Up: key.NewBinding(
		key.WithKeys("up", "k"),
		key.WithHelp("↑/k", "move up"),
	),
	Down: key.NewBinding(
		key.WithKeys("down", "j"),
		key.WithHelp("↓/j", "move down"),
	),
	Filter: key.NewBinding(
		key.WithKeys("/"),
		key.WithHelp("/", "filter"),
	),
	Confirm: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("↳", "confirm"),
	),
	Select: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("↳", "select"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "cancel"),
	),
	Help: key.NewBinding(
		key.WithKeys("?"),
		key.WithHelp("?", "toggle help"),
	),
}
View Source
var PickerKeys = pickerKeys{
	Up: key.NewBinding(
		key.WithKeys("up", "k"),
		key.WithHelp("↑/k", "move up"),
	),
	Down: key.NewBinding(
		key.WithKeys("down", "j"),
		key.WithHelp("↓/j", "move down"),
	),
	Select: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("↳", "select"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("esc", "q"),
		key.WithHelp("esc/q", "cancel"),
	),
}

Functions

func ContainsKey

func ContainsKey(v string, a []string) string

func DumpToLog added in v0.8.0

func DumpToLog(msg ...any)

func FocusedListKeyMap

func FocusedListKeyMap() blist.KeyMap

func FocusedPanelKeyMap

func FocusedPanelKeyMap() viewport.KeyMap

func FocusedTextAreaKeyMap added in v0.8.0

func FocusedTextAreaKeyMap() textarea.KeyMap

func HeaderView

func HeaderView(titleText string, width int, focusColor lipgloss.AdaptiveColor) string

func HelpStyle

func HelpStyle(width int) lipgloss.Style

func NewFocusedDelegate

func NewFocusedDelegate() blist.DefaultDelegate

func NewUnfocusedDelegate

func NewUnfocusedDelegate() blist.DefaultDelegate

func NewUnfocusedHighlightDelegate

func NewUnfocusedHighlightDelegate() blist.DefaultDelegate

func PrintToLog added in v0.8.0

func PrintToLog(format string, a ...any)

func TruncateText

func TruncateText(text string, width int) string

func UnfocusedListKeyMap

func UnfocusedListKeyMap() blist.KeyMap

func UnfocusedPanelKeyMap

func UnfocusedPanelKeyMap() viewport.KeyMap

func UnfocusedTextAreaKeyMap added in v0.8.0

func UnfocusedTextAreaKeyMap() textarea.KeyMap

Types

type Edit added in v0.8.0

type Edit struct {
	EditType
	Path      string
	Value     map[string]interface{} // could this handle any type?
	Timestamp time.Time
}

type EditType added in v0.8.0

type EditType int
const (
	EditTypeAdd EditType = iota
	EditTypeUpdate
	EditTypeDelete
)

type Editor added in v0.8.0

type Editor struct {
	EditsByPath map[string][]*Edit
}

func NewEditor added in v0.8.0

func NewEditor() *Editor

func (*Editor) AddUpdateEdit added in v0.8.0

func (e *Editor) AddUpdateEdit(path string, value map[string]interface{})

func (*Editor) IsEmpty added in v0.8.0

func (e *Editor) IsEmpty() bool

IsEmpty checks if any edits have been made

func (*Editor) ResetEditor added in v0.8.0

func (e *Editor) ResetEditor()

ResetEditor resets the editor - runs after data is saved

type HelpModel added in v0.8.0

type HelpModel struct {
	Width int

	ShowAll bool // if true, render the "full" help menu
	OneLine bool

	ShortHelp       []key.Binding
	FullHelpOneLine []key.Binding
	FullHelp        [][]key.Binding

	ShortSeparator string
	FullSeparator  string

	// The symbol we use in the short help when help items have been truncated
	// due to width. Periods of ellipsis by default.
	Ellipsis string

	Styles HelpStyles
}

HelpModel contains the state of the help view.

func NewHelpModel added in v0.8.0

func NewHelpModel(active bool) HelpModel

New creates a new help view with some useful defaults.

func (HelpModel) FullHelpView added in v0.8.0

func (m HelpModel) FullHelpView(groups [][]key.Binding) string

FullHelpView renders help columns from a slice of key binding slices. Each top level slice entry renders into a column.

func (HelpModel) SingleLineHelpView added in v0.8.0

func (m HelpModel) SingleLineHelpView(bindings []key.Binding) string

SingleLineHelpView renders a single line help view from a slice of keybindings. If the line is longer than the maximum width it will be gracefully truncated, showing only as many help items as possible.

func (HelpModel) Update added in v0.8.0

func (m HelpModel) Update(_ tea.Msg) (HelpModel, tea.Cmd)

Update helps satisfy the Bubble Tea Model interface. It's a no-op.

func (HelpModel) View added in v0.8.0

func (m HelpModel) View() string

View renders the help view's current state.

type HelpStyles added in v0.8.0

type HelpStyles struct {
	Ellipsis lipgloss.Style

	// Styling for the short help
	ShortKey       lipgloss.Style
	ShortDesc      lipgloss.Style
	ShortSeparator lipgloss.Style

	// Styling for the full help
	FullKey       lipgloss.Style
	FullDesc      lipgloss.Style
	FullSeparator lipgloss.Style
}

Styles is a set of available style definitions for the Help bubble.

func NewStyles added in v0.8.0

func NewStyles(active bool) HelpStyles

type HelpType added in v0.8.0

type HelpType int
const (
	HelpTypeMain HelpType = iota
	HelpTypeEdit
	HelpTypeList
	HelpTypeSelect
	HelpTypePanel
	HelpTypeQuit
)

type Keys

type Keys struct {
	Quit           key.Binding
	Help           key.Binding
	ModelLeft      key.Binding
	ModelRight     key.Binding
	NavigateModels key.Binding
	NavigateLeft   key.Binding
	NavigateRight  key.Binding
	Navigation     key.Binding
	Confirm        key.Binding
	Select         key.Binding
	Cancel         key.Binding
	Up             key.Binding
	Down           key.Binding
	Filter         key.Binding
	Edit           key.Binding
	Save           key.Binding
	Newline        key.Binding
}

type PickerItemSelected added in v0.8.0

type PickerItemSelected struct {
	Selected int
	From     PickerKind
}

type PickerKind added in v0.8.0

type PickerKind string

type PickerModel added in v0.8.0

type PickerModel struct {
	Open bool
	// contains filtered or unexported fields
}

func NewPickerModel added in v0.8.0

func NewPickerModel(title string, kind PickerKind, items []string, initSelected int) PickerModel

func (PickerModel) Init added in v0.8.0

func (m PickerModel) Init() tea.Cmd

func (PickerModel) Update added in v0.8.0

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

func (PickerModel) View added in v0.8.0

func (m PickerModel) View() string

type PickerOpenMsg added in v0.8.0

type PickerOpenMsg struct {
	Kind PickerKind
}

type PopupClose added in v0.8.0

type PopupClose struct{}

type PopupFailMsg added in v0.8.0

type PopupFailMsg struct {
	Err error
}

type PopupModel added in v0.8.0

type PopupModel struct {
	Open    bool
	Title   string
	Content string
	Warning string
	Help    HelpModel
}

func NewPopupModel added in v0.8.0

func NewPopupModel(title, content string, helpKeys []key.Binding) PopupModel

func (PopupModel) Init added in v0.8.0

func (m PopupModel) Init() tea.Cmd

func (PopupModel) Update added in v0.8.0

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

func (*PopupModel) UpdateText added in v0.8.0

func (m *PopupModel) UpdateText(title, content, warning string)

func (PopupModel) View added in v0.8.0

func (m PopupModel) View() string

type PopupMsg added in v0.8.0

type PopupMsg struct {
	Title   string
	Content string
	Warning string
}

type SaveCloseAndResetMsg added in v0.8.0

type SaveCloseAndResetMsg struct{}

type SaveFailMsg added in v0.8.0

type SaveFailMsg struct {
	Err error
}

type SaveModel added in v0.8.0

type SaveModel struct {
	Open               bool
	Save               bool
	FilePath           string
	Title              string
	Content            string
	Warning            string
	RenderedDuringQuit bool
	Help               HelpModel
}

func NewSaveModel added in v0.8.0

func NewSaveModel(filepath string) SaveModel

func (SaveModel) Init added in v0.8.0

func (m SaveModel) Init() tea.Cmd

func (SaveModel) Update added in v0.8.0

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

func (SaveModel) View added in v0.8.0

func (m SaveModel) View() string

type SaveModelMsg added in v0.8.0

type SaveModelMsg struct {
	InQuitWorkflow bool
}

type SaveNoChangeMsg added in v0.8.0

type SaveNoChangeMsg struct{}

type SaveStartMsg added in v0.8.0

type SaveStartMsg struct{}

type SaveSuccessMsg added in v0.8.0

type SaveSuccessMsg struct{}

type TbdModal

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

func NewTbdModal

func NewTbdModal(modelName string) TbdModal

func (*TbdModal) Close

func (m *TbdModal) Close()

func (TbdModal) Init

func (m TbdModal) Init() tea.Cmd

func (*TbdModal) Open

func (m *TbdModal) Open()

func (TbdModal) Update

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

func (TbdModal) View

func (m TbdModal) View() string

Jump to

Keyboard shortcuts

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