### Run a confirmation prompt example Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Full example demonstrating how to initialize and run a confirmation prompt to capture user input. ```go package main import ( "fmt" "github.com/erikgeiser/promptkit/confirmation" ) func main() { c := confirmation.New("Are you sure?", confirmation.Undecided) answer, err := c.RunPrompt() if err != nil { panic(err) } if answer { fmt.Println("You confirmed!") } else { fmt.Println("You declined.") } } ``` -------------------------------- ### Pre-select items in a multi-selection prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Example demonstrating how to pre-mark specific choices when the prompt starts. ```go items := []string{"Option A", "Option B", "Option C"} ms := selection.NewMulti("Select items:", items) ms.PreSelected = selection.PreSelect("Option A", "Option C") selected, _ := ms.RunPrompt() // "Option A" and "Option C" will be marked when prompt starts ``` -------------------------------- ### Multi-Prompt Integration Example Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Demonstrates managing state transitions between multiple prompt types in a single application. ```go package main import ( "fmt" tea "charm.land/bubbletea/v2" "github.com/erikgeiser/promptkit/selection" "github.com/erikgeiser/promptkit/textinput" "github.com/erikgeiser/promptkit/confirmation" ) type State int const ( StepName State = iota StepCategory StepConfirm StepDone ) type Model struct { currentStep State name string category string nameModel *textinput.Model categoryModel *selection.Model[string] confirmModel *confirmation.Model } func (m *Model) Init() tea.Cmd { m.nameModel = textinput.NewModel(textinput.New("Name:")) m.categoryModel = selection.NewModel(selection.New("Category:", []string{"A", "B"})) m.confirmModel = confirmation.NewModel(confirmation.New("Confirm?", confirmation.Undecided)) return m.nameModel.Init() } func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch m.currentStep { case StepName: _, cmd := m.nameModel.Update(msg) return m, cmd case StepCategory: _, cmd := m.categoryModel.Update(msg) return m, cmd case StepConfirm: _, cmd := m.confirmModel.Update(msg) return m, cmd } return m, nil } func (m *Model) View() string { switch m.currentStep { case StepName: return m.nameModel.View().String() case StepCategory: return m.categoryModel.View().String() case StepConfirm: return m.confirmModel.View().String() case StepDone: return fmt.Sprintf("Name: %s\nCategory: %s\n", m.name, m.category) } return "" } func main() { m := &Model{} p := tea.NewProgram(m) p.Run() } ``` -------------------------------- ### Example usage of selection prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/selection-prompt.md Demonstrates initializing and running a selection prompt to capture user input. ```go package main import ( "fmt" "github.com/erikgeiser/promptkit/selection" ) func main() { choices := []string{"Option A", "Option B", "Option C"} s := selection.New("Choose an option:", choices) choice, err := s.RunPrompt() if err != nil { panic(err) } fmt.Println("You selected:", choice) } ``` -------------------------------- ### Example: Using TextInput Model Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Demonstrates creating a program with a TextInput model and retrieving the final value. ```go package main import ( tea "charm.land/bubbletea/v2" "github.com/erikgeiser/promptkit/textinput" ) func main() { ti := textinput.New("Name:") m := textinput.NewModel(ti) p := tea.NewProgram(m) _, _ = p.Run() if m.Err == nil { name, _ := m.Value() // Use name } } ``` -------------------------------- ### NewValue Usage Example Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Demonstrates creating a Value from a boolean input. ```go defaultValue := confirmation.NewValue(true) // Yes // or defaultValue := confirmation.NewValue(false) // No ``` -------------------------------- ### Handle confirmation prompt execution Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Example showing how to run a prompt and handle the result or potential abort errors. ```go c := confirmation.New("Delete file?", confirmation.No) proceed, err := c.RunPrompt() if err != nil { // Handle abort or error return } if proceed { os.Remove("file.txt") } else { fmt.Println("Cancelled deletion") } ``` -------------------------------- ### Confirmation Model Usage Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Example of running a confirmation prompt within a Bubble Tea program. ```go package main import ( tea "charm.land/bubbletea/v2" "github.com/erikgeiser/promptkit/confirmation" ) func main() { c := confirmation.New("Delete?", confirmation.No) m := confirmation.NewModel(c) p := tea.NewProgram(m) _, _ = p.Run() if m.Err == nil { proceed, _ := m.Value() if proceed { // Perform deletion } } } ``` -------------------------------- ### Integrate Selection Model in Bubble Tea Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Example of wrapping a selection prompt in a Bubble Tea program and retrieving the result after execution. ```go package main import ( "fmt" tea "charm.land/bubbletea/v2" "github.com/erikgeiser/promptkit/selection" ) func main() { choices := []string{"Option 1", "Option 2", "Option 3"} s := selection.New("Choose:", choices) // Create model for use in larger TUI m := selection.NewModel(s) p := tea.NewProgram(m) _, _ = p.Run() // Retrieve selection after program exit if m.Err == nil { result, _ := m.Value() fmt.Println("Selected:", result) } } ``` -------------------------------- ### Inspect Error Chains Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/errors.md Example of checking for specific error types returned by RunPrompt(). ```go result, err := prompt.RunPrompt() // err could be: // 1. promptkit.ErrAborted — User cancelled // 2. validation error — Input didn't pass validation // 3. key map error — Configuration error // 4. fmt.Errorf("running prompt: %w", err) — Bubble Tea error // 5. nil — Success ``` -------------------------------- ### NewDefaultKeyMap Constructor Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/selection-prompt.md Initializes a KeyMap with standard default bindings. Use this to override specific keys as shown in the example. ```go func NewDefaultKeyMap() *KeyMap ``` ```go s := selection.New("Choose:", choices) s.KeyMap = selection.NewDefaultKeyMap() s.KeyMap.Select = []string{"enter", " "} // Allow space to select ``` -------------------------------- ### Get text input with validation Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Configures a text input prompt with a custom validation function. ```go ti := textinput.New("Email:") ti.Validate = func(s string) error { if !strings.Contains(s, "@") { return textinput.ErrInputValidation } return nil } email, _ := ti.RunPrompt() ``` -------------------------------- ### Define Lipgloss Color Codes Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Examples of using named colors, 256-color palette indices, and hex values for terminal styling. ```go // Named colors lipgloss.Color("red") lipgloss.Color("green") lipgloss.Color("blue") // ... etc // 256-color palette (0-255) lipgloss.Color("32") // Green lipgloss.Color("196") // Red lipgloss.Color("21") // Blue // Hex colors (True Color terminals) lipgloss.Color("#ff0000") // Red lipgloss.Color("#00ff00") // Green lipgloss.Color("#0000ff") // Blue ``` -------------------------------- ### Catch ErrAborted Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/errors.md Example of checking for the abort error using errors.Is. ```go import ( "errors" "github.com/erikgeiser/promptkit" ) result, err := prompt.RunPrompt() if errors.Is(err, promptkit.ErrAborted) { // User cancelled the prompt fmt.Println("Prompt was cancelled by user") return } if err != nil { // Other error panic(err) } ``` -------------------------------- ### Create and Run a Prompt in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/README.md Standard pattern for initializing, configuring, and executing a prompt. ```go // Create prompt with question and items prompt := prompttype.New(question, items) // Customize (optional) prompt.SomeField = customValue // Run and get result result, err := prompt.RunPrompt() if err != nil { // Handle error } // Use result ``` -------------------------------- ### Get password input Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Configures a text input prompt to hide characters and use a mask. ```go pwd := textinput.New("Password:") pwd.Hidden = true pwd.HideMask = '*' password, _ := pwd.RunPrompt() ``` -------------------------------- ### Initialize and run a text input prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Creates a new TextInput instance and executes it to capture user input. ```go package main import ( "fmt" "github.com/erikgeiser/promptkit/textinput" ) func main() { ti := textinput.New("Enter your name:") input, err := ti.RunPrompt() if err != nil { panic(err) } fmt.Println("Hello,", input) } ``` -------------------------------- ### Initialize a TextArea Prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Creates a new TextArea instance with a specified prompt string and custom height configuration. ```go package main import ( "fmt" "github.com/erikgeiser/promptkit/textinput" ) func main() { ta := textinput.NewArea("Enter your feedback:") ta.Height = 10 // Show 10 lines at a time feedback, err := ta.RunPrompt() if err != nil { panic(err) } fmt.Println("Feedback received:") fmt.Println(feedback) } ``` -------------------------------- ### MultiModel.Init Method Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Initializes the model, including templates and pre-selection state. ```go func (m *MultiModel[T]) Init() tea.Cmd ``` -------------------------------- ### Initialize a new Confirmation prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Creates a new confirmation prompt instance using the New constructor. ```go func New(prompt string, defaultValue Value) *Confirmation ``` -------------------------------- ### Implement a MultiSelection Program Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Demonstrates integrating a MultiSelection prompt into a Bubble Tea program. ```go package main import ( tea "charm.land/bubbletea/v2" "github.com/erikgeiser/promptkit/selection" ) func main() { items := []string{"Item 1", "Item 2", "Item 3"} ms := selection.NewMulti("Select items:", items) ms.MinSelections = 1 ms.MaxSelections = 2 m := selection.NewMultiModel(ms) p := tea.NewProgram(m) _, _ = p.Run() if m.Err == nil { selected, _ := m.Values() // Use selected items } } ``` -------------------------------- ### Model Initialization Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Initializes the model and templates. ```go func (m *Model) Init() tea.Cmd ``` -------------------------------- ### Create a Text Input Prompt in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Initializes a single-line text input prompt. ```go import "github.com/erikgeiser/promptkit/textinput" ti := textinput.New("What's your name?") name, _ := ti.RunPrompt() ``` -------------------------------- ### Configure Confirmation KeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/configuration.md Customize key bindings for yes, no, and toggle actions in a confirmation prompt. ```go c := confirmation.New("Confirm?", confirmation.Undecided) c.KeyMap.Yes = []string{"y", "Y", "1"} // '1' for yes c.KeyMap.No = []string{"n", "N", "0"} // '0' for no c.KeyMap.Toggle = []string{"tab", " "} // Space toggles ``` -------------------------------- ### Basic Selection Prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/configuration.md Initializes a selection prompt using default settings. ```go s := selection.New("Pick one:", []string{"A", "B", "C"}) // Uses all defaults result, _ := s.RunPrompt() ``` -------------------------------- ### Create a Confirmation Prompt in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Initializes a yes/no confirmation prompt with a default value. ```go import "github.com/erikgeiser/promptkit/confirmation" c := confirmation.New("Are you sure?", confirmation.No) proceed, _ := c.RunPrompt() ``` -------------------------------- ### Configure Selection KeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/configuration.md Customize key bindings for navigation and selection in a selection prompt. ```go s := selection.New("Choose:", choices) s.KeyMap.Down = []string{"down", "j"} // Multiple keys work s.KeyMap.Up = []string{"up", "k"} s.KeyMap.Select = []string{"enter", " "} // Space also selects s.KeyMap.ScrollDown = []string{"pgdown", "ctrl+d"} s.KeyMap.ScrollUp = []string{"pgup", "ctrl+u"} ``` -------------------------------- ### MultiModel.View Method Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Renders the current state of the multi-selection prompt. ```go func (m *MultiModel[T]) View() tea.View ``` -------------------------------- ### Initialize Default KeyMap in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Creates a new KeyMap with standard bindings and allows for custom key overrides. ```go c := confirmation.New("Continue?", confirmation.Undecided) c.KeyMap = confirmation.NewDefaultKeyMap() c.KeyMap.Yes = []string{"y", "Y", "1"} // Allow '1' for yes c.KeyMap.No = []string{"n", "N", "0"} // Allow '0' for no ``` -------------------------------- ### MultiModel.Init Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Initializes the model, templates, and applies pre-selection. ```APIDOC ## func (m *MultiModel[T]) Init() tea.Cmd ### Description Initializes the model, templates, and applies pre-selection. ### Returns - **tea.Cmd** - Initialization command ``` -------------------------------- ### Create a multi-selection prompt in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/README.md Initializes a multi-choice selection prompt with configurable minimum and maximum selection constraints. ```go import "github.com/erikgeiser/promptkit/selection" items := []string{"A", "B", "C", "D"} ms := selection.NewMulti("Select items:", items) ms.MinSelections = 1 ms.MaxSelections = 3 selected, err := ms.RunPrompt() // selected is []string with 1-3 items ``` -------------------------------- ### New Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Creates a new confirmation prompt instance with a specified prompt string and default value. ```APIDOC ## func New(prompt string, defaultValue Value) *Confirmation ### Description Creates a new confirmation prompt with sensible defaults. ### Parameters - **prompt** (string) - Required - Question text - **defaultValue** (Value) - Required - Initial selection (Yes, No, or Undecided) ### Returns - ***Confirmation** - Initialized confirmation prompt ``` -------------------------------- ### Execute Multi-Selection Prompt with Custom Types Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Demonstrates running a multi-selection prompt using a custom struct type for the selection choices. ```go type Product struct { ID int Name string } products := []Product{ {1, "Widget"}, {2, "Gadget"}, {3, "Tool"}, } ms := selection.NewMulti("Select products:", products) ms.MinSelections = 1 ms.MaxSelections = 3 selected, err := ms.RunPrompt() if err != nil { panic(err) } ``` -------------------------------- ### View project file structure Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/README.md Displays the directory layout of the PromptKit repository. ```text output/ ├── README.md (this file) ├── types.md (all type definitions) ├── errors.md (error reference) ├── configuration.md (configuration options) ├── api-reference/ │ ├── promptkit-core.md (core utilities) │ ├── selection-prompt.md (selection prompt) │ ├── multi-selection-prompt.md (multi-selection prompt) │ ├── textinput-prompt.md (text input) │ ├── textarea-prompt.md (text area) │ ├── confirmation-prompt.md (confirmation) │ └── models-bubbletea.md (Bubble Tea integration) ``` -------------------------------- ### Import PromptKit Packages Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Required imports for core functionality, specific prompt types, and Bubble Tea integration. ```go // Core utilities import "github.com/erikgeiser/promptkit" // Selection prompts import "github.com/erikgeiser/promptkit/selection" // Text input prompts import "github.com/erikgeiser/promptkit/textinput" // Confirmation prompts import "github.com/erikgeiser/promptkit/confirmation" // For Bubble Tea integration import tea "charm.land/bubbletea/v2" ``` -------------------------------- ### Model.Init Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Initializes the confirmation model. ```APIDOC ## func (m *Model) Init() tea.Cmd ### Description Initializes the model. ``` -------------------------------- ### New Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Creates a new text input prompt instance with the specified prompt text. ```APIDOC ## func New(prompt string) *TextInput ### Description Creates a new text input prompt with sensible defaults. ### Parameters - **prompt** (string) - Required - Question or prompt text ### Returns - ***TextInput** - Initialized text input prompt ``` -------------------------------- ### Create a Selection Prompt in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Initializes a selection prompt to pick one item from a provided slice of strings. ```go import "github.com/erikgeiser/promptkit/selection" s := selection.New("Pick one:", []string{"A", "B", "C"}) result, _ := s.RunPrompt() // result is "A", "B", or "C" ``` -------------------------------- ### Initialize Multi-Selection Key Map Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Creates a new MultiKeyMap with default bindings and allows for custom key overrides. ```go func NewDefaultMultiKeyMap() *MultiKeyMap ``` ```go ms := selection.NewMulti("Select:", choices) ms.KeyMap = selection.NewDefaultMultiKeyMap() ms.KeyMap.Toggle = []string{"space", "x"} // Allow 'x' to toggle ``` -------------------------------- ### Handle MultiSelection Constraint Errors Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/errors.md Demonstrates how to configure selection limits and handle errors when constraints are violated. ```go ms := selection.NewMulti("Select items:", items) ms.MinSelections = 2 ms.MaxSelections = 5 selected, err := ms.RunPrompt() if err != nil { // Error if user tries to submit with <2 or >5 items marked if errors.Is(err, promptkit.ErrAborted) { fmt.Println("Cancelled") } } ``` -------------------------------- ### Model.Init Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Initializes the model and templates. ```APIDOC ## func (m *Model) Init() tea.Cmd ### Description Initializes the model and templates. ### Returns - **tea.Cmd** - Initialization command ``` -------------------------------- ### Handle KeyMap Configuration Errors Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/errors.md Demonstrates how to detect specific KeyMap validation errors after running a prompt. ```go s := selection.New("Choose:", choices) s.KeyMap.Down = []string{} // Invalid - no down key result, err := s.RunPrompt() if err != nil { if strings.Contains(err.Error(), "no down key") { fmt.Println("KeyMap configuration error:", err) } } ``` -------------------------------- ### Define a detailed help text template Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Includes input validation feedback and help hints using color formatting functions. ```go ti.Template = ` {{ Bold .Prompt }} {{ Faint "Press Ctrl+H for help" }} {{ .Input -}} {{ if .ValidationError -}} {{ Foreground "196" "✗ " }}{{ .ValidationError }} {{ else -}} {{ Foreground "46" "✓ Valid" }} {{ end -}} ` ``` -------------------------------- ### Customize prompt key maps Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/README.md Define multiple key bindings for navigation and selection actions. ```go s := selection.New("Choose:", items) s.KeyMap.Down = []string{"down", "j", "ctrl+n"} // Multiple keys s.KeyMap.Up = []string{"up", "k", "ctrl+p"} s.KeyMap.Select = []string{"enter", " "} ``` -------------------------------- ### Default to Yes Configuration Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Configures the prompt to default to Yes. ```go c := confirmation.New("Install updates?", confirmation.Yes) // User can press Enter to confirm, or 'n' to decline install, _ := c.RunPrompt() ``` -------------------------------- ### Execute the confirmation prompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Method signature for executing the prompt and handling the returned boolean choice or potential errors. ```go func (c *Confirmation) RunPrompt() (bool, error) ``` -------------------------------- ### TextInput RunPrompt Method Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Executes the text input prompt and returns the string input or an error. ```go func (t *TextInput) RunPrompt() (string, error) ``` -------------------------------- ### Initialize Selection Model Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Constructor for creating a Bubble Tea model from a Selection prompt. ```go func NewModel[T any](selection *Selection[T]) *Model[T] ``` -------------------------------- ### Configure TextInput KeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/configuration.md Customize key bindings for movement, submission, and clearing in a text input prompt. ```go ti := textinput.New("Input:") ti.KeyMap.MoveBackward = []string{"left", "ctrl+h"} // Alt keys ti.KeyMap.MoveForward = []string{"right", "ctrl+l"} ti.KeyMap.Submit = []string{"enter", "ctrl+d"} ti.KeyMap.Clear = []string{"esc", "ctrl+u"} ``` -------------------------------- ### Test Error Handling Patterns in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/errors.md Demonstrates how to verify abort conditions and custom validation errors using the testing package. ```go import "testing" func TestAbortHandling(t *testing.T) { s := selection.New("Test", []string{"A", "B"}) // Inject error or abort condition _, err := s.RunPrompt() if !errors.Is(err, promptkit.ErrAborted) { t.Errorf("expected ErrAborted, got %v", err) } } func TestValidationError(t *testing.T) { ti := textinput.New("Test") ti.Validate = func(s string) error { if s != "expected" { return textinput.ErrInputValidation } return nil } // Simulate user input that fails validation } ``` -------------------------------- ### Model View Rendering Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Renders the current confirmation prompt view. ```go func (m *Model) View() tea.View ``` -------------------------------- ### Selection[T] RunPrompt Method Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Executes the selection prompt and returns the selected value or an error. ```go func (s *Selection[T]) RunPrompt() (T, error) ``` -------------------------------- ### Simple Confirmation Usage Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Basic implementation of a confirmation prompt. ```go package main import ( "github.com/erikgeiser/promptkit/confirmation" ) func main() { c := confirmation.New("Delete this file?", confirmation.No) confirmed, _ := c.RunPrompt() if confirmed { // Delete file } } ``` -------------------------------- ### Create New TextInput Model Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Instantiates a new model using the provided TextInput configuration. ```go func NewModel(ti *TextInput) *Model ``` -------------------------------- ### Access promptkit utility functions Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Provides a map of standard string and math functions available within templates. ```go template.FuncMap{ "Repeat": strings.Repeat, // Repeat(string, int) string "Join": strings.Join, // Join([]string, string) string "ToUpper": strings.ToUpper, // ToUpper(string) string "ToLower": strings.ToLower, // ToLower(string) string "TrimPrefix": strings.TrimPrefix, // TrimPrefix(string, string) string "TrimSuffix": strings.TrimSuffix, // TrimSuffix(string, string) string "Len": ansi.PrintableRuneWidth, // Len(string) int (ANSI-aware) "Min": func(a, b int) int, // Min(int, int) int "Max": func(a, b int) int, // Max(int, int) int "Add": func(a, b int) int, // Add(int, int) int "Sub": func(a, b int) int, // Sub(int, int) int "Mul": func(a, b int) int, // Mul(int, int) int } ``` -------------------------------- ### Handle selection prompt results Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/selection-prompt.md Shows how to handle the result of a prompt execution, including checking for user abortion. ```go var result string var err error choices := []string{"Yes", "No"} s := selection.New("Do you want to continue?", choices) result, err = s.RunPrompt() if errors.Is(err, promptkit.ErrAborted) { fmt.Println("Cancelled") } else if err != nil { panic(err) } else { fmt.Printf("Selected: %s\n", result) } ``` -------------------------------- ### New[T any](prompt string, choices []T) *Selection[T] Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/selection-prompt.md Creates a new selection prompt instance with the specified prompt text and a slice of selectable choices. ```APIDOC ## New[T any](prompt string, choices []T) *Selection[T] ### Description Creates a new selection prompt with sensible defaults. ### Parameters - **prompt** (string) - Required - Question or prompt text - **choices** ([]T) - Required - Slice of items to select from ### Returns - *Selection[T] - Initialized selection prompt ``` -------------------------------- ### Select multiple items with limits Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Configures a multi-selection prompt with minimum and maximum selection constraints. ```go ms := selection.NewMulti("Select 2-5 items:", items) ms.MinSelections = 2 ms.MaxSelections = 5 selected, _ := ms.RunPrompt() ``` -------------------------------- ### NewDefaultKeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/selection-prompt.md Initializes a new KeyMap instance with standard default key bindings for the selection prompt. ```APIDOC ## func NewDefaultKeyMap() *KeyMap ### Description Returns a KeyMap with sensible default key bindings. ### Returns - ***KeyMap** - Initialized key map with standard bindings ### Example ```go s := selection.New("Choose:", choices) s.KeyMap = selection.NewDefaultKeyMap() s.KeyMap.Select = []string{"enter", " "} // Allow space to select ``` ``` -------------------------------- ### Create a Custom Multi-Selection Template Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Implement a template for multi-selection prompts that tracks marked choices using the IsMarked helper function. ```go ms := selection.NewMulti("Select:", items) ms.Template = ` {{ Bold .Prompt }} {{ Faint (print "(" .NMarkedChoices " selected)") }} {{ range $i, $choice := .Choices -}} {{ if eq $.SelectedIndex $i -}} → {{ if IsMarked $choice -}}[x]{{ else -}}[ ]{{ end }} {{ .String }} {{ else -}} • {{ if IsMarked $choice -}}[x]{{ else -}}[ ]{{ end }} {{ .String }} {{ end }} {{ "\n" }} {{ end -}} ` selected, _ := ms.RunPrompt() ``` -------------------------------- ### NewArea Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Creates a new text area prompt instance with default settings. ```APIDOC ## func NewArea(prompt string) *TextArea ### Description Creates a new text area prompt with sensible defaults. ### Parameters - **prompt** (string) - Required - Question or prompt text ### Returns - `*TextArea` - Initialized text area prompt ``` -------------------------------- ### Basic Feedback Form Usage Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Demonstrates a standard implementation of a feedback form with a placeholder and fixed height. ```go package main import ( "fmt" "github.com/erikgeiser/promptkit/textinput" ) func main() { ta := textinput.NewArea("Enter your feedback:") ta.Placeholder = "Please describe your experience..." ta.Height = 8 feedback, _ := ta.RunPrompt() fmt.Println("Thank you for your feedback!") } ``` -------------------------------- ### NewDefaultKeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Initializes a KeyMap with standard default key bindings for confirmation prompts. ```APIDOC ## func NewDefaultKeyMap() ### Description Returns a KeyMap with sensible default key bindings for confirmation prompts. ### Returns *KeyMap — Initialized key map with standard bindings. ### Example ```go c := confirmation.New("Continue?", confirmation.Undecided) c.KeyMap = confirmation.NewDefaultKeyMap() c.KeyMap.Yes = []string{"y", "Y", "1"} // Allow '1' for yes c.KeyMap.No = []string{"n", "N", "0"} // Allow '0' for no ``` ``` -------------------------------- ### Apply Common Lipgloss Style Methods Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Methods for configuring colors, text effects, dimensions, and borders on a style object. ```go style := lipgloss.NewStyle() // Colors style = style.Foreground(lipgloss.Color("32")) // Green style = style.Background(lipgloss.Color("236")) // Dark gray // Text effects style = style.Bold() style = style.Italic() style = style.Underline() style = style.CrossOut() style = style.Faint() // Dimensions style = style.Width(20) style = style.Height(5) style = style.Padding(1, 2) style = style.Margin(1) // Borders style = style.Border(lipgloss.RoundedBorder()) ``` -------------------------------- ### RunPrompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Executes the text input prompt and captures user input. ```APIDOC ## func (t *TextInput) RunPrompt() (string, error) ### Description Executes the text input prompt and returns the entered text. ### Returns - **string** - User-entered text - **error** - Error if validation fails or prompt is aborted ### Errors - **promptkit.ErrAborted** - Prompt was aborted by user - **Validation error** - Error returned from the Validate function ``` -------------------------------- ### Use selection display template functions Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Functions for applying styles and checking scroll hint positions in selection templates. ```go Selected(*Choice) string // Apply SelectedChoiceStyle Unselected(*Choice) string // Apply UnselectedChoiceStyle IsScrollUpHintPosition(int) bool // Show scroll up hint at index IsScrollDownHintPosition(int) bool // Show scroll down hint at index ``` -------------------------------- ### RunPrompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Executes the multi-selection prompt and returns the user's selected values. ```APIDOC ## RunPrompt ### Description Executes the multi-selection prompt and returns the selected values. ### Signature `func (s *MultiSelection[T]) RunPrompt() ([]T, error)` ### Returns - `[]T` - Slice of selected values in original order - `error` - Error if validation fails or prompt is aborted ### Errors - `promptkit.ErrAborted` - Prompt was aborted by user - Validation errors (too few/many selections, key map validation) ``` -------------------------------- ### Create a Custom Selection Template Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Define a custom string template for a selection prompt to control the visual layout of choices and indicators. ```go s := selection.New("Choose:", items) s.Template = ` {{ Bold .Prompt }} {{ Faint (print "(" .NChoices "/" .NAllChoices ")") }} {{ range $i, $choice := .Choices -}} {{ if eq $.SelectedIndex $i -}} ▸ {{ (Selected $choice) }} {{ else -}} • {{ (Unselected $choice) }} {{ end }} {{ "\n" }} {{ end -}} ` result, _ := s.RunPrompt() ``` -------------------------------- ### Confirmation Model Methods Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Bubble Tea model implementation methods for the Confirmation component. ```go func (m *Model) Init() tea.Cmd func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) func (m *Model) View() tea.View func (m *Model) Value() (bool, error) ``` -------------------------------- ### Render Model View Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/models-bubbletea.md Renders the current selection prompt view based on terminal constraints and styling. ```go func (m *Model[T]) View() tea.View ``` -------------------------------- ### Model.View Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Renders the current text input prompt view. ```APIDOC ## func (m *Model) View() tea.View ### Description Renders the current text input prompt view. ### Returns - **tea.View** - Rendered view ``` -------------------------------- ### MultiModel.View Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Renders the current multi-selection prompt view. ```APIDOC ## func (m *MultiModel[T]) View() tea.View ### Description Renders the current multi-selection prompt view. ### Returns - **tea.View** - Rendered view ``` -------------------------------- ### RunPrompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Executes the text area prompt and captures user input. ```APIDOC ## func (t *TextArea) RunPrompt() (string, error) ### Description Executes the text area prompt and returns the entered text. ### Returns - `string` - User-entered text - `error` - Error if validation fails or prompt is aborted ### Errors - `promptkit.ErrAborted` - Prompt was aborted by user - Validation error from `Validate` function ``` -------------------------------- ### Model.View Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/selection-prompt.md Renders the current state of the selection prompt. ```APIDOC ## Model.View ### Description Renders the current selection prompt view. ### Signature `func (m *Model[T]) View() tea.View` ### Returns - **tea.View** - Rendered view ``` -------------------------------- ### NewDefaultMultiKeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Initializes a MultiKeyMap with standard default key bindings for multi-selection prompts. ```APIDOC ## NewDefaultMultiKeyMap ### Description Returns a MultiKeyMap with sensible default key bindings. ### Signature `func NewDefaultMultiKeyMap() *MultiKeyMap` ### Returns - `*MultiKeyMap` - Initialized key map with standard bindings ### Example ```go ms := selection.NewMulti("Select:", choices) ms.KeyMap = selection.NewDefaultMultiKeyMap() ms.KeyMap.Toggle = []string{"space", "x"} // Allow 'x' to toggle ``` ``` -------------------------------- ### TextArea Package Function Signatures Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Handles multi-line text area input prompts. ```go // Create new text area func NewArea(prompt string) *TextArea // Run text area prompt func (t *TextArea) RunPrompt() (string, error) // Create model for Bubble Tea func NewAreaModel(ta *TextArea) *AreaModel // Create key map with defaults func NewDefaultAreaKeyMap() *AreaKeyMap ``` -------------------------------- ### Display Project Directory Structure Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/INDEX.md Visual representation of the project's file hierarchy. ```text output/ ├── INDEX.md (this file) ├── README.md (overview & examples) ├── quick-reference.md (function signatures) ├── types.md (type definitions) ├── errors.md (error reference) ├── configuration.md (config options) ├── templates-and-styling.md (appearance customization) └── api-reference/ ├── promptkit-core.md (core utilities) ├── selection-prompt.md (single selection) ├── multi-selection-prompt.md (multiple selections) ├── textinput-prompt.md (single-line input) ├── textarea-prompt.md (multi-line input) ├── confirmation-prompt.md (yes/no dialog) └── models-bubbletea.md (Bubble Tea integration) ``` -------------------------------- ### NewDefaultKeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Initializes a KeyMap with standard key bindings compatible with common text editors. ```APIDOC ## func NewDefaultKeyMap() ### Description Returns a KeyMap with sensible default key bindings compatible with common text editors. ### Returns - `*KeyMap` — Initialized key map with standard bindings ### Example ```go ti := textinput.New("Input:") ti.KeyMap = textinput.NewDefaultKeyMap() ti.KeyMap.Submit = []string{"enter", "ctrl+d"} ``` ``` -------------------------------- ### As Bubble Tea Model Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Wraps a prompt as a Bubble Tea model for integration into larger TUI applications. ```go m := selection.NewModel(selection.New("Choose:", items)) p := tea.NewProgram(m) _, _ = p.Run() result, _ := m.Value() ``` -------------------------------- ### Model.View Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Renders the current confirmation prompt view. ```APIDOC ## func (m *Model) View() tea.View ### Description Renders the current confirmation prompt view. ### Returns - **tea.View** - Rendered view ``` -------------------------------- ### Initialize prompts with Go generics Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Use generics to define the data type for selection prompts. This ensures type safety across different input types. ```go selection.New[string]("String:", strings.Split(...)) selection.New[int]("Number:", []int{1,2,3}) type Item struct { Name string } selection.New[Item]("Item:", items) ``` -------------------------------- ### Initialize Default Area Key Map Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Creates an AreaKeyMap with standard bindings, which can be further customized. ```go func NewDefaultAreaKeyMap() *AreaKeyMap ``` ```go ta := textinput.NewArea("Feedback:") ta.KeyMap = textinput.NewDefaultAreaKeyMap() ta.KeyMap.Submit = []string{"ctrl+enter"} // Require Ctrl+Enter to submit ``` -------------------------------- ### RunPrompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Executes the confirmation prompt and returns the user's choice as a boolean. ```APIDOC ## func (c *Confirmation) RunPrompt() (bool, error) ### Description Executes the confirmation prompt and returns the user's choice. ### Returns - **bool** - true for Yes, false for No - **error** - Error if prompt is aborted or key map is invalid ### Errors - **promptkit.ErrAborted** - Prompt was aborted by user (Ctrl+C) - Validation errors from key map validation ``` -------------------------------- ### Handle Template Errors in Go Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/errors.md Demonstrates catching and identifying template-related errors during prompt execution. ```go s := selection.New("Choose:", choices) s.Template = "{{ InvalidFunction }}" result, err := s.RunPrompt() if err != nil && strings.Contains(err.Error(), "Template Error") { fmt.Println("Template syntax error:", err) } ``` -------------------------------- ### TextInput.RunPrompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Executes the text input prompt and returns the entered string. ```APIDOC ## func (t *TextInput) RunPrompt() (string, error) ### Description Executes the text input prompt and returns the entered string. ### Returns - **string** - The user input. - **error** - An error if the prompt fails. ``` -------------------------------- ### Core Package Function Signatures Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Provides utility functions for text formatting and template integration. ```go // Get template functions func UtilFuncMap() template.FuncMap // Text wrapping functions func WordWrap(input string, width int) string func HardWrap(input string, width int) string func Truncate(input string, width int) string // Type for wrap functions type WrapMode func(string, int) string // Error var ErrAborted = fmt.Errorf("prompt aborted") ``` -------------------------------- ### Selection with Pagination Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Sets the number of items displayed per page. ```go s := selection.New("Choose:", items) s.PageSize = 10 result, _ := s.RunPrompt() ``` -------------------------------- ### Configure Selection Wrap Modes Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/configuration.md Sets the wrapping behavior for selection prompts. Setting WrapMode to nil disables wrapping. ```go s := selection.New("Choose:", choices) // WordWrap (soft wrap at word boundary, hard wrap at width) s.WrapMode = promptkit.WordWrap // HardWrap (break at any character at width) s.WrapMode = promptkit.HardWrap // Truncate (cut off at width) s.WrapMode = promptkit.Truncate // Disable wrapping s.WrapMode = nil ``` -------------------------------- ### Selection Package Function Signatures Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Provides methods for creating and managing single or multi-selection prompts, including filtering and styling. ```go // Create new selection func New[T any](prompt string, choices []T) *Selection[T] // Run single-selection prompt func (s *Selection[T]) RunPrompt() (T, error) // Create model for Bubble Tea func NewModel[T any](selection *Selection[T]) *Model[T] // Pre-select helper for multi-selection func PreSelect[T comparable](preSelectedValues ...T) func(c *Choice[T]) bool // Create new multi-selection func NewMulti[T any](prompt string, choices []T) *MultiSelection[T] // Run multi-selection prompt func (s *MultiSelection[T]) RunPrompt() ([]T, error) // Create model for Bubble Tea func NewMultiModel[T any](ms *MultiSelection[T]) *MultiModel[T] // Filter functions func FilterContainsCaseInsensitive[T any](filter string, choice *Choice[T]) bool func FilterContainsCaseSensitive[T any](filter string, choice *Choice[T]) bool // Create key maps with defaults func NewDefaultKeyMap() *KeyMap func NewDefaultMultiKeyMap() *MultiKeyMap // Style functions func DefaultSelectedChoiceStyle[T any](c *Choice[T]) string func DefaultFinalChoiceStyle[T any](c *Choice[T]) string func DefaultCursorMarkedChoiceStyle[T any](c *Choice[T]) string func DefaultMarkedChoiceStyle[T any](c *Choice[T]) string ``` -------------------------------- ### Select a single item Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/00-START-HERE.md Basic implementation for creating a single-selection prompt. ```go s := selection.New("Choose:", items) result, _ := s.RunPrompt() ``` -------------------------------- ### Confirmation Package Function Signatures Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Manages boolean confirmation prompts with predefined Yes/No/Undecided values. ```go // Create confirmation value func NewValue(v bool) Value // Create new confirmation prompt func New(prompt string, defaultValue Value) *Confirmation // Run confirmation prompt func (c *Confirmation) RunPrompt() (bool, error) // Create model for Bubble Tea func NewModel(c *Confirmation) *Model // Create key map with defaults func NewDefaultKeyMap() *KeyMap // Predefined values var ( Yes = Value(&yes) // true No = Value(&no) // false Undecided = Value(nil) // neither ) ``` -------------------------------- ### Confirmation.RunPrompt Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Executes the confirmation prompt and returns a boolean result. ```APIDOC ## func (c *Confirmation) RunPrompt() (bool, error) ### Description Executes the confirmation prompt and returns a boolean result. ### Returns - **bool** - The confirmation result. - **error** - An error if the prompt fails. ``` -------------------------------- ### Confirmation Struct Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md The main struct representing a configurable confirmation prompt. ```go type Confirmation struct { // configuration fields } ``` -------------------------------- ### Confirmation Display Template Variables Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Variables available for rendering the Confirmation widget during the selection phase. ```go Prompt string // Configured prompt YesSelected bool // Yes currently selected NoSelected bool // No currently selected Undecided bool // Undecided (neither selected) DefaultYes bool // Yes is default value DefaultNo bool // No is default value DefaultUndecided bool // Undecided is default TerminalWidth int // Terminal width KeyMap *KeyMap // Configured key map ``` -------------------------------- ### Define a minimal selection template Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/templates-and-styling.md Uses a simple arrow indicator to highlight the currently selected item. ```go s.Template = ` {{ .Prompt }} {{ range $i, $choice := .Choices -}} {{ if eq $.SelectedIndex $i }}> {{ end }}{{ .String }} {{ end -}} ` ``` -------------------------------- ### TextArea Package Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Functions for creating and running multi-line text area prompts. ```APIDOC ## TextArea Package ### Functions - `NewArea(prompt string) *TextArea` - Creates a new text area. - `(t *TextArea) RunPrompt() (string, error)` - Executes the text area prompt. - `NewAreaModel(ta *TextArea) *AreaModel` - Creates a Bubble Tea model for text area. ``` -------------------------------- ### NewDefaultAreaKeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Initializes an AreaKeyMap with standard default key bindings for text area components. ```APIDOC ## func NewDefaultAreaKeyMap() ### Description Returns an AreaKeyMap with sensible default key bindings. ### Returns - `*AreaKeyMap` - Initialized key map with standard bindings ### Example ```go ta := textinput.NewArea("Feedback:") ta.KeyMap = textinput.NewDefaultAreaKeyMap() ta.KeyMap.Submit = []string{"ctrl+enter"} ``` ``` -------------------------------- ### NewMulti[T] Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Creates a new multi-selection prompt instance with the specified prompt text and available choices. ```APIDOC ## NewMulti[T] ### Description Creates a new multi-selection prompt with sensible defaults. ### Signature `func NewMulti[T any](prompt string, choices []T) *MultiSelection[T]` ### Parameters - **prompt** (string) - Required - Question or prompt text - **choices** ([]T) - Required - Slice of items to select from ### Returns - `*MultiSelection[T]` - Initialized multi-selection prompt ``` -------------------------------- ### NewModel Constructor Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/confirmation-prompt.md Creates a new confirmation model for use with Bubble Tea. ```go func NewModel(c *Confirmation) *Model ``` -------------------------------- ### MultiKeyMap Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/multi-selection-prompt.md Configuration structure defining key bindings for multi-selection prompt navigation and actions. ```APIDOC ## type MultiKeyMap ### Description Defines key bindings for multi-selection prompt navigation and action. ### Fields - **Down** ([]string) - Default: {"down"} - Move cursor down - **Up** ([]string) - Default: {"up"} - Move cursor up - **Select** ([]string) - Default: {"enter"} - Confirm selections - **Toggle** ([]string) - Default: {"space"} - Mark/unmark current choice - **Abort** ([]string) - Default: {"ctrl+c"} - Cancel the prompt - **ClearFilter** ([]string) - Default: {"esc"} - Clear filter text - **ScrollDown** ([]string) - Default: {"pgdown"} - Scroll down one page - **ScrollUp** ([]string) - Default: {"pgup"} - Scroll up one page ``` -------------------------------- ### Define KeyMap struct Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/types.md Configures key bindings for single-selection navigation and interaction. ```go type KeyMap struct { Down []string Up []string Select []string Abort []string ClearFilter []string ScrollDown []string ScrollUp []string } ``` -------------------------------- ### Execute prompt with custom validation Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textinput-prompt.md Demonstrates how to assign a custom validation function to the TextInput instance before running the prompt. ```go ti := textinput.New("Enter email:") ti.Validate = func(s string) error { if !strings.Contains(s, "@") { return textinput.ErrInputValidation } return nil } email, err := ti.RunPrompt() if err != nil { panic(err) } ``` -------------------------------- ### Render Model View Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/api-reference/textarea-prompt.md Renders the text area prompt view for the Bubble Tea runtime. ```go func (m *AreaModel) View() tea.View ``` -------------------------------- ### Confirmation Package Source: https://github.com/erikgeiser/promptkit/blob/main/_autodocs/quick-reference.md Functions for creating and running boolean confirmation prompts. ```APIDOC ## Confirmation Package ### Functions - `NewValue(v bool) Value` - Creates a confirmation value. - `New(prompt string, defaultValue Value) *Confirmation` - Creates a new confirmation prompt. - `(c *Confirmation) RunPrompt() (bool, error)` - Executes the confirmation prompt. - `NewModel(c *Confirmation) *Model` - Creates a Bubble Tea model for confirmation. ```