Documentation ¶
Overview ¶
Package mode implements modes, which are widgets tailored for a specific task.
Index ¶
- Variables
- func ErrorText(err error) ui.Text
- func FocusedCodeArea(a cli.App) (tk.CodeArea, error)
- type Completion
- type CompletionItem
- type CompletionSpec
- type FilterSpec
- type Histlist
- type HistlistSpec
- type Histwalk
- type HistwalkSpec
- type Instant
- type InstantSpec
- type Lastcmd
- type LastcmdSpec
- type LastcmdStore
- type Listing
- type ListingItem
- type ListingSpec
- type Location
- type LocationSpec
- type LocationStore
- type LocationWSIterator
- type Navigation
- type NavigationCursor
- type NavigationFile
- type NavigationSpec
- type Stub
- type StubSpec
Constants ¶
This section is empty.
Variables ¶
var ErrFocusedWidgetNotCodeArea = errors.New("focused widget is not a code area")
ErrFocusedWidgetNotCodeArea is returned when an operation requires the focused widget to be a code area but it is not.
var Prompt = modePrompt
Prompt returns a callback suitable as the prompt in the codearea of a mode widget.
Functions ¶
Types ¶
type Completion ¶
Completion is a mode specialized for viewing and inserting completion candidates. It is based on the ComboBox widget.
func NewCompletion ¶
func NewCompletion(app cli.App, cfg CompletionSpec) (Completion, error)
NewCompletion starts the completion UI.
type CompletionItem ¶
type CompletionItem struct { // Used in the UI and for filtering. ToShow ui.Text // Used when inserting a candidate. ToInsert string }
CompletionItem represents a completion item, also known as a candidate.
type CompletionSpec ¶
type CompletionSpec struct { Bindings tk.Bindings Name string Replace diag.Ranging Items []CompletionItem Filter FilterSpec }
CompletionSpec specifies the configuration for the completion mode.
type FilterSpec ¶
type FilterSpec struct { // Called with the filter text to get the filter predicate. If nil, the // predicate performs substring match. Maker func(string) func(string) bool // Highlighter for the filter. If nil, the filter will not be highlighted. Highlighter func(string) (ui.Text, []ui.Text) }
FilterSpec specifies the configuration for the filter in listing modes.
type Histlist ¶
Histlist is a mode for browsing history and selecting entries to insert. It is based on the ComboBox widget.
func NewHistlist ¶
func NewHistlist(app cli.App, spec HistlistSpec) (Histlist, error)
NewHistlist creates a new histlist mode.
type HistlistSpec ¶
type HistlistSpec struct { // Key bindings. Bindings tk.Bindings // AllCmds is called to retrieve all commands. AllCmds func() ([]storedefs.Cmd, error) // Dedup is called to determine whether deduplication should be done. // Defaults to true if unset. Dedup func() bool // Configuration for the filter. Filter FilterSpec // RPrompt of the code area (first row of the widget). CodeAreaRPrompt func() ui.Text }
HistlistSpec specifies the configuration for the histlist mode.
type Histwalk ¶
type Histwalk interface { tk.Widget // Walk to the previous entry in history. Prev() error // Walk to the next entry in history. Next() error // Update buffer with current entry. Always returns a nil error. Accept() error }
Histwalk is a mode for walking through history.
func NewHistwalk ¶
func NewHistwalk(app cli.App, cfg HistwalkSpec) (Histwalk, error)
NewHistwalk creates a new Histwalk mode.
type HistwalkSpec ¶
type HistwalkSpec struct { // Key bindings. Bindings tk.Bindings // History store to walk. Store histutil.Store // Only walk through items with this prefix. Prefix string }
HistwalkSpec specifies the configuration for the histwalk mode.
type Instant ¶
Instant is a mode that executes code whenever it changes and shows the result.
func NewInstant ¶
func NewInstant(app cli.App, cfg InstantSpec) (Instant, error)
NewInstant creates a new instant mode.
type InstantSpec ¶
type InstantSpec struct { // Key bindings. Bindings tk.Bindings // The function to execute code and returns the output. Execute func(code string) ([]string, error) }
InstantSpec specifies the configuration for the instant mode.
type Lastcmd ¶
Lastcmd is a mode for inspecting the last command, and inserting part of all of it. It is based on the ComboBox widget.
func NewLastcmd ¶
func NewLastcmd(app cli.App, cfg LastcmdSpec) (Lastcmd, error)
NewLastcmd creates a new lastcmd mode.
type LastcmdSpec ¶
type LastcmdSpec struct { // Key bindings. Bindings tk.Bindings // Store provides the source for the last command. Store LastcmdStore // Wordifier breaks a command into words. Wordifier func(string) []string }
LastcmdSpec specifies the configuration for the lastcmd mode.
type LastcmdStore ¶
LastcmdStore is a subset of histutil.Store used in lastcmd mode.
type Listing ¶
Listing is a customizable mode for browsing through a list of items. It is based on the ComboBox widget.
func NewListing ¶
func NewListing(app cli.App, spec ListingSpec) (Listing, error)
NewListing creates a new listing mode.
type ListingItem ¶
type ListingItem struct { // Passed to the Accept callback in Config. ToAccept string // How the item is shown. ToShow ui.Text }
ListingItem is an item to show in the listing.
type ListingSpec ¶
type ListingSpec struct { // Key bindings. Bindings tk.Bindings // Caption of the listing. If empty, defaults to " LISTING ". Caption string // A function that takes the query string and returns a list of Item's and // the index of the Item to select. Required. GetItems func(query string) (items []ListingItem, selected int) // A function to call when the user has accepted the selected item. If the // return value is true, the listing will not be closed after accpeting. // If unspecified, the Accept function default to a function that does // nothing other than returning false. Accept func(string) // Whether to automatically accept when there is only one item. AutoAccept bool }
ListingSpec specifies the configuration for the listing mode.
type Location ¶
Location is a mode for viewing location history and changing to a selected directory. It is based on the ComboBox widget.
func NewLocation ¶
func NewLocation(app cli.App, cfg LocationSpec) (Location, error)
NewLocation creates a new location mode.
type LocationSpec ¶
type LocationSpec struct { // Key bindings. Bindings tk.Bindings // Store provides the directory history and the function to change directory. Store LocationStore // IteratePinned specifies pinned directories by calling the given function // with all pinned directories. IteratePinned func(func(string)) // IterateHidden specifies hidden directories by calling the given function // with all hidden directories. IterateHidden func(func(string)) // IterateWorksapce specifies workspace configuration. IterateWorkspaces LocationWSIterator // Configuration for the filter. Filter FilterSpec }
LocationSpec is the configuration to start the location history feature.
type LocationStore ¶
type LocationStore interface { Dirs(blacklist map[string]struct{}) ([]storedefs.Dir, error) Chdir(dir string) error Getwd() (string, error) }
LocationStore defines the interface for interacting with the directory history.
type LocationWSIterator ¶
LocationWSIterator is a function that iterates all workspaces by calling the passed function with the name and pattern of each kind of workspace. Iteration should stop when the called function returns false.
func (LocationWSIterator) Parse ¶
func (ws LocationWSIterator) Parse(path string) (kind, root string)
Parse returns whether the path matches any kind of workspace. If there is a match, it returns the kind of the workspace and the root. It there is no match, it returns "", "".
type Navigation ¶
type Navigation interface { tk.Widget // string if there is no selected name, which can happen if the current // directory is empty. SelectedName() string Select(f func(tk.ListBoxState) int) ScrollPreview(delta int) Ascend() Descend() MutateFiltering(f func(bool) bool) // with ".", should be shown. MutateShowHidden(f func(bool) bool) }
func NewNavigation ¶
func NewNavigation(app cli.App, spec NavigationSpec) (Navigation, error)
NewNavigation creates a new navigation mode.
type NavigationCursor ¶
type NavigationCursor interface { NavigationFile, error) // nil if the current directory is the root of the filesystem. Parent() (NavigationFile, error) Ascend() error Descend(name string) error }Current() (
NavigationCursor represents a cursor for navigating in a potentially virtual filesystem.
func NewOSNavigationCursor ¶
func NewOSNavigationCursor(chdir func(string) error) NavigationCursor
NewOSNavigationCursor returns a NavigationCursor backed by the OS.
type NavigationFile ¶
type NavigationFile interface { string ShowName() ui.Text // a directory. IsDirDeep() bool // a (possibly incomplete) slice of bytes if the File represents a normal // file, or an error if the File cannot be read. Read() ([]NavigationFile, []byte, error) }Name()
NavigationFile represents a potentially virtual file.
type NavigationSpec ¶
type NavigationSpec struct { tk.Bindings Cursor NavigationCursor // columns. If unspecified, the ratio is 1:3:4. WidthRatio func() [3]int Filter FilterSpec CodeAreaRPrompt func() ui.Text }Bindings
NavigationSpec specifieis the configuration for the navigation mode.