ui

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FaintColor = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#8b8b8b"}
	FaintStyle = lipgloss.NewStyle().Foreground(FaintColor)
	OkColor    = lipgloss.AdaptiveColor{Light: "#43BF6D", Dark: "#73F59F"}
	OkStyle    = lipgloss.NewStyle().Foreground(OkColor)
	ErrColor   = lipgloss.AdaptiveColor{Light: "#770000", Dark: "#AA0000"}
	ErrStyle   = lipgloss.NewStyle().Foreground(ErrColor)
	BrownColor = lipgloss.AdaptiveColor{Light: "#A67C53", Dark: "#A67C53"}
	BrownStyle = lipgloss.NewStyle().Foreground(BrownColor)
	DocStyle   = lipgloss.NewStyle().Margin(1, 2)
	TitleStyle = lipgloss.NewStyle().
				Foreground(lipgloss.Color("230")).
				Background(lipgloss.Color("32")).
				Padding(0, 1)
	TitleBarStyle = lipgloss.NewStyle().Padding(0, 0, 1, 2)
	HelpStyle     = lipgloss.NewStyle().Padding(1, 0, 0, 2)
	SpinnerStyle  = lipgloss.NewStyle().
					Foreground(lipgloss.AdaptiveColor{Light: "#8E8E8E", Dark: "#747373"})
)
View Source
var ServiceControls = []ServiceControl{
	{
		Use:     "restart [name]",
		Short:   "Restart service",
		Aliases: []string{"r"},
		WaitMsg: "Restarting...",
		Display: "💫 Restart",
		Do: func(cli client.Client, name string) (string, error) {
			n, e := cli.ServiceRestart(name, false)
			if e != nil {
				return "", e
			} else {
				return fmt.Sprintf("Restarted %d services", n.Count), nil
			}
		},
	},
	{
		Use:     "rebuild [name]",
		Short:   "Invalidates build cache and restarts service",
		Aliases: []string{"invalidate"},
		WaitMsg: "Rebuilding...",
		Display: "🔨 Rebuild",
		Do: func(cli client.Client, name string) (string, error) {
			n, e := cli.ServiceRestart(name, true)
			if e != nil {
				return "", e
			} else {
				return fmt.Sprintf("Rebuilt %d services", n.Count), nil
			}
		},
	},
	{
		Use:     "stop [name]",
		Short:   "Stops service",
		Aliases: []string{"kill"},
		WaitMsg: "Stopping the service...",
		Display: "🛑 Stop",
		Do: func(cli client.Client, name string) (string, error) {
			n, e := cli.ServiceStop(name)
			if e != nil {
				return "", e
			} else {
				return fmt.Sprintf("Stopped %d services", n.Count), nil
			}
		},
	},
}

Functions

func BasicTable

func BasicTable(data [][]Pair) string

func Display

func Display(v any) string

func DisplayArray

func DisplayArray(vs []any) []string

func DisplayFloat

func DisplayFloat(f float64) string

func DisplayFloatWithGran

func DisplayFloatWithGran(f float64, gran float64) string

func DisplayInt

func DisplayInt(n int64) string

func DisplayUint

func DisplayUint(n uint64) string

func ErrMsg

func ErrMsg(err any) tea.Cmd

func ExitWithError

func ExitWithError(err any)

func FixedBlock

func FixedBlock(pre string, post string, n int) string

func MapToStableList

func MapToStableList[K cmp.Ordered, V any, E any](m map[K]V, cvt func(K, V) E) []E
func Navigate(model tea.Model) tea.Cmd

func Pad

func Pad(n int) string

func PromptSelect

func PromptSelect(title string, list []string) string

func PromptSelectService

func PromptSelectService(cl client.Client) string

func PromptSelectValueDesc

func PromptSelectValueDesc[V cmp.Ordered](title string, vd map[V]string) V

func PromptString

func PromptString(msg string, initial string, placeholder string, validate func(s string) error) string

func RenderErrorLine

func RenderErrorLine(err any) string

func RenderOkLine

func RenderOkLine(res any) string

func Run

func Run(m Bimodel)

func SetSpinnerState

func SetSpinnerState(b bool) tea.Cmd

func SpinnyAsync

func SpinnyAsync(msg string, done <-chan struct{})

func SpinnyWait

func SpinnyWait[T any](msg string, f func() (T, error)) (res T)

func StatusMsg

func StatusMsg(msg string) tea.Cmd

Types

type Bimodel

type Bimodel interface {
	tea.Model
	Run() error
}

func MakeServiceDetailModel

func MakeServiceDetailModel(cl client.Client, item *ServiceItem) Bimodel

func MakeServiceListModel

func MakeServiceListModel(cl client.Client) Bimodel

type ChanStore

type ChanStore[T any] <-chan T

func (ChanStore[T]) Next

func (c ChanStore[T]) Next() (data T, next Store[T], err error)

type DerivedStore

type DerivedStore[T, U any] struct {
	Src Store[T]
	Fn  func(T) U
}

func (DerivedStore[T, U]) Next

func (t DerivedStore[T, U]) Next() (data U, next Store[U], err error)

type Displayer

type Displayer interface {
	Display() string
}

Displayer is an interface for displaying a string.

type ImmutableStore

type ImmutableStore[T any] [1]T

func (ImmutableStore[T]) Next

func (d ImmutableStore[T]) Next() (data T, next Store[T], err error)

type Item

type Item interface {
	list.DefaultItem
	FilterValue() string
	Entries() []Pair
}

type KeyMatchMsg

type KeyMatchMsg struct {
	Key string
}

type List

type List[T Item] struct {
	Model list.Model
	// contains filtered or unexported fields
}

func NewList

func NewList[T Item](del list.ItemDelegate) List[T]

func (List[T]) Init

func (m List[T]) Init() tea.Cmd

func (List[T]) Run

func (m List[T]) Run() error

func (List[T]) Update

func (m List[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (List[T]) View

func (m List[T]) View() string

func (List[T]) WithPull

func (m List[T]) WithPull(f func() ([]T, error)) List[T]

func (List[T]) WithStore

func (m List[T]) WithStore(s Store[[]T]) List[T]

Options.

func (List[T]) WithThen

func (m List[T]) WithThen(then func(T) tea.Model) List[T]

func (List[T]) WithTitle

func (m List[T]) WithTitle(title string) List[T]
type NavigateMsg struct {
	Model tea.Model
}

type Observer

type Observer[T any] struct {
	Source Store[T]
	Data   T
	Err    error
	Busy   bool
}

func MakeObserver

func MakeObserver[T any](src Store[T]) Observer[T]

func (*Observer[T]) Observe

func (d *Observer[T]) Observe(msg tea.Msg, onChanged func(T, error) tea.Cmd) (cmd tea.Cmd)

func (*Observer[T]) Update

func (d *Observer[T]) Update(msg tea.Msg) (cmd tea.Cmd, changed bool)

type Page

type Page struct {
	Title string

	// Key mappings for navigating the list.
	KeyMap []key.Binding

	Help help.Model

	StatusMessageLifetime time.Duration
	// contains filtered or unexported fields
}

func NewPage

func NewPage(inner PageModel, prop PageProps) Page

New returns a new model with sensible defaults.

func (Page) FullHelp

func (m Page) FullHelp() [][]key.Binding

func (Page) Height

func (m Page) Height() int

Height returns the current height setting.

func (Page) Init

func (m Page) Init() tea.Cmd

func (Page) Run

func (m Page) Run() error

func (*Page) SetHeight

func (m *Page) SetHeight(v int)

SetHeight sets the height of this component.

func (*Page) SetShowHelp

func (m *Page) SetShowHelp(v bool)

SetShowHelp shows or hides the help view.

func (*Page) SetShowTitle

func (m *Page) SetShowTitle(v bool)

SetShowTitle shows or hides the title bar.

func (*Page) SetSize

func (m *Page) SetSize(width, height int)

SetSize sets the width and height of this component.

func (*Page) SetSpinner

func (m *Page) SetSpinner(spinner spinner.Spinner)

SetSpinner allows to set the spinner style.

func (*Page) SetWidth

func (m *Page) SetWidth(v int)

SetWidth sets the width of this component.

func (Page) ShortHelp

func (m Page) ShortHelp() []key.Binding

func (Page) ShowHelp

func (m Page) ShowHelp() bool

ShowHelp returns whether or not the help is set to be rendered.

func (Page) ShowTitle

func (m Page) ShowTitle() bool

ShowTitle returns whether or not the title bar is set to be rendered.

func (*Page) StartSpinner

func (m *Page) StartSpinner() tea.Cmd

StartSpinner starts the spinner. Note that this returns a command.

func (*Page) StopSpinner

func (m *Page) StopSpinner()

StopSpinner stops the spinner.

func (Page) Update

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

Update is the Bubble Tea update loop.

func (Page) View

func (m Page) View() string

View renders the component.

func (Page) Width

func (m Page) Width() int

Width returns the current width setting.

type PageModel

type PageModel interface {
	// Interactive page.
	Update(tea.Msg) (PageModel, tea.Cmd)
	View(w, h int) string
	// Non-interactive page.
	Run() error
}

type PageProps

type PageProps struct {
	Title string
	Keys  []key.Binding
}

type Pair

type Pair struct {
	Key   string
	Value string
}

func Pairs

func Pairs(in ...string) (r []Pair)

type PullStore

type PullStore[T any] func() (data T, err error)

func (PullStore[T]) Next

func (s PullStore[T]) Next() (data T, next Store[T], err error)

type ServiceControl

type ServiceControl struct {
	Use, Short string
	Aliases    []string
	WaitMsg    string
	Display    string
	Do         func(cli client.Client, name string) (msg string, err error)
}

type ServiceDetailModel

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

func (ServiceDetailModel) Init

func (m ServiceDetailModel) Init() tea.Cmd

func (ServiceDetailModel) Run

func (m ServiceDetailModel) Run() error

func (ServiceDetailModel) Update

func (m ServiceDetailModel) Update(msg tea.Msg) (PageModel, tea.Cmd)

func (ServiceDetailModel) View

func (m ServiceDetailModel) View(w, h int) string

type ServiceItem

type ServiceItem struct {
	Name string
	session.ServiceInfo
}

func (ServiceItem) Description

func (i ServiceItem) Description() string

func (ServiceItem) Entries

func (i ServiceItem) Entries() (m []Pair)

func (ServiceItem) FilterValue

func (i ServiceItem) FilterValue() string

func (ServiceItem) Title

func (i ServiceItem) Title() string

type Store

type Store[T any] interface {
	Next() (data T, next Store[T], err error)
}

Jump to

Keyboard shortcuts

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