tui

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Black           = lipgloss.Color("#000000")
	DarkRed         = lipgloss.Color("#FF0000")
	Red             = lipgloss.Color("#FF5353")
	Pink            = lipgloss.Color("#E760FC")
	Orange          = lipgloss.Color("214")
	Yellow          = lipgloss.Color("#DBBD70")
	Green           = lipgloss.Color("34")
	LightGreen      = lipgloss.Color("86")
	DarkGreen       = lipgloss.Color("#325451")
	GreenBlue       = lipgloss.Color("#00A095")
	DeepBlue        = lipgloss.Color("39")
	LightBlue       = lipgloss.Color("81")
	Blue            = lipgloss.Color("63")
	Violet          = lipgloss.Color("13")
	Grey            = lipgloss.Color("#737373")
	LightGrey       = lipgloss.Color("245")
	LighterGrey     = lipgloss.Color("250")
	EvenLighterGrey = lipgloss.Color("253")
	DarkGrey        = lipgloss.Color("#606362")
	White           = lipgloss.Color("#ffffff")
	OffWhite        = lipgloss.Color("#a8a7a5")
)

Variables

View Source
var (
	DebugLogLevel = Blue
	InfoLogLevel  = lipgloss.AdaptiveColor{Dark: string(LightGreen), Light: string(Green)}
	ErrorLogLevel = Red
	WarnLogLevel  = Yellow

	LogRecordAttributeKey = lipgloss.AdaptiveColor{Dark: string(White), Light: string(Black)}

	HelpKey  = Grey
	HelpDesc = LightGrey

	HighlightBackground              = Grey
	HighlightForeground              = White
	SelectedBackground               = lipgloss.Color("#a19518")
	SelectedForeground               = Black
	HighlightedAndSelectedBackground = lipgloss.Color("#635c0e")
	HighlightedAndSelectedForeground = White

	TitleColor = lipgloss.AdaptiveColor{
		Dark:  "",
		Light: "",
	}

	ScrollPercentageBackground = lipgloss.AdaptiveColor{
		Dark:  string(DarkGrey),
		Light: string(EvenLighterGrey),
	}
)
View Source
var (
	Regular = lipgloss.NewStyle()
	Bold    = Regular.Copy().Bold(true)
	Padded  = Regular.Copy().Padding(0, 1)
	Faint   = Regular.Copy().Faint(true)

	Width  = lipgloss.Width
	Height = lipgloss.Height
)
View Source
var ErrDuplicateTab = errors.New("not allowed to create tabs with duplicate titles")
View Source
var TitleStyle = Bold.Copy().Foreground(TitleColor)

Functions

func Ago

func Ago(now, t time.Time) string

func CmdHandler

func CmdHandler(msg tea.Msg) tea.Cmd

func CreateRuns

func CreateRuns(runs RunService, workspaceIDs ...resource.ID) tea.Cmd

func CreateTasks

func CreateTasks(cmd string, fn task.Func, ids ...resource.ID) tea.Cmd

CreateTasks returns a command that creates one or more tasks using the given IDs. If a task fails to be created then no further tasks will be created, and an error notification is sent. If all tasks are successfully created then a status notification is sent accordingly.

func GlobalBreadcrumb(title string) string
func NavigateTo(kind Kind, opts ...NavigateOption) tea.Cmd

NavigateTo sends an instruction to navigate to a page with the given model kind, and optionally parent resource.

func OpenVim

func OpenVim(path string) tea.Cmd

func ReportError

func ReportError(err error, msg string, args ...any) tea.Cmd

func RequestConfirmation

func RequestConfirmation(prompt string, action tea.Cmd) tea.Cmd

func WaitTasks

func WaitTasks(created CreatedTasksMsg) tea.Cmd

Types

type CompletedTasksMsg

type CompletedTasksMsg struct {
	// The command of the completed tasks (all tasks are assumed to be running
	// the same command).
	Command string
	Tasks   task.Multi
	// Errors from originally creating tasks
	CreateErrs []error
}

type ConfirmPromptMsg

