Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSave is returned when trying to save a tab that it's not a file // in the file system. ErrInvalidSave = errors.New("cannot flush this content") // ErrInvalidReload is returned when trying to reload a tab that it's not a file // in the file system. ErrInvalidReload = errors.New("cannot reload this content") // ErrInvalidSplit is returned when attempting to split over a floating window. ErrInvalidSplit = errors.New("cannot split this window") // ErrInvalidOverwrite is returned when trying to overwrite a tab that it's not a file // in the file system. ErrInvalidOverwrite = errors.New("cannot overwrite this content") )
Functions ¶
This section is empty.
Types ¶
type CellEditor ¶
type CellEditor interface {
Edit(ctx context.Context, start, end term.Coordinates, str string) (
from, to term.Coordinates, old string, err error,
)
}
CellEditor is a cell.Editor that can fail.
type Command ¶
type Command struct {
Name string
Args []string
// optional. If command is dispatched while non-tab is in focus,
// then these fields will be zero-valued.
URI workspaceapi.URI
Resource Handler
Window browserapi.Window
Cursor struct {
Content term.Coordinates
Window term.Coordinates
}
}
Command represents a command issued by the user.
type CommandHandler ¶
type CommandHandler interface {
// Handle is called when user issued a command previously
// registered via SubscribeCommand.
HandleCommand(context.Context, Command) (err error)
// Complete takes command args and returns a list of expanded
// options for them.
// It also returns a expanded version of the last arg, or an
// empty string if the last arg could/should not be
// automatically expanded.
Complete(ctx context.Context, cmd string, args []string) (
iterator.Iterator[string], error,
)
}
CommandHandler is a callback interface that wraps the basic method Command.
func FuncCommandHandler ¶
func FuncCommandHandler( fn func(context.Context, Command) error, completer func( context.Context, string, []string, ) (iterator.Iterator[string], error), ) CommandHandler
FuncCommandHandler returns an CommandHandler that calls fn every time HandleCommand is invoked and completer when Complete is invoked.
func NopCommandCompleter ¶
func NopCommandCompleter( fn func(context.Context, Command) error, ) CommandHandler
NopCommandCompleter returns an CommandHandler that calls fn every time HandleCommand is invoked, but does not have a completion function.
type CommandManual ¶
type CommandManual struct {
Name string
// Summary is a short 80-100 character description.
Summary string
// Synopsis is a single line synopsis of how
// this CLI is to be used. It should ONLY include
// the semantic information about how arguments are parsed.
//
// Example: [<options>] [<revision-range>] [[--] <path>...]
Synopsis string
// Commands is a list of accepted commands or nil
// if no commands are expected.
Commands []CommandManual
}
CommandManual represents a command's manual and documentation.
type CommandRegistry ¶ added in v0.0.58
type CommandRegistry interface {
// RegisterCommand registers a command to be dispatched
// to CommandHandler. Registered commands appear in the
// command prompt. Use RegisterCommand for editing and
// live-programming actions that operate on the current
// file and need no persistent output, such as
// navigating to a symbol definition, toggling a fold, or
// reformatting a selection.
RegisterCommand(CommandManual, CommandHandler) error
// RegisterREPLCommand registers a REPL command to be
// dispatched to REPLHandler. Registered commands appear
// in the IDE's shell. Use RegisterREPLCommand for
// configuration, monitoring and troubleshooting commands
// that produce inspectable output the user wants to
// review, such as a debugger, a log viewer, or a status
// dashboard.
RegisterREPLCommand(CommandManual, REPLHandler) error
}
CommandRegistry abstracts the ability to register new commands.
type Editor ¶
type Editor interface {
// SubscribeEvents subscribes EventHandler to events of type EventType.
SubscribeEvents([]EventType, EventHandler) error
// Editor returns the editor.Handler that manages the given resource,
// if there is a resource currently open with the given URI.
Editor(resource workspaceapi.URI) (Handler, error)
// SetLocationList sets the Handler's location list for users to
// navigate the code. See LocationList for more details.
// In order to remove a location list, SetLocationList must be called
// with an empty (or nil) LocationList.
// Locations are removed if underlying buffer is updated. It is the
// responsibility of the caller to recompute the list of locations
// and call SetLocationList with the new list of locations after
// every update. Check cell.Buffer.Subscribe for more details.
SetLocationList(Handler, LocationPriority, string, LocationList) error
// Moves cursor to the next location on list with ID.
MoveToNextLocation(h Handler, ID string) error
// Moves cursor to the previous location on list with ID.
MoveToPrevLocation(h Handler, ID string) error
// Cursor gets the position of Handler's cursor in the underlying
// content buffer.
Cursor(Handler) (term.Coordinates, error)
// SetCursor sets the cursor of Handler to the given Coordinates.
SetCursor(Handler, term.Coordinates) error
// CellView returns a CellView which allows to read the editor's internal buffer.
CellView(Handler) CellView
// CellEditor returns a CellEditor which allows for direct write access
// to the editor's internal buffer.
CellEditor(Handler) CellEditor
// SetDefaultAttributes sets the default attributes of the given Handler
// before any LocationList overwrites.
SetDefaultAttributes(Handler, term.Attributes) error
}
Editor is the interface that wraps an API to manage a text editor.
type Event ¶
type Event struct {
Type EventType
URI workspaceapi.URI
Resource Handler
Start, End term.Coordinates
From, To term.Coordinates
Content string
}
Event encapsulates eventual information about a particular editor resource.
type EventHandler ¶
type EventHandler interface {
// Handle handles Event and returns true if it no longer needs to receive events,
// in other words it returns true if it's done processing events.
Handle(context.Context, Event) bool
}
EventHandler wraps the basic method Handle.
func FuncEventHandler ¶
func FuncEventHandler(fn func(context.Context, Event) bool) EventHandler
FuncEventHandler returns an EventHandler that calls fn every time Handle is invoked.
type EventType ¶
type EventType uint8
EventType is a type of editor event.
const ( // EventTypeOpen is dispatched when an editor is called the Edit method. // Content represents the initial content of the underlying resource. EventTypeOpen EventType = iota // EventTypeClose is dispatched when an editor buffer is closed. EventTypeClose // EventTypeFlush is dispatched when an editor buffer is Flushed. // Content represents the file content that was flushed. EventTypeFlush // EventTypeCreate is dispatched when a watched resource is created out-of-band // or not in the workspace. EventTypeCreate // EventTypeChange is dispatched when a watched resource is updated out-of-band // or not in the workspace. EventTypeChange // EventTypeRemove is dispatched when a watched resource is removed out-of-band // or not in the workspace. EventTypeRemove // EventTypeRename is dispatched when a watched resource is renamed out-of-band // or not in the workspace. EventTypeRename // EventTypeEdit is dispatched when new content is inserted into an editor buffer. // Start, End represent the input to Edit whereas // From, To represent output coordinates. See cell.Editor.Edit for // more details. EventTypeEdit // EventTypeScroll is dispatched when content is scrolled to a new offset. // Start represents the new scroll offset, whereas From represents the // last offset position. EventTypeScroll // EventTypeHidden is dispatched when some content is hidden. // Start represents the start of the hidden block of lines, whereas End // represents the end of the hidden block. EventTypeHidden // EventTypeVisible is dispatched when some content is hidden. // Start represents the start of the hidden block of lines, whereas End // represents the end of the hidden block. EventTypeVisible // EventTypeFocus is dispatched when an editor handler is on browser.Focus. // Start contains the width (X) and height (Y) of the content in focus. // From contains the position of the cursor at that content focus. // If content is resized, EventTypeFocus is sent again, with the new dimensions. EventTypeFocus // EventTypeUnfocus is dispatched when an editor handler is not // on browser.Focus anymore. EventTypeUnfocus // EventTypeCursor is dispatched when the position of the cursor of an // editor Handler changes, either in the window coordinate system or the underlying // content position. Event.Start will be set to the cursor's window position, // and Event.From will be set to the cursor's scroll position. EventTypeCursor // EventTypeSelection is dispatched when the user selects a chunk of text. // Start, End represent the selection coordinates and Content contains // the content selected as a result. EventTypeSelection )
type Handler ¶
type Handler interface {
browserapi.Handler
// This is only used to differentiate editor.Handler from the rest
// of tui.Handler in a browser.Component.
Resource() workspaceapi.URI
}
Handler just wraps a tui.Handler to indicate that this API's handlers might not be compatible with other APIs.
type Location ¶
type Location struct {
From, To term.Coordinates
Attr term.Attributes
Message string
Icon string
}
Location represents a content location in an Editor's buffer. From is inclusive and To is exclusive: the range covers cells [From, To). A location where From == To is empty (spans zero cells) and will not match any cursor position.
type LocationList ¶
type LocationList interface {
Current() (Location, bool)
Prev() (Location, bool)
Next() (Location, bool)
}
LocationList is the interface that groups Prev and Next location methods to fetch the previous and next item respectively.
Both Prev/Next return false if reached either end or beginning of list.
Current returns the current result. If there are no results in the list then Current returns false.
func LocationSlice ¶
func LocationSlice(in []Location) LocationList
LocationSlice returns a LocationList based on in
type LocationPriority ¶
type LocationPriority uint
LocationPriority defines the order of which location attributes and messages are processed.
const ( // LocationPriorityInfo defines an informational location. LocationPriorityInfo LocationPriority = iota // LocationPriorityWarning defines a warning location. LocationPriorityWarning // LocationPriorityError defines an error location. LocationPriorityError // LocationPriorityCritical defines an critical location. LocationPriorityCritical )
type REPLHandler ¶ added in v0.0.58
type REPLHandler interface {
repl.CommandHandler
// Help returns responsive components that describe
// the command's usage for the given arguments.
Help(ctx context.Context, args []string) (
iterator.Iterator[component.Responsive], error,
)
}
REPLHandler extends repl.CommandHandler with a Help method that returns documentation for a command.