Documentation
¶
Overview ¶
Package inquire provides line-oriented interactive CLI prompts that render inline at the current cursor, leaving answered questions as static scrollback.
TTY requirements ¶
Run requires both stdin and stdout to be terminals. Piping either stream returns ErrNotTerminal. Stderr may be redirected.
Interrupts ¶
Ctrl+C aborts the entire session and returns ErrInterrupted. Answers bound before the interrupt are kept; later prompts are not run.
See https://pkg.go.dev/github.com/burl/inquire/v2 for API reference.
Index ¶
- Variables
- type Option
- type Session
- func (s *Session) AnyKey(message string, more func(*widget.AnyKey)) *Session
- func (s *Session) Input(value *string, prompt string, more func(*widget.Input)) *Session
- func (s *Session) Menu(value *string, prompt string, more func(*widget.Menu)) *Session
- func (s *Session) Note(text string, more func(*widget.Note)) *Session
- func (s *Session) Run(ctx context.Context) error
- func (s *Session) Select(prompt string, more func(*widget.Select)) *Session
- func (s *Session) YesNo(value *bool, prompt string, more func(*widget.YesNo)) *Session
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotTerminal is returned when stdin or stdout is not a terminal. ErrNotTerminal = errors.New("inquire: stdin/stdout is not a terminal") // ErrInterrupted is returned when the user presses Ctrl+C. ErrInterrupted = errors.New("inquire: interrupted") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Session)
Option configures a query session.
func WithColor ¶
WithColor forces ANSI color on (true) or off (false). When unset, color follows NO_COLOR, TERM, and COLORTERM.
func WithOutput ¶
WithOutput sets the terminal output stream (must be a TTY for Run).
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a fluent builder for interactive prompts.
func Query ¶
Query builds an interactive prompt session.
Example (Chain) ¶
package main
import (
"github.com/burl/inquire/v2"
)
func main() {
var name string
var ok bool
// Widgets chain on Query; Run needs a real TTY in production.
_ = inquire.Query().
Input(&name, "what is your name", nil).
YesNo(&ok, "continue", nil)
}
Output:
Example (NotTerminal) ¶
package main
import (
"context"
"errors"
"fmt"
"github.com/burl/inquire/v2"
)
func main() {
err := inquire.Query().Run(context.TODO())
fmt.Println(errors.Is(err, inquire.ErrNotTerminal))
}
Output: true
Directories
¶
| Path | Synopsis |
|---|---|
|
Grail demo: Monty Python quest through every inquire widget.
|
Grail demo: Monty Python quest through every inquire widget. |
|
termui
command
Command termui exercises the inquire band layer: an inline menu that does not take over the full screen.
|
Command termui exercises the inquire band layer: an inline menu that does not take over the full screen. |
|
internal
|
|
|
termui
Package termui implements the inline terminal band layer for inquire.
|
Package termui implements the inline terminal band layer for inquire. |
|
Package widget provides configurable prompt types used with [inquire.Query].
|
Package widget provides configurable prompt types used with [inquire.Query]. |