modes

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package mode implements modes, which are widgets tailored for a specific task.

Index

Constants

This section is empty.

Variables

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

View Source
var Prompt = modePrompt

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

Functions

func ErrorText added in v0.18.0

func ErrorText(err error) ui.Text

ErrorText returns a red "error:" followed by unstyled space and err.Error().

func FocusedCodeArea

func FocusedCodeArea(a cli.App) (tk.CodeArea, error)

FocusedCodeArea returns a CodeArea widget if the currently focused widget is a CodeArea. Otherwise it returns the error ErrFocusedWidgetNotCodeArea.

Types

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

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

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)
	// 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
	// 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

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, error)

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(chdir func(string) error) 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
	// Configuration for the filter.
	Filter FilterSpec
	// RPrompt of the code area (first row of the widget).
	CodeAreaRPrompt func() ui.Text
}

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.

Jump to

Keyboard shortcuts

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