Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContinue can be returned from SelectStory function // to show the same dialog again. ErrContinue = errors.New("continue") // ErrReturn can be returned from SelectStory function // to return to the dialog one level higher. ErrReturn = errors.New("return") // ErrAbort can be returned from SelectStory function // to abort the dialog with panicking using prompt.ErrCanceled. ErrAbort = errors.New("abort") )
Functions ¶
Types ¶
type Dialog ¶ added in v0.17.0
type Dialog struct {
// contains filtered or unexported fields
}
Dialog represents a dialog to be used to let the user pick a single story from the list.
func NewDialog ¶ added in v0.17.0
func NewDialog() *Dialog
NewDialog creates and returns a new dialog with no options set.
func (*Dialog) NewSubdialog ¶ added in v0.17.0
NewSubdialog can be used to create a new dialog based on the current dialog. The option list is empty again, just the dialog depth is inherited.
func (*Dialog) PushOptions ¶ added in v0.17.0
func (dialog *Dialog) PushOptions(opts ...*DialogOption)
PushOptions can be used to add options to the option chain.
The dialog will try to find the matching option based on the order the options are matching, so in case there is an option matching any input pushed as the first option, no other option body will ever be executed.
type DialogOption ¶ added in v0.17.0
type DialogOption struct { // Description is the text the user is presented when the option is active. // The slice represents the lines of text printed to the user. Description []string // IsActive is a function that decides whether the option is active for the dialog. // When the option is not active, it is not presented to the user. It is handy // to limit the options when e.g. there are no stories and so on. IsActive func(stories []common.Story, depth int) bool // MatchesInput is a function that decides whether SelectStory should be executed. // It basically checks the input and when it matches, it returns true, otherwise // the input is passed to the next option in the chain. MatchesInput func(input string, stories []common.Story) bool // SelectStory represents the option body, the task being to pick a single story // from the given story list. The function can be pretty much anything // as long as it matches the signature. It can run a subdialog, filter stories etc. SelectStory func(input string, stories []common.Story, current *Dialog) (common.Story, error) }
DialogOption represents a single option the user has when presented with a dialog. It represents a single input choice and the associated action.
func NewFilterOption ¶ added in v0.17.0
func NewFilterOption() *DialogOption
NewFilterOption returns an option that can be used to filter stories by matching the title against the given regexp.
func NewIndexOption ¶ added in v0.17.0
func NewIndexOption() *DialogOption
NewIndexOption returns an option that can be used to choose a story by its index.
func NewReturnOrAbortOptions ¶ added in v0.17.0
func NewReturnOrAbortOptions() []*DialogOption
NewReturnOrAbortOptions returns a set of options that handle
- press Enter -> return one level up
- insert 'q' -> abort the dialog