tui

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Black           = lipgloss.Color("#000000")
	DarkRed         = lipgloss.Color("#FF0000")
	Red             = lipgloss.Color("#FF5353")
	Purple          = lipgloss.Color("135")
	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")
)
View Source
const PromptHeight = 3

Height of prompt including borders

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 = lipgloss.AdaptiveColor{
		Dark:  "ff",
		Light: "",
	}
	HelpDesc = lipgloss.AdaptiveColor{
		Dark:  "248",
		Light: "246",
	}

	InactivePreviewBorder = lipgloss.AdaptiveColor{
		Dark:  "244",
		Light: "250",
	}

	CurrentBackground            = Grey
	CurrentForeground            = White
	SelectedBackground           = lipgloss.Color("110")
	SelectedForeground           = Black
	CurrentAndSelectedBackground = lipgloss.Color("117")
	CurrentAndSelectedForeground = Black

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

	RunReportBackgroundColor   = EvenLighterGrey
	GroupReportBackgroundColor = EvenLighterGrey

	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

	Border      = Regular.Copy().Border(lipgloss.NormalBorder())
	ThickBorder = Regular.Copy().Border(lipgloss.ThickBorder()).BorderForeground(Violet)

	Title          = Padded.Copy().Foreground(White).Background(Purple)
	TitleCommand   = Padded.Copy().Foreground(White).Background(Blue)
	TitlePath      = Padded.Copy().Foreground(White).Background(modulePathColor)
	TitleWorkspace = Padded.Copy().Foreground(White).Background(Green)
	TitleID        = Padded.Copy().Foreground(White).Background(Green)
	TitleAddress   = Padded.Copy().Foreground(White).Background(Blue)
	TitleSerial    = Padded.Copy().Foreground(White).Background(Orange)
	TitleTainted   = Padded.Copy().Foreground(White).Background(Red)

	RunReportStyle = Padded.Copy().Background(EvenLighterGrey)
)

Functions

func Ago

func Ago(now, t time.Time) string
func Breadcrumbs(title string, res resource.Resource, crumbs ...string) string

func CmdHandler

func CmdHandler(msg tea.Msg) tea.Cmd
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 OpenEditor added in v0.2.0

func OpenEditor(path string) tea.Cmd

func ReportError

func ReportError(err error) tea.Cmd

func ReportInfo added in v0.1.4

func ReportInfo(msg string, args ...any) tea.Cmd

func YesNoPrompt added in v0.1.10

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

YesNoPrompt sends a message to enable the prompt widget, specifically asking the user for a yes/no answer. If yes is given then the action is invoked.

Types

type Cache added in v0.2.0

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

page Cache: not so much for performance but to retain memory of user actions, e.g. a user may select a particular row in a table, navigate away from the page and later return to the page, and they would expect the same row still to be selected.

func NewCache added in v0.2.0

func NewCache() *Cache

func (*Cache) Exists added in v0.2.0

func (c *Cache) Exists(page Page) bool

func (*Cache) Get added in v0.2.0

func (c *Cache) Get(page Page) tea.Model

func (*Cache) Put added in v0.2.0

func (c *Cache) Put(page Page, model tea.Model)

func (*Cache) Update added in v0.2.0

func (c *Cache) Update(key Page, msg tea.Msg) tea.Cmd

func (*Cache) UpdateAll added in v0.2.0

func (c *Cache) UpdateAll(msg tea.Msg) []tea.Cmd

type ErrorMsg

type ErrorMsg error

type FilterBlurMsg added in v0.1.9

type FilterBlurMsg struct{}

FilterBlurMsg is a request to unfocus the filter widget. It is not acknowledged.

type FilterCloseMsg added in v0.1.9

type FilterCloseMsg struct{}

FilterCloseMsg is a request to close the filter widget. It is not acknowledged.

type FilterFocusReqMsg added in v0.1.9

type FilterFocusReqMsg struct{}

FilterFocusReqMsg is a request to focus the filter widget.

type FilterKeyMsg added in v0.1.9

type FilterKeyMsg tea.KeyMsg

FilterKeyMsg is a key entered by the user into the filter widget

type Helpers

type Helpers struct {
	ModuleService    ModuleService
	WorkspaceService WorkspaceService
	RunService       RunService
	TaskService      TaskService
	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) CreateApplyTasks added in v0.3.4

func (h *Helpers) CreateApplyTasks(opts *run.CreateOptions, ids ...resource.ID) tea.Cmd

func (*Helpers) CreateTasks added in v0.2.0

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

func (*Helpers) CurrentWorkspaceName

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

func (*Helpers) GroupReport added in v0.2.0

func (h *Helpers) GroupReport(group *task.Group, table bool) string

RunReport renders a colored summary of a run's changes. Set table to true if the report is rendered within a table row.

func (*Helpers) LatestRunReport

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

func (*Helpers) Module added in v0.2.0

func (h *Helpers) Module(res resource.Resource) *module.Module

func (*Helpers) ModuleCurrentResourceCount added in v0.1.10

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