type ConfirmPromptMsg struct {
	Prompt string
	Action tea.Cmd
}

type CreatedRunsMsg

type CreatedRunsMsg struct {
	Runs []*run.Run
	// Errors from creating tasks
	CreateErrs []error
}

type CreatedTasksMsg

type CreatedTasksMsg struct {
	// The command of the completed tasks (all tasks are assumed to be running
	// the same command).
	Command string
	Tasks   task.Multi
	// Errors from creating tasks
	CreateErrs []error
}

type ErrorMsg

type ErrorMsg struct {
	Error   error
	Message string
	Args    []any
}

func NewErrorMsg

func NewErrorMsg(err error, msg string, args ...any) ErrorMsg

type Helpers

type Helpers struct {
	ModuleService    ModuleService
	WorkspaceService WorkspaceService
	RunService       RunService
	StateService     StateService
	Logger           logging.Interface
}

Helper methods for easily surfacing info in the TUI.

TODO: leverage a cache to enhance performance, particularly if we introduce sqlite at some stage. These helpers are invoked on every render, which for a table with, say 40 visible rows, means they are invoked 40 times a render, which is 40 lookups.

func (*Helpers) Breadcrumbs

func (h *Helpers) Breadcrumbs(title string, parent resource.Resource) string

func (*Helpers) CurrentWorkspaceName

func (h *Helpers) CurrentWorkspaceName(workspaceID *resource.ID) string

func (*Helpers) LatestRunReport

func (h *Helpers) LatestRunReport(r *run.Run) string

func (*Helpers) ModuleCurrentRunChanges

func (h *Helpers) ModuleCurrentRunChanges(mod *module.Module) string

func (*Helpers) ModuleCurrentRunStatus

func (h *Helpers) ModuleCurrentRunStatus(mod *module.Module) string

func (*Helpers) ModulePath

func (h *Helpers) ModulePath(res resource.Resource) string

func (*Helpers) RunReport

func (h *Helpers) RunReport(report run.Report) string

func (*Helpers) RunStatus

func (h *Helpers) RunStatus(r *run.Run) string

func (*Helpers) WorkspaceCurrentCheckmark

func (h *Helpers) WorkspaceCurrentCheckmark(ws *workspace.Workspace) string

WorkspaceCurrentCheckmark returns a check mark if the workspace is the current workspace for its module.

func (*Helpers) WorkspaceCurrentRunChanges

func (h *Helpers) WorkspaceCurrentRunChanges(ws *workspace.Workspace) string

func (*Helpers) WorkspaceCurrentRunStatus

func (h *Helpers) WorkspaceCurrentRunStatus(ws *workspace.Workspace) string

func (*Helpers) WorkspaceName

func (h *Helpers) WorkspaceName(res resource.Resource) string

func (*Helpers) WorkspaceResourceCount

func (h *Helpers) WorkspaceResourceCount(ws *workspace.Workspace) string

type InfoMsg

type InfoMsg string

type Kind

type Kind int
const (
	ModuleListKind Kind = iota
	ModuleKind
	WorkspaceListKind
	WorkspaceKind
	RunListKind
	RunKind
	TaskListKind
	TaskKind
	TaskDetailsKind
	LogsKind
)

func FirstPageKind

func FirstPageKind(s string) (Kind, error)

FirstPageKind retrieves the model corresponding to the user requested first page.

func (Kind) String

func (i Kind) String() string

type Maker

type Maker interface {
	Make(target resource.Resource, width, height int) (tea.Model, error)
}

Maker makes new models

type ModelHelpBindings

type ModelHelpBindings interface {
	HelpBindings() []key.Binding
}

ModelHelpBindings is implemented by models that surface further help bindings specific to the model.

type ModelID

type ModelID interface {
	ID() string
}

ModelID is implemented by models that are able to provide a unique identification string.

type ModelStatus

type ModelStatus interface {
	Status() string
}

ModelID is implemented by models that are able to provide a unique identification string.

type ModelTitle

type ModelTitle interface {
	Title() string
}

ModelTitle is implemented by models that show a title

