Documentation ¶
Index ¶
- Variables
- func Hyperlink(url string, text ...string) string
- func NewVisualElement(renderFn RenderFn) *visualElement
- func Ptr[T any](value T) *T
- type Canvas
- type CanvasSize
- type Confirm
- type ConfirmOptions
- type CursorPosition
- type Printer
- type Prompt
- type PromptOptions
- type RenderFn
- type Select
- type SelectOptions
- type SetProgressFunc
- type Spinner
- func (s *Spinner) Render(printer Printer) error
- func (s *Spinner) Run(ctx context.Context, task func(context.Context) error) error
- func (s *Spinner) Start(ctx context.Context) error
- func (s *Spinner) Stop(ctx context.Context) error
- func (s *Spinner) UpdateText(text string)
- func (s *Spinner) WithCanvas(canvas Canvas) Visual
- type SpinnerOptions
- type Task
- type TaskList
- type TaskListOptions
- type TaskOptions
- type TaskState
- type Visual
- type VisualContext
Constants ¶
This section is empty.
Variables ¶
var BoldString = color.New(color.Bold).SprintfFunc()
var ErrCancelled = errors.New("cancelled by user")
Functions ¶
func NewVisualElement ¶
func NewVisualElement(renderFn RenderFn) *visualElement
Types ¶
type CanvasSize ¶
CanvasSize represents the size of the canvas.
type Confirm ¶
type Confirm struct {
// contains filtered or unexported fields
}
Confirm is a component for prompting the user to confirm a message.
func NewConfirm ¶
func NewConfirm(options *ConfirmOptions) *Confirm
NewConfirm creates a new Confirm instance.
func (*Confirm) WithCanvas ¶
WithCanvas sets the canvas for the Confirm component.
type ConfirmOptions ¶
type ConfirmOptions struct { // The writer to use for output (default: os.Stdout) Writer io.Writer // The reader to use for input (default: os.Stdin) Reader io.Reader // The default value to use for the prompt (default: nil) DefaultValue *bool // The message to display before the prompt Message string // The optional message to display when the user types ? (default: "") HelpMessage string // The optional hint text that display after the message (default: "[Type ? for hint]") Hint string // The optional placeholder text to display when the value is empty (default: "") PlaceHolder string }
ConfirmOptions represents the options for the Confirm component.
var DefaultConfirmOptions ConfirmOptions = ConfirmOptions{ Writer: os.Stdout, Reader: os.Stdin, }
type CursorPosition ¶
CursorPosition represents the position of the cursor on the canvas.
type Printer ¶
type Printer interface { internal.Cursor Fprintf(format string, a ...any) Fprintln(a ...any) ClearCanvas() CursorPosition() CursorPosition SetCursorPosition(position CursorPosition) Size() CanvasSize }
Printer is a base component for UX components that require a printer for rendering.
func NewPrinter ¶
NewPrinter creates a new Printer instance.
type Prompt ¶
type Prompt struct {
// contains filtered or unexported fields
}
Prompt is a component for prompting the user for input.
func NewPrompt ¶
func NewPrompt(options *PromptOptions) *Prompt
NewPrompt creates a new Prompt instance.
func (*Prompt) WithCanvas ¶
WithCanvas sets the canvas for the prompt.
type PromptOptions ¶
type PromptOptions struct { // The writer to use for output (default: os.Stdout) Writer io.Writer // The reader to use for input (default: os.Stdin) Reader io.Reader // The default value to use for the prompt (default: "") DefaultValue string // The message to display before the prompt Message string // The optional message to display when the user types ? (default: "") HelpMessage string // The optional hint text that display after the message (default: "[Type ? for hint]") Hint string // The optional placeholder text to display when the value is empty (default: "") PlaceHolder string // The optional validation function to use ValidationFn func(string) (bool, string) // The optional validation message to display when validation fails (default: "Invalid input") ValidationMessage string // The optional validation message to display when the value is empty and required (default: "This field is required") RequiredMessage string // Whether or not the prompt is required (default: false) Required bool // Whether or not to clear the prompt after completion (default: false) ClearOnCompletion bool // Whether or not to capture hint keys (default: true) IgnoreHintKeys bool }
PromptOptions represents the options for the Prompt component.
var DefaultPromptOptions PromptOptions = PromptOptions{ Writer: os.Stdout, Reader: os.Stdin, Required: false, ValidationMessage: "Invalid input", RequiredMessage: "This field is required", Hint: "[Type ? for hint]", ClearOnCompletion: false, IgnoreHintKeys: false, ValidationFn: func(input string) (bool, string) { return true, "" }, }
type Select ¶
type Select struct {
// contains filtered or unexported fields
}
Select is a component for prompting the user to select an option from a list.
func NewSelect ¶
func NewSelect(options *SelectOptions) *Select
NewSelect creates a new Select instance.
func (*Select) WithCanvas ¶
WithCanvas sets the canvas for the select component.
type SelectOptions ¶
type SelectOptions struct { // The writer to use for output (default: os.Stdout) Writer io.Writer // The reader to use for input (default: os.Stdin) Reader io.Reader // The default value to use for the prompt (default: nil) SelectedIndex *int // The message to display before the prompt Message string // The available options to display Allowed []string // The optional message to display when the user types ? (default: "") HelpMessage string // The optional hint text that display after the message (default: "[Type ? for hint]") Hint string // The maximum number of options to display at one time (default: 6) DisplayCount int // Whether or not to display the number prefix before each option (default: false) DisplayNumbers *bool // Whether or not to disable filtering (default: true) EnableFiltering *bool }
SelectOptions represents the options for the Select component.
type SetProgressFunc ¶
type SetProgressFunc func(string)
SetProgressFunc is a function that sets the progress of a task.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is a component for displaying a spinner.
func NewSpinner ¶
func NewSpinner(options *SpinnerOptions) *Spinner
NewSpinner creates a new Spinner instance.
func (*Spinner) UpdateText ¶
UpdateText updates the text of the spinner.
func (*Spinner) WithCanvas ¶
WithCanvas sets the canvas for the spinner.
type SpinnerOptions ¶
type SpinnerOptions struct { Animation []string Text string Interval time.Duration ClearOnStop bool Writer io.Writer }
SpinnerOptions represents the options for the Spinner component.
var DefaultSpinnerOptions SpinnerOptions = SpinnerOptions{ Animation: []string{"|", "/", "-", "\\"}, Text: "Loading...", Interval: 250 * time.Millisecond, Writer: os.Stdout, }
type Task ¶
type Task struct { Title string Action func(SetProgressFunc) (TaskState, error) State TaskState Error error // contains filtered or unexported fields }
Task represents a task in the task list.
type TaskList ¶
type TaskList struct {
// contains filtered or unexported fields
}
TaskList is a component for managing a list of tasks.
func NewTaskList ¶
func NewTaskList(options *TaskListOptions) *TaskList
NewTaskList creates a new TaskList instance.
func (*TaskList) AddTask ¶
func (t *TaskList) AddTask(options TaskOptions) *TaskList
AddTask adds a task to the task list and manages async/sync execution.
func (*TaskList) Run ¶
Run executes all async tasks first and then runs queued sync tasks sequentially.
func (*TaskList) WithCanvas ¶
WithCanvas sets the canvas for the TaskList component.
type TaskListOptions ¶
type TaskListOptions struct { // The writer to use for output (default: os.Stdout) Writer io.Writer MaxConcurrentAsync int SuccessStyle string ErrorStyle string WarningStyle string RunningStyle string SkippedStyle string PendingStyle string }
TaskListOptions represents the options for the TaskList component.
var DefaultTaskListOptions TaskListOptions = TaskListOptions{ Writer: os.Stdout, MaxConcurrentAsync: 5, SuccessStyle: color.GreenString("(✔) Done "), ErrorStyle: color.RedString("(x) Error "), WarningStyle: color.YellowString("(!) Warning "), RunningStyle: color.CyanString("(-) Running "), SkippedStyle: color.HiBlackString("(-) Skipped "), PendingStyle: color.HiBlackString("(o) Pending "), }
type TaskOptions ¶
type TaskOptions struct { Title string Action func(SetProgressFunc) (TaskState, error) Async bool }
TaskOptions represents the options for the Task component.
type VisualContext ¶
type VisualContext struct { // The size of the visual Size CanvasSize // The relative row position of the visual within the canvas Top int }