package cli
import "src.elv.sh/pkg/cli"
Package cli implements a generic interactive line editor.
Index ¶
Package Files ¶
app.go app_spec.go loop.go tty.go
type App ¶
type App interface { // ReadCode requests the App to read code from the terminal by running an // event loop. This function is not re-entrant. ReadCode() (string, error) // MutateState mutates the state of the app. MutateState(f func(*State)) // CopyState returns a copy of the a state. CopyState() State // CodeArea returns the codearea widget of the app. CodeArea() tk.CodeArea // SetAddon sets the current addon to the given widget. If there is an // existing addon, it is closed first. If the existing addon implements // interface{ Close(bool) }, the Close method is called with the accept // argument. To close the current addon without setting a new one, call // SetAddon(nil, accept). SetAddon(w tk.Widget, accept bool) // CommitEOF causes the main loop to exit with EOF. If this method is called // when an event is being handled, the main loop will exit after the handler // returns. CommitEOF() // CommitCode causes the main loop to exit with the current code content. If // this method is called when an event is being handled, the main loop will // exit after the handler returns. CommitCode() // Redraw requests a redraw. It never blocks and can be called regardless of // whether the App is active or not. Redraw() // RedrawFull requests a full redraw. It never blocks and can be called // regardless of whether the App is active or not. RedrawFull() // Notify adds a note and requests a redraw. Notify(note string) }
App represents a CLI app.
func NewApp ¶
NewApp creates a new App from the given specification.
type AppSpec ¶
type AppSpec struct { TTY TTY MaxHeight func() int RPromptPersistent func() bool BeforeReadline []func() AfterReadline []func(string) Highlighter Highlighter Prompt Prompt RPrompt Prompt GlobalBindings tk.Bindings CodeAreaBindings tk.Bindings Abbreviations func(f func(abbr, full string)) QuotePaste func() bool SmallWordAbbreviations func(f func(abbr, full string)) CodeAreaState tk.CodeAreaState State State }
AppSpec specifies the configuration and initial state for an App.
type Highlighter ¶
type Highlighter interface { // Get returns the highlighted code and any static errors. Get(code string) (ui.Text, []error) // LateUpdates returns a channel for delivering late updates. LateUpdates() <-chan struct{} }
Highlighter represents a code highlighter whose result can be delivered asynchronously.
type Prompt ¶
type Prompt interface { // Trigger requests a re-computation of the prompt. The force flag is set // when triggered for the first time during a ReadCode session or after a // SIGINT that resets the editor. Trigger(force bool) // Get returns the current prompt. Get() ui.Text // LastUpdates returns a channel for notifying late updates. LateUpdates() <-chan struct{} }
Prompt represents a prompt whose result can be delivered asynchronously.
func NewConstPrompt ¶
NewConstPrompt returns a Prompt that always shows the given text.
type State ¶
type State struct { // Notes that have been added since the last redraw. Notes []string // An addon widget. When non-nil, it is shown under the codearea widget and // terminal events are handled by it. // // The cursor is placed on the addon by default. If the addon widget // implements interface{ Focus() bool }, the Focus method is called to // determine that instead. Addon tk.Widget }
State represents mutable state of an App.
type TTY ¶
type TTY interface { // Setup sets up the terminal for the CLI app. // // This method returns a restore function that undoes the setup, and any // error during setup. It only returns fatal errors that make the terminal // unsuitable for later operations; non-fatal errors may be reported by // showing a warning message, but not returned. // // This method should be called before any other method is called. Setup() (restore func(), err error) // ReadEvent reads a terminal event. ReadEvent() (term.Event, error) // SetRawInput requests the next n ReadEvent calls to read raw events. It // is applicable to environments where events are represented as a special // sequences, such as VT100. It is a no-op if events are delivered as whole // units by the terminal, such as Windows consoles. SetRawInput(n int) // StopInput causes input delivery to be stopped. When this function // returns, the channel previously returned by StartInput will no longer // deliver input events. StopInput() // NotifySignals start relaying signals and returns a channel on which // signals are delivered. NotifySignals() <-chan os.Signal // StopSignals stops the relaying of signals. After this function returns, // the channel returned by NotifySignals will no longer deliver signals. StopSignals() // Size returns the height and width of the terminal. Size() (h, w int) // Buffer returns the current buffer. The initial value of the current // buffer is nil. Buffer() *term.Buffer // ResetBuffer resets the current buffer to nil without actuating any redraw. ResetBuffer() // UpdateBuffer updates the current buffer and draw it to the terminal. UpdateBuffer(bufNotes, bufMain *term.Buffer, full bool) error // ClearScreen clears the terminal screen and places the cursor at the top // left corner. ClearScreen() }
TTY is the type the terminal dependency of the editor needs to satisfy.
func NewTTY ¶
NewTTY returns a new TTY from input and output terminal files.
Directories ¶
Path | Synopsis |
---|---|
clitest | Package clitest provides utilities for testing cli.App. |
histutil | Package histutil provides utilities for working with command history. |
lscolors | Package lscolors provides styling of filenames based on file features. |
mode | Package mode implements modes, which are widgets tailored for a specific task. |
prompt | Package prompt provides an implementation of the cli.Prompt interface. |
term | Package term provides functionality for working with terminals. |
tk | Package tk is the toolkit for the cli package. |
Package cli imports 10 packages (graph) and is imported by 4 packages. Updated now.
Tools for package owners.