type ModuleService

type ModuleService interface {
	Get(id resource.ID) (*module.Module, error)
	List() []*module.Module
	Reload() error
	Init(moduleID resource.ID) (*task.Task, error)
	Format(moduleID resource.ID) (*task.Task, error)
	Validate(moduleID resource.ID) (*task.Task, error)
	SetCurrent(moduleID, workspaceID resource.ID) error
}
type NavigateOption func(msg *NavigationMsg)

func WithParent

func WithParent(parent resource.Resource) NavigateOption
type NavigationMsg struct {
	Page Page
}

NavigationMsg is an instruction to navigate to a page.

func NewNavigationMsg

func NewNavigationMsg(kind Kind, opts ...NavigateOption) NavigationMsg

type Page

type Page struct {
	// The model kind
	Kind Kind
	// The model's parent resource
	Parent resource.Resource
}

Page identifies an instance of a model

type RunService

type RunService interface {
	Create(workspaceID resource.ID, opts run.CreateOptions) (*run.Run, error)
	Get(id resource.ID) (*run.Run, error)
	List(opts run.ListOptions) []*run.Run
	Apply(runID resource.ID) (*task.Task, error)
}

type SetActiveTabMsg

type SetActiveTabMsg string

type StateService

type StateService interface {
	Reload(workspaceID resource.ID) (*task.Task, error)
	Get(workspaceID resource.ID) (*state.State, error)
	Delete(workspaceID resource.ID, addrs ...state.ResourceAddress) (*task.Task, error)
	Taint(workspaceID resource.ID, addr state.ResourceAddress) (*task.Task, error)
	Untaint(workspaceID resource.ID, addr state.ResourceAddress) (*task.Task, error)
}

type Tab

type Tab struct {
	tea.Model

	Title string
}

A tab is one of a set of tabs. A tab has a title, and an embedded model, which is responsible for the visible content under the tab.

type TabSet

type TabSet struct {
	Tabs []Tab
	// contains filtered or unexported fields
}

TabSet is a related set of zero or more tabs, one of which is active, i.e. its contents are rendered.

func NewTabSet

func NewTabSet(width, height int) TabSet

func (TabSet) Active

func (m TabSet) Active() (bool, Tab)

Active returns the currently active tab. If there are no tabs, then false is returned.

func (TabSet) ActiveTitle

func (m TabSet) ActiveTitle() string

Active returns the title of the currently active tab. If there are no tabs, then an empty string is returned.

func (*TabSet) AddTab

func (m *TabSet) AddTab(maker Maker, parent resource.Resource, title string) (tea.Cmd, error)

AddTab adds a tab to the tab set, using the maker and parent to construct the model associated with the tab. The title must be unique in the set. Upon success the associated model's Init() is returned for the caller to initialise the model.

func (*TabSet) HelpBindings

func (m *TabSet) HelpBindings() (bindings []key.Binding)

func (TabSet) Init

func (m TabSet) Init() tea.Cmd

Init initializes the existing tabs in the collection.

func (*TabSet) SetActiveTab

func (m *TabSet) SetActiveTab(title string)

SetActiveTab looks up a tab with a title and makes it the active tab. If the tab's model is not yet initialized then its Init() command is returned. If no such tab exists no action is taken.

func (TabSet) Update

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

func (TabSet) View

func (m TabSet) View() string

func (TabSet) WithTabSetInfo

func (m TabSet) WithTabSetInfo(i tabSetInfo) TabSet

type TaskService

type TaskService interface {
	Counter() int
	Get(taskID resource.ID) (*task.Task, error)
	List(opts task.ListOptions) []*task.Task
	Cancel(taskID resource.ID) (*task.Task, error)
}

type WorkspaceService

type WorkspaceService interface {
	Reload(moduleID resource.ID) (*task.Task, error)
	Get(id resource.ID) (*workspace.Workspace, error)
	List(opts workspace.ListOptions) []*workspace.Workspace
	SelectWorkspace(moduleID, workspaceID resource.ID) error
	Delete(id resource.ID) (*task.Task, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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