Documentation ¶
Overview ¶
Package prompt is a slightly modified version of promptui's list. The original version can be found at https://github.com/manifoldco/promptui A little copying is better than a little dependency. - Go proverbs.
Index ¶
- Constants
- type AsyncList
- func (l *AsyncList) CanPageDown() bool
- func (l *AsyncList) CanPageUp() bool
- func (l *AsyncList) CancelSearch()
- func (l *AsyncList) Cursor() int
- func (l *AsyncList) Index() int
- func (l *AsyncList) Items() ([]interface{}, int)
- func (l *AsyncList) Matches(key interface{}) []int
- func (l *AsyncList) Next()
- func (l *AsyncList) PageDown()
- func (l *AsyncList) PageUp()
- func (l *AsyncList) Prev()
- func (l *AsyncList) Search(term string)
- func (l *AsyncList) SetCursor(i int)
- func (l *AsyncList) SetStart(i int)
- func (l *AsyncList) Size() int
- func (l *AsyncList) Start() int
- func (l *AsyncList) Update() chan struct{}
- type KeyBinding
- type List
- type OptionalFunc
- type Options
- type Prompt
- type State
- type SyncList
- func (l *SyncList) CanPageDown() bool
- func (l *SyncList) CanPageUp() bool
- func (l *SyncList) CancelSearch()
- func (l *SyncList) Cursor() int
- func (l *SyncList) Index() int
- func (l *SyncList) Items() ([]interface{}, int)
- func (l *SyncList) Matches(item interface{}) []int
- func (l *SyncList) Next()
- func (l *SyncList) PageDown()
- func (l *SyncList) PageUp()
- func (l *SyncList) Prev()
- func (l *SyncList) Search(term string)
- func (l *SyncList) SetCursor(i int)
- func (l *SyncList) SetStart(i int)
- func (l *SyncList) Size() int
- func (l *SyncList) Start() int
- func (l *SyncList) Update() chan struct{}
Constants ¶
const NotFound = -1
NotFound is an index returned when no item was selected.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncList ¶ added in v0.3.0
type AsyncList struct {
// contains filtered or unexported fields
}
AsyncList holds a collection of items that can be displayed with an N number of visible items. The list can be moved up, down by one item of time or an entire page (ie: visible size). It keeps track of the current selected item.
func NewAsyncList ¶ added in v0.3.0
NewAsyncList creates and initializes a list of searchable items. The items attribute must be a slice type.
func (*AsyncList) CanPageDown ¶ added in v0.3.0
CanPageDown returns whether a list can still PageDown().
func (*AsyncList) CancelSearch ¶ added in v0.3.0
func (l *AsyncList) CancelSearch()
CancelSearch stops the current search and returns the list to its original order.
func (*AsyncList) Index ¶ added in v0.3.0
Index returns the index of the item currently selected inside the searched list.
func (*AsyncList) Items ¶ added in v0.3.0
Items returns a slice equal to the size of the list with the current visible items and the index of the active item in this list.
func (*AsyncList) Next ¶ added in v0.3.0
func (l *AsyncList) Next()
Next moves the visible list forward one item.
func (*AsyncList) PageDown ¶ added in v0.3.0
func (l *AsyncList) PageDown()
PageDown moves the visible list forward by x items. Where x is the size of the visible items on the list.
func (*AsyncList) PageUp ¶ added in v0.3.0
func (l *AsyncList) PageUp()
PageUp moves the visible list backward by x items. Where x is the size of the visible items on the list.
func (*AsyncList) Prev ¶ added in v0.3.0
func (l *AsyncList) Prev()
Prev moves the visible list back one item.
func (*AsyncList) SetCursor ¶ added in v0.3.0
SetCursor sets the position of the cursor in the list. Values out of bounds will be clamped.
func (*AsyncList) SetStart ¶ added in v0.3.0
SetStart sets the current scroll position. Values out of bounds will be clamped.
type KeyBinding ¶ added in v0.2.1
KeyBinding is used for mapping a key to a function
type List ¶
type List interface { // Next moves the visible list forward one item Next() // Prev moves the visible list back one item. Prev() // PageUp moves the visible list backward by x items. Where x is the size of the // visible items on the list PageUp() // PageDown moves the visible list forward by x items. Where x is the size of // the visible items on the list PageDown() // CanPageDown returns whether a list can still PageDown(). CanPageDown() bool // CanPageUp returns whether a list can still PageUp() CanPageUp() bool // Search allows the list to be filtered by a given term. Search(term string) // CancelSearch stops the current search and returns the list to its original order. CancelSearch() // Start returns the current render start position of the list. Start() int // SetStart sets the current scroll position. Values out of bounds will be clamped. SetStart(i int) // SetCursor sets the position of the cursor in the list. Values out of bounds will // be clamped. SetCursor(i int) // Index returns the index of the item currently selected inside the searched list Index() int // Items returns a slice equal to the size of the list with the current visible // items and the index of the active item in this list. Items() ([]interface{}, int) // Matches returns the matched items against a search term Matches(key interface{}) []int // Cursor is the current cursor position Cursor() int // Size is the number of items to be displayed Size() int Update() chan struct{} }
type OptionalFunc ¶ added in v0.2.1
type OptionalFunc func(*Prompt)
OptionalFunc handles functional arguments of the prompt
func WithInformation ¶ added in v0.2.1
func WithInformation(f informationRendererFunc) OptionalFunc
WithInformation adds additional information below to the prompt
func WithItemRenderer ¶ added in v0.2.1
func WithItemRenderer(f itemRendererFunc) OptionalFunc
WithItemRenderer to add your own implementation on rendering an Item
func WithSelectionHandler ¶ added in v0.2.1
func WithSelectionHandler(f selectionHandlerFunc) OptionalFunc
WithSelectionHandler adds a selection handler to the prompt
type Options ¶
type Options struct { LineSize int `default:"5"` StartInSearch bool DisableColor bool VimKeys bool `default:"true"` }
Options is the common options for building a prompt
type Prompt ¶ added in v0.2.1
type Prompt struct {
// contains filtered or unexported fields
}
Prompt is a interactive prompt for command-line
func Create ¶ added in v0.2.1
func Create(label string, opts *Options, list List, fs ...OptionalFunc) *Prompt
Create returns a pointer to prompt that is ready to Run
func (*Prompt) AddKeyBinding ¶ added in v0.2.1
func (p *Prompt) AddKeyBinding(b *KeyBinding) error
AddKeyBinding adds a key-function map to prompt
func (*Prompt) ListSize ¶ added in v0.2.1
ListSize returns the size of the items that is renderer each time
func (*Prompt) SetExitMsg ¶ added in v0.2.1
SetExitMsg adds a rendered cell grid to be printed after prompt is finished
type State ¶ added in v0.2.1
type State struct { List List SearchMode bool SearchStr string SearchLabel string Cursor int Scroll int ListSize int }
State holds the changeable vars of the prompt
type SyncList ¶ added in v0.3.0
type SyncList struct {
// contains filtered or unexported fields
}
SyncList holds a collection of items that can be displayed with an N number of visible items. The list can be moved up, down by one item of time or an entire page (ie: visible size). It keeps track of the current selected item.
func NewList ¶
NewList creates and initializes a list of searchable items. The items attribute must be a slice type.
func (*SyncList) CanPageDown ¶ added in v0.3.0
CanPageDown returns whether a list can still PageDown().
func (*SyncList) CancelSearch ¶ added in v0.3.0
func (l *SyncList) CancelSearch()
CancelSearch stops the current search and returns the list to its original order.
func (*SyncList) Index ¶ added in v0.3.0
Index returns the index of the item currently selected inside the searched list.
func (*SyncList) Items ¶ added in v0.3.0
Items returns a slice equal to the size of the list with the current visible items and the index of the active item in this list.
func (*SyncList) Next ¶ added in v0.3.0
func (l *SyncList) Next()
Next moves the visible list forward one item.
func (*SyncList) PageDown ¶ added in v0.3.0
func (l *SyncList) PageDown()
PageDown moves the visible list forward by x items. Where x is the size of the visible items on the list.
func (*SyncList) PageUp ¶ added in v0.3.0
func (l *SyncList) PageUp()
PageUp moves the visible list backward by x items. Where x is the size of the visible items on the list.
func (*SyncList) Prev ¶ added in v0.3.0
func (l *SyncList) Prev()
Prev moves the visible list back one item.
func (*SyncList) SetCursor ¶ added in v0.3.0
SetCursor sets the position of the cursor in the list. Values out of bounds will be clamped.
func (*SyncList) SetStart ¶ added in v0.3.0
SetStart sets the current scroll position. Values out of bounds will be clamped.