Documentation ¶
Index ¶
- Variables
- func BlurCmd() tea.Msg
- func DefaultCostView(cost time.Duration, total, current, prevAmount int64) string
- func DefaultPercentAgeFunc(total, current int64, percent float64) string
- func DefaultRowRender(cursorSymbol string, hintSymbol string, choice string) string
- func FinishCmd() tea.Msg
- func FocusCmd() tea.Msg
- func IsFinish(status Status) bool
- func NewLineSuggestionRender(suggestionItems []string, a *Autocomplete) string
- func QuitCmd() tea.Msg
- func TabSuggestionRender(suggestionItems []string, a *Autocomplete) string
- type Autocomplete
- func (a *Autocomplete) Init() tea.Cmd
- func (a *Autocomplete) SetProgram(program *tea.Program)
- func (a *Autocomplete) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (a *Autocomplete) Value() string
- func (a *Autocomplete) View() string
- func (a *Autocomplete) WithCompleter(completer Completer) *Autocomplete
- func (a *Autocomplete) WithInput(input *Input) *Autocomplete
- func (a *Autocomplete) WithKeyMap(keyMap AutocompleteKeyMap) *Autocomplete
- func (a *Autocomplete) WithSelectionCreator(f func(suggester []string, a *Autocomplete) *Selection) *Autocomplete
- func (a *Autocomplete) WithSuggestionViewRender(f func(suggestionItems []string, a *Autocomplete) string) *Autocomplete
- type AutocompleteKeyMap
- type AutocompleteValCtx
- type Completer
- type Components
- type CursorMode
- type EchoMode
- type Input
- func (i *Input) Blink() bool
- func (i *Input) Blur()
- func (i *Input) Cursor() int
- func (i *Input) CursorEnd()
- func (i *Input) CursorMode() CursorMode
- func (i *Input) CursorStart()
- func (i *Input) Focus()
- func (i *Input) Focused() bool
- func (i *Input) Init() tea.Cmd
- func (i *Input) Reset()
- func (i *Input) SetCursor(pos int)
- func (i *Input) SetCursorMode(model CursorMode)
- func (i *Input) SetProgram(program *tea.Program)
- func (i *Input) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (i *Input) Value() string
- func (i *Input) View() string
- type InputKeyMap
- type PrintHelper
- func (p PrintHelper) Center(str string)
- func (p PrintHelper) Debug(format string, a ...any)
- func (p PrintHelper) Error(format string, a ...any)
- func (p PrintHelper) Failed(format string, a ...any)
- func (p PrintHelper) Fatal(format string, a ...any)
- func (p PrintHelper) GetProgram() *tea.Program
- func (p PrintHelper) Info(format string, a ...any)
- func (p PrintHelper) Print(str string)
- func (p PrintHelper) PrintWithPrefix(prefix, format string, a ...any)
- func (p PrintHelper) Success(format string, a ...any)
- func (p PrintHelper) Warn(format string, a ...any)
- type Progress
- func (pro *Progress) Change(amount int64)
- func (pro *Progress) Cost() time.Duration
- func (pro *Progress) Decr(amount int64)
- func (pro *Progress) DecrOne()
- func (pro *Progress) Done()
- func (pro *Progress) Incr(amount int64)
- func (pro *Progress) IncrOne()
- func (pro *Progress) Init() tea.Cmd
- func (pro *Progress) Println(args ...interface{})
- func (pro *Progress) SetProgram(program *tea.Program)
- func (pro *Progress) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (pro *Progress) View() string
- func (pro *Progress) ViewAs(percent float64, now time.Time, done bool) string
- func (pro *Progress) WithCostView(f func(cost time.Duration, total, current, prevAmount int64) string) *Progress
- func (pro *Progress) WithDefaultGradient() *Progress
- func (pro *Progress) WithDefaultScaledGradient() *Progress
- func (pro *Progress) WithDisableCostView() *Progress
- func (pro *Progress) WithDisablePercentage() *Progress
- func (pro *Progress) WithDoneView(f func() string) *Progress
- func (pro *Progress) WithEmpty(empty rune) *Progress
- func (pro *Progress) WithEmptyColor(empty string) *Progress
- func (pro *Progress) WithFull(full rune) *Progress
- func (pro *Progress) WithFullColor(full string) *Progress
- func (pro *Progress) WithGradient(colorA, colorB string) *Progress
- func (pro *Progress) WithPercentAgeFunc(f func(total int64, current int64, percent float64) string) *Progress
- func (pro *Progress) WithPercentAgeStyle(sty *style.Style) *Progress
- func (pro *Progress) WithQuitKey(key key.Binding) *Progress
- func (pro *Progress) WithScaledGradient(colorA, colorB string) *Progress
- func (pro *Progress) WithSolidFill(color string) *Progress
- func (pro *Progress) WithTickCostDelay(delay time.Duration) *Progress
- func (pro *Progress) WithTitleView(f func(done bool) string) *Progress
- func (pro *Progress) WithTotal(total int64) *Progress
- func (pro *Progress) WithWidth(w int) *Progress
- type ProgressMsg
- type RefreshPromptMsg
- type Selection
- type SelectionItem
- type SelectionKeyMap
- type Shape
- type Spinner
- type StartUp
- type Status
- type Suggester
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( InputDefaultRequired = false InputDefaultRequiredMsg = style.New().Fg(color.Red).Render("Input is required.") InputDefaultRequiredMsgKeepTime = time.Second * 3 InputDefaultStatus = Focus InputDefaultPrompt = "> " InputDefaultValue = strx.Empty InputDefaultBlinkSpeed = time.Millisecond * 530 InputDefaultEchoMode = EchoNormal InputDefaultEchoCharacter = '*' InputDefaultCharLimit = 0 InputDefaultPlaceholderStyle = style.New().Fg(color.Gray) InputDefaultPromptStyle = style.New() InputDefaultTextStyle = style.New() InputDefaultBackgroundStyle = style.New() InputDefaultCursorStyle = style.New() )
var ( PrefixFatal = style.New().Fg(color.Red).Render("FATAL ") PrefixError = style.New().Fg(color.RedPink).Render("ERROR ") PrefixWarn = style.New().Fg(color.Orange).Render("WARN ") PrefixInfo = style.New().Fg(color.Special).Render("INFO ") PrefixDebug = style.New().Fg(color.Gray).Render("DEBUG ") PrefixSuccess = style.New().Fg(color.Special).Render("SUCCESS ") PrefixFailed = style.New().Fg(color.Red).Render("FAILED ") )
default prefix
var ( ProgressDefaultTotal int64 = 100 ProgressDefaultCurrent int64 = 0 ProgressDefaultPercentAgeFunc = DefaultPercentAgeFunc ProgressDefaultPercentAgeStyle = style.New().Inline() ProgressDefaultWidth = 45 ProgressDefaultFull = '█' ProgressDefaultFullColor = "#7571F9" ProgressDefaultEmpty = '░' ProgressDefaultEmptyColor = "#606060" ProgressDefaultShowPercentage = true ProgressDefaultShowCost = true ProgressDefaultPrevAmount int64 = 0 ProgressDefaultCostView = DefaultCostView ProgressDefaultTickCostDelay = time.Millisecond * 100 )
var ( SelectionDefaultCursorSymbol = ">" SelectionDefaultUnCursorSymbol = " " SelectionDefaultCursorSymbolStyle = theme.DefaultTheme.CursorSymbolStyle SelectionDefaultChoiceTextStyle = theme.DefaultTheme.ChoiceTextStyle SelectionDefaultPrompt = "Please select options:" SelectionDefaultPromptStyle = style.New().Bold().Fg(color.White) SelectionDefaultHintSymbol = "✓" SelectionDefaultHintSymbolStyle = theme.DefaultTheme.MultiSelectedHintSymbolStyle SelectionDefaultUnHintSymbol = "✗" SelectionDefaultUnHintSymbolStyle = theme.DefaultTheme.UnHintSymbolStyle SelectionDefaultDisableOutPutResult = false SelectionDefaultPageSize = 5 SelectionDefaultHelp = help.New() SelectionDefaultRowRender = DefaultRowRender SelectionDefaultEnableFilter = true SelectionDefaultFilterInput = NewInput() SelectionDefaultFilterFunc = DefaultFilterFunc SelectionDefaultShowHelp = true )
var ( Line = Shape{ Frames: []string{"|", "/", "-", "\\"}, FPS: time.Second / 10, } Dot = Shape{ Frames: []string{"⣾ ", "⣽ ", "⣻ ", "⢿ ", "⡿ ", "⣟ ", "⣯ ", "⣷ "}, FPS: time.Second / 10, } MiniDot = Shape{ Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, FPS: time.Second / 12, } Jump = Shape{ Frames: []string{"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"}, FPS: time.Second / 10, } Pulse = Shape{ Frames: []string{"█", "▓", "▒", "░"}, FPS: time.Second / 8, } Points = Shape{ Frames: []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●"}, FPS: time.Second / 7, } Globe = Shape{ Frames: []string{"🌍", "🌎", "🌏"}, FPS: time.Second / 4, } Moon = Shape{ Frames: []string{"🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"}, FPS: time.Second / 8, } Monkey = Shape{ Frames: []string{"🙈", "🙉", "🙊"}, FPS: time.Second / 3, } Meter = Shape{ Frames: []string{ "▱▱▱", "▰▱▱", "▰▰▱", "▰▰▰", "▰▰▱", "▰▱▱", "▱▱▱", }, FPS: time.Second / 7, } Hamburger = Shape{ Frames: []string{"☱", "☲", "☴", "☲"}, FPS: time.Second / 3, } Running = Shape{ Frames: []string{emoji.Walking, emoji.Running}, FPS: time.Second / 6, } )
Some spinners to choose from. You could also make your own.
var ( SpinnerDefaultModel = spinner.New() SpinnerDefaultShape = Line SpinnerDefaultShapeStyle = theme.DefaultTheme.SpinnerShapeStyle SpinnerDefaultPrompt = "Loading..." SpinnerDefaultDisableOutPutResult = false SpinnerDefaultStatus = Normal )
var ( InterruptKey = key.NewBinding( key.WithKeys("ctrl+c"), key.WithHelp("^C", "kill program"), ) )
Functions ¶
func DefaultCostView ¶
func DefaultPercentAgeFunc ¶
func DefaultRowRender ¶
func NewLineSuggestionRender ¶
func NewLineSuggestionRender(suggestionItems []string, a *Autocomplete) string
func TabSuggestionRender ¶
func TabSuggestionRender(suggestionItems []string, a *Autocomplete) string
Types ¶
type Autocomplete ¶
type Autocomplete struct { /* custom */ Input *Input Suggester Suggester Completer Completer KeyMap AutocompleteKeyMap SelectionCreator func(options []string, a *Autocomplete) *Selection SuggestionViewRender func(suggestionItems []string, a *Autocomplete) string Padding int Program *tea.Program *PrintHelper Selection *Selection ShowSelection bool ShouldNewSelection bool }
func NewAutocomplete ¶
func NewAutocomplete(suggester Suggester) *Autocomplete
NewAutocomplete constructor
func (*Autocomplete) Init ¶
func (a *Autocomplete) Init() tea.Cmd
func (*Autocomplete) SetProgram ¶
func (a *Autocomplete) SetProgram(program *tea.Program)
func (*Autocomplete) View ¶
func (a *Autocomplete) View() string
func (*Autocomplete) WithCompleter ¶
func (a *Autocomplete) WithCompleter(completer Completer) *Autocomplete
WithCompleter DefaultCompleter
func (*Autocomplete) WithInput ¶
func (a *Autocomplete) WithInput(input *Input) *Autocomplete
func (*Autocomplete) WithKeyMap ¶
func (a *Autocomplete) WithKeyMap(keyMap AutocompleteKeyMap) *Autocomplete
WithKeyMap DefaultAutocompleteKeyMap
func (*Autocomplete) WithSelectionCreator ¶
func (a *Autocomplete) WithSelectionCreator(f func(suggester []string, a *Autocomplete) *Selection) *Autocomplete
WithSelectionCreator DefaultSelectionCreator
func (*Autocomplete) WithSuggestionViewRender ¶
func (a *Autocomplete) WithSuggestionViewRender(f func(suggestionItems []string, a *Autocomplete) string) *Autocomplete
WithSuggestionViewRender Two implementations are provided by default: NewLineSuggestionRender or TabSuggestionRender, of course you can also choose to implement your own `render`
type AutocompleteKeyMap ¶
type AutocompleteKeyMap struct { Quit key.Binding CloseSelection key.Binding Up key.Binding Down key.Binding Complete key.Binding GotoEnd key.Binding }
func DefaultAutocompleteKeyMap ¶
func DefaultAutocompleteKeyMap() AutocompleteKeyMap
type AutocompleteValCtx ¶
type AutocompleteValCtx struct { Cursor int Value string // contains filtered or unexported fields }
func (AutocompleteValCtx) CursorVal ¶
func (a AutocompleteValCtx) CursorVal() string
CursorVal a.Value[:a.Cursor]
func (AutocompleteValCtx) CursorWord ¶
func (a AutocompleteValCtx) CursorWord() string
CursorWord current word
type Completer ¶
type Completer func(valCtx AutocompleteValCtx, choiceWord string) (newVal string, newCursor int)
Completer result (newValue,newCursor) DefaultCompleter
func DefaultCompleter ¶
func DefaultCompleter() Completer
type Components ¶
type Components interface { tea.Model // SetProgram this method will be called back when the tea.Program starts. // please keep passing this method SetProgram(program *tea.Program) }
Components, You can use these components directly:
- Input
- Selection
- Spinner
- Autocomplete
- Progress
Or use them inline in your custom component, for how to embed them, you can refer to the implementation of `Confirm`.
type CursorMode ¶
type CursorMode int
CursorMode describes the behavior of the cursor.
const ( CursorBlink CursorMode = iota CursorStatic CursorHide )
func (CursorMode) Map ¶
func (c CursorMode) Map() textinput.CursorMode
func (CursorMode) String ¶
func (c CursorMode) String() string
String returns the cursor mode in a human-readable format. This method is provisional and for informational purposes only.
type EchoMode ¶
type EchoMode int
EchoMode sets the Input behavior of the text Input field.
const ( // EchoNormal displays text as is. This is the default behavior. EchoNormal EchoMode = iota // EchoPassword displays the EchoCharacter mask instead of actual // characters. This is commonly used for password fields. EchoPassword // EchoNone displays nothing as characters are entered. This is commonly // seen for password fields on the command line. EchoNone )
type Input ¶
type Input struct { Model textinput.Model FocusPrompt string UnFocusPrompt string OutputResult bool Required bool RequiredMsg string RequiredMsgKeepAliveTime time.Duration BlinkSpeed time.Duration Status Status EchoMode EchoMode EchoCharacter rune // CharLimit is the maximum amount of characters this Input element will // accept. If 0 or less, there's no limit. CharLimit int Prompt string DefaultValue string PromptStyle *style.Style DefaultValueStyle *style.Style FocusSymbol string UnFocusSymbol string FocusInterval string UnFocusInterval string FocusSymbolStyle *style.Style UnFocusSymbolStyle *style.Style FocusIntervalStyle *style.Style UnFocusIntervalStyle *style.Style TextStyle *style.Style BackgroundStyle *style.Style CursorStyle *style.Style KeyMap InputKeyMap // contains filtered or unexported fields }
Input the Input component.
func (*Input) Blur ¶
func (i *Input) Blur()
Blur removes the Focus state on the model. When the model is blurred it can not receive keyboard Input and the cursor will be hidden.
func (*Input) CursorEnd ¶
func (i *Input) CursorEnd()
CursorEnd moves the cursor to the end of the Input field.
func (*Input) CursorMode ¶
func (i *Input) CursorMode() CursorMode
CursorMode returns the model's cursor mode. For available cursor modes, see type CursorMode.
func (*Input) CursorStart ¶
func (i *Input) CursorStart()
CursorStart moves the cursor to the start of the Input field.
func (*Input) Focus ¶
func (i *Input) Focus()
Focus sets the Focus state on the model. When the model is in Focus it can receive keyboard Input and the cursor will be hidden.
func (*Input) Reset ¶
func (i *Input) Reset()
Reset sets the Input to its default state with no Input. Returns whether or not the cursor blink should reset.
func (*Input) SetCursor ¶
SetCursor moves the cursor to the given position. If the position is out of bounds the cursor will be moved to the start or end accordingly.
func (*Input) SetCursorMode ¶
func (i *Input) SetCursorMode(model CursorMode)
SetCursorMode sets the model's cursor mode. This method returns a command.
For available cursor modes, see type CursorMode.
func (*Input) SetProgram ¶
type InputKeyMap ¶
func InputDefaultKeyMap ¶
func InputDefaultKeyMap() InputKeyMap
type PrintHelper ¶
type PrintHelper struct {
// contains filtered or unexported fields
}
PrintHelper Used for thread-safe output when running the Components
func NewPrintHelper ¶
func NewPrintHelper(program *tea.Program) *PrintHelper
NewPrintHelper constructor
func (PrintHelper) Center ¶
func (p PrintHelper) Center(str string)
func (PrintHelper) Debug ¶
func (p PrintHelper) Debug(format string, a ...any)
func (PrintHelper) Error ¶
func (p PrintHelper) Error(format string, a ...any)
func (PrintHelper) Failed ¶
func (p PrintHelper) Failed(format string, a ...any)
func (PrintHelper) Fatal ¶
func (p PrintHelper) Fatal(format string, a ...any)
func (PrintHelper) GetProgram ¶
func (p PrintHelper) GetProgram() *tea.Program
func (PrintHelper) Info ¶
func (p PrintHelper) Info(format string, a ...any)
func (PrintHelper) Print ¶
func (p PrintHelper) Print(str string)
func (PrintHelper) PrintWithPrefix ¶
func (p PrintHelper) PrintWithPrefix(prefix, format string, a ...any)
func (PrintHelper) Success ¶
func (p PrintHelper) Success(format string, a ...any)
func (PrintHelper) Warn ¶
func (p PrintHelper) Warn(format string, a ...any)
type Progress ¶
type Progress struct { *PrintHelper Id int // the progress total Total int64 // Current amount Current int64 // kill program Quit key.Binding // Total width of the progress bar, including percentage, if set. Width int // "Filled" sections of the progress bar. Full rune FullColor string // "Empty" sections of progress bar. Empty rune EmptyColor string ShowPercentage bool PercentAgeFunc func(total, current int64, percent float64) string PercentAgeStyle *style.Style ShowCost bool CostView func(cost time.Duration, total, current, prevAmount int64) string TickCostDelay time.Duration DoneView func() string TitleView func(done bool) string // contains filtered or unexported fields }
func (*Progress) Cost ¶
Cost the progress cost. plz make sure Progress.end and Progress.start are not null
func (*Progress) SetProgram ¶
func (*Progress) WithCostView ¶
func (pro *Progress) WithCostView(f func(cost time.Duration, total, current, prevAmount int64) string) *Progress
WithCostView append cost view.
func (*Progress) WithDefaultGradient ¶
WithDefaultGradient sets a gradient fill with default colors.
func (*Progress) WithDefaultScaledGradient ¶
WithDefaultScaledGradient sets a gradient with default colors, and scales the gradient to fit the filled portion of the ramp.
func (*Progress) WithDisableCostView ¶
WithDisableCostView disable cost view
func (*Progress) WithDisablePercentage ¶
WithDisablePercentage disable output percentage.
func (*Progress) WithDoneView ¶
WithDoneView when Group is done, will callback this func.
func (*Progress) WithEmptyColor ¶
WithEmptyColor default "#606060"
func (*Progress) WithFullColor ¶
WithFullColor default "#7571F9"
func (*Progress) WithGradient ¶
WithGradient sets a gradient fill blending between two colors.
func (*Progress) WithPercentAgeFunc ¶
func (pro *Progress) WithPercentAgeFunc(f func(total int64, current int64, percent float64) string) *Progress
WithPercentAgeFunc default DefaultPercentAgeFunc
func (*Progress) WithPercentAgeStyle ¶
WithPercentAgeStyle replace percentage style
func (*Progress) WithQuitKey ¶
WithQuitKey replace `Quit` key, user interrupt, kill program.
func (*Progress) WithScaledGradient ¶
WithScaledGradient scales the gradient to fit the width of the filled portion of the progress bar.
func (*Progress) WithSolidFill ¶
WithSolidFill sets the progress to use a solid fill with the given color.
func (*Progress) WithTickCostDelay ¶
WithTickCostDelay defaultTicKCostDelay the interval time between each refresh cost time
func (*Progress) WithTitleView ¶
WithTitleView append title view.
type ProgressMsg ¶
type RefreshPromptMsg ¶
type RefreshPromptMsg string
type Selection ¶
type Selection struct { // result Selected map[int]struct{} Choices []SelectionItem Validators []Validator // how many options to display at a time PageSize int DisableOutPutResult bool // key binding Keymap SelectionKeyMap // key Help text Help help.Model ShowHelp bool Prompt string Header string CursorSymbol string UnCursorSymbol string HintSymbol string UnHintSymbol string PromptStyle *style.Style CursorSymbolStyle *style.Style HintSymbolStyle *style.Style UnHintSymbolStyle *style.Style ChoiceTextStyle *style.Style // RowRender output options // CursorSymbol,HintSymbol,choice RowRender func(CursorSymbol string, HintSymbol string, choice string) string EnableFilter bool FilterInput *Input FilterFunc func(input string, items []SelectionItem) []SelectionItem FocusSymbol string UnFocusSymbol string FocusInterval string UnFocusInterval string FocusSymbolStyle *style.Style UnFocusSymbolStyle *style.Style FocusIntervalStyle *style.Style UnFocusIntervalStyle *style.Style ValueStyle *style.Style // contains filtered or unexported fields }
func DefaultSelectionCreator ¶
func DefaultSelectionCreator(suggester []string, a *Autocomplete) *Selection
func (*Selection) SetProgram ¶
type SelectionItem ¶
func DefaultFilterFunc ¶
func DefaultFilterFunc(input string, items []SelectionItem) []SelectionItem
type SelectionKeyMap ¶
type SelectionKeyMap struct { Up key.Binding Down key.Binding Choice key.Binding Confirm key.Binding // kill program Quit key.Binding }
func DefaultMultiKeyMap ¶
func DefaultMultiKeyMap() SelectionKeyMap
func DefaultSingleKeyMap ¶
func DefaultSingleKeyMap() SelectionKeyMap
func (SelectionKeyMap) FullHelp ¶
func (k SelectionKeyMap) FullHelp() [][]key.Binding
func (SelectionKeyMap) ShortHelp ¶
func (k SelectionKeyMap) ShortHelp() []key.Binding
type Spinner ¶
type Spinner struct { *PrintHelper Model spinner.Model // user interrupt, kill program. Quit key.Binding Shape Shape ShapeStyle *style.Style Prompt string DisableOutPutResult bool Status Status // contains filtered or unexported fields }
func (*Spinner) RefreshPrompt ¶
RefreshPrompt refresh prompt.
func (*Spinner) SetProgram ¶
type StartUp ¶
func NewStartUp ¶
func NewStartUp(c Components, ops ...tea.ProgramOption) *StartUp
NewStartUp new StartUp
func (*StartUp) Start ¶
Start Deprecated: please use StartUp.Run instead.
type Suggester ¶
type Suggester func(valCtx AutocompleteValCtx) ([]string, bool)
Suggester get suggest options
type Validator ¶
type Validator func(ans interface{}) error
Validator is a function passed to a Question after a user has provided a response. If the function returns an error, then the user will be prompted again for another response.