Documentation
¶
Index ¶
- Variables
- func ClearLine(out io.Writer)
- func ClearToEndOfScreen(out io.Writer)
- func Confirm() clix.PromptOption
- func HideCursor(out io.Writer)
- func MoveCursorDown(out io.Writer, n int)
- func MoveCursorUp(out io.Writer, n int)
- func MultiSelect(options []clix.SelectOption) clix.PromptOption
- func RestoreCursorPosition(out io.Writer)
- func SaveCursorPosition(out io.Writer)
- func Select(options []clix.SelectOption) clix.PromptOption
- func ShowCursor(out io.Writer)
- func WithContinueText(text string) clix.PromptOption
- type Extension
- type Key
- type TerminalPrompter
- type TerminalState
Constants ¶
This section is empty.
Variables ¶
var ( KeyEnter = Key{'\n', '\n'} KeyEscape = Key{0, 0x1b} KeyUp = Key{0, 0xF1} // Unique code for up arrow KeyDown = Key{0, 0xF2} // Unique code for down arrow KeyLeft = Key{0, 0xF3} // Unique code for left arrow KeyRight = Key{0, 0xF4} // Unique code for right arrow KeyHome = Key{0, 0xF5} // Unique code for home KeyEnd = Key{0, 0xF6} // Unique code for end KeyF1 = Key{0, 0xF7} // Unique code for F1 KeyF2 = Key{0, 0xF8} // Unique code for F2 KeyF3 = Key{0, 0xF9} // Unique code for F3 KeyF4 = Key{0, 0xFA} // Unique code for F4 KeyF5 = Key{0, 0xFB} // Unique code for F5 KeyF6 = Key{0, 0xFC} // Unique code for F6 KeyF7 = Key{0, 0xFD} // Unique code for F7 KeyF8 = Key{0, 0xFE} // Unique code for F8 KeyF9 = Key{0, 0xFF} // Unique code for F9 KeyF10 = Key{0, 0xE1} // Unique code for F10 KeyF11 = Key{0, 0xE2} // Unique code for F11 KeyF12 = Key{0, 0xE3} // Unique code for F12 KeyTab = Key{'\t', '\t'} KeyBackspace = Key{0x7f, 0x7f} KeyCtrlC = Key{0, 0x03} KeySpace = Key{' ', ' '} )
Special keys - using unique Code values so == comparison works
var KeyUnknown = Key{0, 0}
KeyUnknown represents an unknown key.
Functions ¶
func ClearToEndOfScreen ¶
ClearToEndOfScreen clears from cursor to end of screen.
func Confirm ¶
func Confirm() clix.PromptOption
Confirm creates a confirmation prompt option. Note: This is now also available in core as clix.WithConfirm(), but kept here for backward compatibility and as a convenience alias. Usage:
prompter.Prompt(ctx, clix.WithLabel("Continue?"), Confirm())
// or use clix.WithConfirm() directly
func MoveCursorDown ¶
MoveCursorDown moves the cursor down n lines.
func MoveCursorUp ¶
MoveCursorUp moves the cursor up n lines.
func MultiSelect ¶
func MultiSelect(options []clix.SelectOption) clix.PromptOption
MultiSelect creates a multi-select prompt option. This option is only valid when using the prompt extension (TerminalPrompter). Usage:
prompter.Prompt(ctx, clix.WithLabel("Select"), MultiSelect([]clix.SelectOption{...}))
func RestoreCursorPosition ¶
RestoreCursorPosition restores the cursor to a previously saved position.
func SaveCursorPosition ¶
SaveCursorPosition saves the current cursor position.
func Select ¶
func Select(options []clix.SelectOption) clix.PromptOption
Select creates a select prompt option. This option is only valid when using the prompt extension (TerminalPrompter). Usage:
prompter.Prompt(ctx, clix.WithLabel("Choose"), Select([]clix.SelectOption{...}))
func WithContinueText ¶
func WithContinueText(text string) clix.PromptOption
WithContinueText sets the text shown for the continue action in multi-select prompts. Usage:
prompter.Prompt(ctx, clix.WithLabel("Select"), MultiSelect([]clix.SelectOption{...}), WithContinueText("Finish"))
Types ¶
type Extension ¶
type Extension struct {
}
Extension replaces the default TextPrompter with TerminalPrompter, enabling advanced prompt features: select, multi-select, confirm, and raw terminal mode.
Without this extension, advanced prompt types (select, multi-select) return errors directing users to add the extension. With this extension, all prompt types are supported.
Example:
import (
"github.com/SCKelemen/clix"
"github.com/SCKelemen/clix/ext/prompt"
)
app := clix.NewApp("myapp")
app.AddExtension(prompt.Extension{})
// Now your app supports select, multi-select, and confirm prompts
// Use advanced prompts via the standard PromptRequest API:
result, err := app.Prompter.Prompt(ctx, clix.PromptRequest{
Label: "Choose an option",
Options: []clix.SelectOption{
{Label: "Option A", Value: "a"},
{Label: "Option B", Value: "b"},
},
})
// Or use the helper function for type-safe access:
if tp := prompt.AsTerminalPrompter(app.Prompter); tp != nil {
// Access TerminalPrompter-specific methods if needed
}
type Key ¶
Key represents a pressed key.
func ReadKey ¶
ReadKey reads a single keypress from the terminal, returning the key code and any special keys (arrows, enter, etc.)
func (Key) IsPrintable ¶
IsPrintable returns true if the key represents a printable character.
type TerminalPrompter ¶
TerminalPrompter implements Prompter with full support for text, select, multi-select, and confirm prompts, including raw terminal mode for interactive navigation.
func AsTerminalPrompter ¶
func AsTerminalPrompter(p clix.Prompter) *TerminalPrompter
AsTerminalPrompter safely casts a Prompter to TerminalPrompter. Returns nil if the prompter is not a TerminalPrompter (e.g., it's a TextPrompter). This allows you to access advanced prompt methods with compile-time safety.
Example:
if tp := prompt.AsTerminalPrompter(app.Prompter); tp != nil {
result, err := tp.PromptWithOptions(ctx, clix.PromptRequest{
TextPromptRequest: clix.TextPromptRequest{Label: "Choose"},
Options: []clix.SelectOption{{Label: "A", Value: "a"}},
})
}
func (TerminalPrompter) Prompt ¶
func (p TerminalPrompter) Prompt(ctx context.Context, opts ...clix.PromptOption) (string, error)
Prompt displays a prompt and reads the user's response. Supports all prompt types: text, select, multi-select, and confirm.
type TerminalState ¶
type TerminalState struct {
// contains filtered or unexported fields
}
TerminalState manages raw terminal mode for interactive prompts.
func EnableRawMode ¶
func EnableRawMode(in *os.File) (*TerminalState, error)
EnableRawMode enables raw terminal mode for reading individual keystrokes.
func (*TerminalState) Restore ¶
func (ts *TerminalState) Restore() error
Restore restores the terminal to its previous state.