prompt

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

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

View Source
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

func NewAsyncList(items chan interface{}, size int) (*AsyncList, error)

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

func (l *AsyncList) CanPageDown() bool

CanPageDown returns whether a list can still PageDown().

func (*AsyncList) CanPageUp added in v0.3.0

func (l *AsyncList) CanPageUp() bool

CanPageUp returns whether a list can still PageUp().

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) Cursor added in v0.3.0

func (l *AsyncList) Cursor() int

func (*AsyncList) Index added in v0.3.0

func (l *AsyncList) Index() int

Index returns the index of the item currently selected inside the searched list.

func (*AsyncList) Items added in v0.3.0

func (l *AsyncList) Items() ([]interface{}, 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.

func (*AsyncList) Matches added in v0.3.0

func (l *AsyncList) Matches(key interface{}) []int

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) Search added in v0.3.0

func (l *AsyncList) Search(term string)

Search allows the list to be filtered by a given term.

func (*AsyncList) SetCursor added in v0.3.0

func (l *AsyncList) SetCursor(i int)

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

func (l *AsyncList) SetStart(i int)

SetStart sets the current scroll position. Values out of bounds will be clamped.

func (*AsyncList) Size added in v0.3.0

func (l *AsyncList) Size() int

func (*AsyncList) Start added in v0.3.0

func (l *AsyncList) Start() int

Start returns the current render start position of the list.

func (*AsyncList) Update added in v0.3.0

func (l *AsyncList) Update() chan struct{}

type KeyBinding added in v0.2.1

type KeyBinding struct {
	Key     rune
	Display string
	Handler func(interface{}) error
	Desc    string
}

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

func (p *Prompt) ListSize() int

ListSize returns the size of the items that is renderer each time

func (*Prompt) Run added in v0.2.1

func (p *Prompt) Run(ctx context.Context) error

Run as name implies starts the prompt until it quits

func (*Prompt) SetExitMsg added in v0.2.1

func (p *Prompt) SetExitMsg(grid [][]term.Cell)

SetExitMsg adds a rendered cell grid to be printed after prompt is finished

func (*Prompt) SetState added in v0.2.1

func (p *Prompt) SetState(state *State)

SetState replaces the state of the prompt

func (*Prompt) State added in v0.2.1

func (p *Prompt) State() *State

State return the current replace-able vars as a struct

func (*Prompt) Stop added in v0.2.1

func (p *Prompt) Stop()

Stop sends a quit signal to the main loop of the prompt

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

func NewList(items interface{}, size int) (*SyncList, error)

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

func (l *SyncList) CanPageDown() bool

CanPageDown returns whether a list can still PageDown().

func (*SyncList) CanPageUp added in v0.3.0

func (l *SyncList) CanPageUp() bool

CanPageUp returns whether a list can still PageUp().

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) Cursor added in v0.3.0

func (l *SyncList) Cursor() int

func (*SyncList) Index added in v0.3.0

func (l *SyncList) Index() int

Index returns the index of the item currently selected inside the searched list.

func (*SyncList) Items added in v0.3.0

func (l *SyncList) Items() ([]interface{}, 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.

func (*SyncList) Matches added in v0.3.0

func (l *SyncList) Matches(item interface{}) []int

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) Search added in v0.3.0

func (l *SyncList) Search(term string)

Search allows the list to be filtered by a given term.

func (*SyncList) SetCursor added in v0.3.0

func (l *SyncList) SetCursor(i int)

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

func (l *SyncList) SetStart(i int)

SetStart sets the current scroll position. Values out of bounds will be clamped.

func (*SyncList) Size added in v0.3.0

func (l *SyncList) Size() int

func (*SyncList) Start added in v0.3.0

func (l *SyncList) Start() int

Start returns the current render start position of the list.

func (*SyncList) Update added in v0.3.0

func (l *SyncList) Update() chan struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL