cliui

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfirmYes = "yes"
	ConfirmNo  = "no"
)

Variables

View Source
var (
	Canceled = xerrors.New("canceled")
)
View Source
var Styles = struct {
	Bold,
	Checkmark,
	Code,
	Crossmark,
	DateTimeStamp,
	Error,
	Field,
	Keyword,
	Paragraph,
	Placeholder,
	Prompt,
	FocusedPrompt,
	Fuchsia,
	Logo,
	Warn,
	Wrap lipgloss.Style
}{
	Bold:          lipgloss.NewStyle().Bold(true),
	Checkmark:     defaultStyles.Checkmark,
	Code:          defaultStyles.Code,
	Crossmark:     defaultStyles.Error.Copy().SetString("✘"),
	DateTimeStamp: defaultStyles.LabelDim,
	Error:         defaultStyles.Error,
	Field:         defaultStyles.Code.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}),
	Keyword:       defaultStyles.Keyword,
	Paragraph:     defaultStyles.Paragraph,
	Placeholder:   lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#585858", Dark: "#4d46b3"}),
	Prompt:        defaultStyles.Prompt.Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
	FocusedPrompt: defaultStyles.FocusedPrompt.Foreground(lipgloss.Color("#651fff")),
	Fuchsia:       defaultStyles.SelectedMenuItem.Copy(),
	Logo:          defaultStyles.Logo.SetString("Coder"),
	Warn:          lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"}),
	Wrap:          lipgloss.NewStyle().Width(80),
}

Styles compose visual elements of the UI!

Functions

func Agent

func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error

Agent displays a spinning indicator that waits for a workspace agent to connect.

func AllowSkipPrompt added in v0.6.0

func AllowSkipPrompt(cmd *cobra.Command)

func DisplayTable added in v0.8.6

func DisplayTable(out any, sort string, filterColumns []string) (string, error)

DisplayTable renders a table as a string. The input argument must be a slice of structs. At least one field in the struct must have a `table:""` tag containing the name of the column in the outputted table.

Nested structs are processed if the field has the `table:"$NAME,recursive"` tag and their fields will be named as `$PARENT_NAME $NAME`. If the tag is malformed or a field is marked as recursive but does not contain a struct or a pointer to a struct, this function will return an error (even with an empty input slice).

If sort is empty, the input order will be used. If filterColumns is empty or nil, all available columns are included.

func FilterTableColumns added in v0.5.6

func FilterTableColumns(header table.Row, columns []string) []table.ColumnConfig

FilterTableColumns returns configurations to hide columns that are not provided in the array. If the array is empty, no filtering will occur!

func ParameterSchema

func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.ParameterSchema) (string, error)

func Prompt

func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error)

Prompt asks the user for input.

func ProvisionerJob

func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOptions) error

ProvisionerJob renders a provisioner job with interactive cancellation.

func Select

func Select(cmd *cobra.Command, opts SelectOptions) (string, error)

Select displays a list of user options.

func Table added in v0.5.6

func Table() table.Writer

Table creates a new table with standardized styles.

func TableHeaders added in v0.9.2

func TableHeaders(tSlice any) ([]string, error)

TableHeaders returns the table header names of all fields in tSlice. tSlice must be a slice of some type.

func ValidateNotEmpty

func ValidateNotEmpty(s string) error

ValidateNotEmpty is a helper function to disallow empty inputs!

func Warn

func Warn(wtr io.Writer, header string, lines ...string)

Warn writes a log to the writer provided.

func WorkspaceBuild

func WorkspaceBuild(ctx context.Context, writer io.Writer, client *codersdk.Client, build uuid.UUID) error

func WorkspaceResources added in v0.4.1

func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource, options WorkspaceResourcesOptions) error

WorkspaceResources displays the connection status and tree-view of provided resources. ┌────────────────────────────────────────────────────────────────────────────┐ │ RESOURCE STATUS ACCESS │ ├────────────────────────────────────────────────────────────────────────────┤ │ google_compute_disk.root │ ├────────────────────────────────────────────────────────────────────────────┤ │ google_compute_instance.dev │ │ └─ dev (linux, amd64) ⦾ connecting [10s] coder ssh dev.dev │ ├────────────────────────────────────────────────────────────────────────────┤ │ kubernetes_pod.dev │ │ ├─ go (linux, amd64) ⦿ connected coder ssh dev.go │ │ └─ postgres (linux, amd64) ⦾ disconnected [4s] coder ssh dev.postgres │ └────────────────────────────────────────────────────────────────────────────┘

Types

type AgentOptions

type AgentOptions struct {
	WorkspaceName string
	Fetch         func(context.Context) (codersdk.WorkspaceAgent, error)
	FetchInterval time.Duration
	WarnInterval  time.Duration
}

type PromptOptions

type PromptOptions struct {
	Text      string
	Default   string
	Secret    bool
	IsConfirm bool
	Validate  func(string) error
}

PromptOptions supply a set of options to the prompt.

type ProvisionerJobOptions

type ProvisionerJobOptions struct {
	Fetch  func() (codersdk.ProvisionerJob, error)
	Cancel func() error
	Logs   func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error)

	FetchInterval time.Duration
	// Verbose determines whether debug and trace logs will be shown.
	Verbose bool
	// Silent determines whether log output will be shown unless there is an
	// error.
	Silent bool
}

type SelectOptions

type SelectOptions struct {
	Options []string
	// Default will be highlighted first if it's a valid option.
	Default    string
	Size       int
	HideSearch bool
}

type WorkspaceResourcesOptions added in v0.4.1

type WorkspaceResourcesOptions struct {
	WorkspaceName  string
	HideAgentState bool
	HideAccess     bool
	Title          string
	ServerVersion  string
}

Jump to

Keyboard shortcuts

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