package mode
import "src.elv.sh/pkg/cli/mode"
Package mode implements modes, which are widgets tailored for a specific task.
Package navigation provides the functionality of navigating the filesystem.
Index ¶
- func ModeLine(content string, space bool) ui.Text
- func ModePrompt(content string, space bool) func() ui.Text
- type Completion
- type CompletionItem
- type CompletionSpec
- 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
Package Files ¶
completion.go histlist.go histwalk.go instant.go lastcmd.go listing.go location.go mode.go navigation.go navigation_fs.go stub.go
func ModeLine ¶
ModeLine returns a text styled as a modeline.
func ModePrompt ¶
ModePrompt returns a callback suitable as the prompt in the codearea of a mode widget.
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 string // Style to use in the UI. ShowStyle ui.Style // 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 }
CompletionSpec specifies the configuration for the completion mode.
type Histlist ¶
Histlist is a mode for browsing history and selecting entries to insert. It is based on the ComboBox widget.
func NewHistlist ¶
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() ([]store.Cmd, error) // Dedup is called to determine whether deduplication should be done. // Defaults to true if unset. Dedup func() bool // MakeFilter is called with the filter content to get a predicate that // filters command texts. If unset, the predicate performs substring match. MakeFilter func(string) func(string) bool }
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 }
Histwalk is a mode for walking through history.
func NewHistwalk ¶
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 ¶
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 ¶
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 ¶
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) bool // 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 ¶
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 }
LocationSpec is the configuration to start the location history feature.
type LocationStore ¶
type LocationStore interface { Dirs(blacklist map[string]struct{}) ([]store.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 // SelectedName returns the currently selected name. It returns an empty // string if there is no selected name, which can happen if the current // directory is empty. () string // Select changes the selection. (f func(tk.ListBoxState) int) // ScrollPreview scrolls the preview. (delta int) // Ascend ascends to the parent directory. () // Descend descends into the currently selected child directory. () // MutateFiltering changes the filtering status. (f func(bool) bool) // MutateShowHidden changes whether hidden files - files whose names start // with ".", should be shown. (f func(bool) bool) }
func NewNavigation ¶
func NewNavigation(app cli.App, spec NavigationSpec) Navigation
NewNavigation creates a new navigation mode.
type NavigationCursor ¶
type NavigationCursor interface { // Current returns a File that represents the current directory. () (NavigationFile, error) // Parent returns a File that represents the parent directory. It may return // nil if the current directory is the root of the filesystem. () (NavigationFile, error) // Ascend navigates to the parent directory. () error // Descend navigates to the named child directory. (name string) error }
NavigationCursor represents a cursor for navigating in a potentially virtual filesystem.
func NewOSNavigationCursor ¶
func NewOSNavigationCursor() NavigationCursor
NewOSNavigationCursor returns a NavigationCursor backed by the OS.
type NavigationFile ¶
type NavigationFile interface { // Name returns the name of the file. () string // ShowName returns a styled filename. () ui.Text // IsDirDeep returns whether the file is itself a directory or a symlink to // a directory. () bool // Read returns either a list of File's if the File represents a directory, // a (possibly incomplete) slice of bytes if the File represents a normal // file, or an error if the File cannot be read. () ([]NavigationFile, []byte, error) }
NavigationFile represents a potentially virtual file.
type NavigationSpec ¶
type NavigationSpec struct { // Key bindings. tk.Bindings // Underlying filesystem. NavigationCursor // A function that returns the relative weights of the widths of the 3 // columns. If unspecified, the ratio is 1:3:4. func() [3]int }
NavigationSpec specifieis the configuration for the navigation mode.
type Stub ¶
Stub is a mode that just shows a modeline and keeps the focus on the code area. It is mainly useful to apply some special non-default bindings.
func NewStub ¶
NewStub creates a new Stub mode.
type StubSpec ¶
type StubSpec struct { // Key bindings. Bindings tk.Bindings // Name to show in the modeline. Name string }
StubSpec specifies the configuration for the stub mode.
Package mode imports 22 packages (graph) and is imported by 1 packages. Updated 4 days ago.
Tools for package owners.