func (*Helpers) ModuleCurrentWorkspace added in v0.2.0

func (h *Helpers) ModuleCurrentWorkspace(mod *module.Module) *workspace.Workspace

func (*Helpers) ModulePath

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

func (*Helpers) Move added in v0.2.0

func (h *Helpers) Move(workspaceID resource.ID, from state.ResourceAddress) tea.Cmd

func (*Helpers) RunReport

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

RunReport renders a colored summary of a run's changes. Set table to true if the report is rendered within a table row.

func (*Helpers) TaskStatus added in v0.2.0

func (h *Helpers) TaskStatus(t *task.Task, background bool) string

TaskStatus provides a rendered colored task status.

func (*Helpers) TaskWorkspace added in v0.2.0

func (h *Helpers) TaskWorkspace(t *task.Task) (resource.Resource, bool)

TaskWorkspace retrieves either the task's workspace if it belongs to a workspace, or if it belongs to a module, then it retrieves the module's current workspace

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) 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
	WorkspaceListKind
	TaskListKind
	TaskKind
	TaskGroupListKind
	TaskGroupKind
	ResourceListKind
	ResourceKind
	LogListKind
	LogKind
)

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(id resource.ID, 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 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() ([]string, []string, 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
	Tag  int
}

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. Identifies the model maker to construct the page.
	Kind Kind
	// The ID of the resource for a model. In the case of global listings of
	// modules, workspaces, etc, this is the global resource.
	ID resource.ID
}

Page identifies an instance of a model

type Prompt added in v0.1.10

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

Prompt is a widget that prompts the user for input and triggers an action.

func NewPrompt added in v0.1.10

func NewPrompt(msg PromptMsg) (*Prompt, tea.Cmd)
func (p *Prompt) HandleBlink(msg tea.Msg) (cmd tea.Cmd)

HandleBlink handles the bubbletea blink message.

func (*Prompt) HandleKey added in v0.1.10

func (p *Prompt) HandleKey(msg tea.KeyMsg) (closePrompt bool, cmd tea.Cmd)

HandleKey handles the user key press, and returns a command to be run, and whether the prompt should be closed.

func (*Prompt) HelpBindings added in v0.1.10

func (p *Prompt) HelpBindings() []key.Binding

func (*Prompt) View added in v0.1.10

func (p *Prompt) View(width int) string

type PromptAction added in v0.1.10

type PromptAction func(text string) tea.Cmd

type PromptMsg added in v0.1.10

type PromptMsg struct {
	// Prompt to display to the user.
	Prompt string
	// Set initial value for the user to edit.
	InitialValue string
	// Action to carry out when key is pressed.
	Action PromptAction
	// Key that when pressed triggers the action and closes the prompt.
	Key key.Binding
	// Cancel is a key that when pressed skips the action and closes the prompt.
	Cancel key.Binding
	// CancelAnyOther, if true, checks if any key other than that specified in
	// Key is pressed. If so then the action is skipped and the prompt is
	// closed. Overrides Cancel key binding.
	CancelAnyOther bool
}

PromptMsg enables the prompt widget.

type RunService

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

type StateService

type StateService interface {
	Reload(workspaceID resource.ID) (*task.Task, error)
	Get(workspaceID resource.ID) (*state.State, error)
	GetResource(resourceID resource.ID) (*state.Resource, 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)
	Move(workspaceID resource.ID, src, dest state.ResourceAddress) (*task.Task, error)
}

type TaskService

type TaskService interface {
	Create(opts task.CreateOptions) (*task.Task, error)
	CreateGroup(cmd string, fn task.Func, ids ...resource.ID) (*task.Group, error)
	CreateDependencyGroup(cmd string, reverse bool, opts ...task.CreateOptions) (*task.Group, error)
	Retry(taskID resource.ID) (*task.Task, error)
	Counter() int
	Get(taskID resource.ID) (*task.Task, error)
	GetGroup(groupID resource.ID) (*task.Group, error)
	List(opts task.ListOptions) []*task.Task
	ListGroups() []*task.Group
	Cancel(taskID resource.ID) (*task.Task, error)
}

type Viewport added in v0.2.0

type Viewport struct {
	Autoscroll bool
	// contains filtered or unexported fields
}

Viewport is a wrapper of the upstream viewport bubble.

func NewViewport added in v0.2.0

func NewViewport(opts ViewportOptions) Viewport

func (*Viewport) AppendContent added in v0.2.0

func (m *Viewport) AppendContent(content string, finished bool) error

func (Viewport) Init added in v0.2.0

func (m Viewport) Init() tea.Cmd

func (*Viewport) SetDimensions added in v0.2.0

func (m *Viewport) SetDimensions(width, height int)

func (Viewport) Update added in v0.2.0

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

func (Viewport) View added in v0.2.0

func (m Viewport) View() string

type ViewportOptions added in v0.2.0

type ViewportOptions struct {
	Width      int
	Height     int
	JSON       bool
	Border     bool
	Autoscroll bool
	Spinner    *spinner.Model
}

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