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

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

func ModeLine(content string, space bool) ui.Text

ModeLine returns a text styled as a modeline.

func ModePrompt

func ModePrompt(content string, space bool) func() ui.Text

ModePrompt returns a callback suitable as the prompt in the codearea of a mode widget.

type Completion

type Completion interface {
    tk.ComboBox
}

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

type Histlist interface {
    tk.ComboBox
}

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() ([]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

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

type Instant interface {
    tk.Widget
}

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

type Lastcmd interface {
    tk.ComboBox
}

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

type LastcmdStore interface {
    Cursor(prefix string) histutil.Cursor
}

LastcmdStore is a subset of histutil.Store used in lastcmd mode.

type Listing

type Listing interface {
    tk.ComboBox
}

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) bool
    // Whether to automatically accept when there is only one item.
    AutoAccept bool
}

ListingSpec specifies the configuration for the listing mode.

type Location

type Location interface {
    tk.ComboBox
}

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
}

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

type LocationWSIterator func(func(kind, pattern string) bool)

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 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.
    SelectedName() string
    // Select changes the selection.
    Select(f func(tk.ListBoxState) int)
    // ScrollPreview scrolls the preview.
    ScrollPreview(delta int)
    // Ascend ascends to the parent directory.
    Ascend()
    // Descend descends into the currently selected child directory.
    Descend()
    // MutateFiltering changes the filtering status.
    MutateFiltering(f func(bool) bool)
    // MutateShowHidden changes whether hidden files - files whose names start
    // with ".", should be shown.
    MutateShowHidden(f func(bool) bool)
}

func NewNavigation

func NewNavigation(app cli.App, spec NavigationSpec) Navigation

NewNavigation creates a new navigation mode.

type NavigationCursor interface {
    // Current returns a File that represents the current directory.
    Current() (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.
    Parent() (NavigationFile, error)
    // Ascend navigates to the parent directory.
    Ascend() error
    // Descend navigates to the named child directory.
    Descend(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 interface {
    // Name returns the name of the file.
    Name() string
    // ShowName returns a styled filename.
    ShowName() ui.Text
    // IsDirDeep returns whether the file is itself a directory or a symlink to
    // a directory.
    IsDirDeep() 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.
    Read() ([]NavigationFile, []byte, error)
}

NavigationFile represents a potentially virtual file.

type NavigationSpec struct {
    // Key bindings.
    Bindings tk.Bindings
    // Underlying filesystem.
    Cursor NavigationCursor
    // A function that returns the relative weights of the widths of the 3
    // columns. If unspecified, the ratio is 1:3:4.
    WidthRatio func() [3]int
}

NavigationSpec specifieis the configuration for the navigation mode.

type Stub

type Stub interface {
    tk.Widget
}

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

func NewStub(cfg StubSpec) Stub

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.