Documentation ¶
Overview ¶
Package editor contains the UI toolkit agnostic unit-testable part of the wi editor. It brings text based editor technology past 1200 bauds.
It is in a standalone package for a few reasons:
- godoc will generate documentation for this code.
- it can be unit tested without having a dependency on termbox.
- hide away ncurse idiocracies (like Ctrl-H == Backspace) which could be supported on Windows or native UI.
This package is not meant to be a general purpose reusable package, the primary maintainer of this project likes having a web browseable documentation. Using a package is an effective workaround the fact that godoc doesn't general documentation for "main" package.
See ../README.md for user information.
Index ¶
- Constants
- func RegisterCommandCommands(dispatcher wicore.CommandsW)
- func RegisterDefaultViewFactories(e Editor)
- func RegisterDocumentCommands(dispatcher wicore.CommandsW)
- func RegisterEditorDefaults(view wicore.ViewW)
- func RegisterKeyBindingCommands(dispatcher wicore.CommandsW)
- func RegisterTodoCommands(dispatcher wicore.CommandsW)
- func RegisterViewCommands(dispatcher wicore.CommandsW)
- func RegisterWindowCommands(dispatcher wicore.CommandsW)
- type ColorMode
- type Editor
- type EventType
- type Logger
- type Plugins
- type ReadWriteSeekCloser
- type Size
- type Terminal
- type TerminalEvent
- type TerminalFake
Constants ¶
const ( EventKey = iota EventResize )
Supported event types.
Variables ¶
This section is empty.
Functions ¶
func RegisterCommandCommands ¶
RegisterCommandCommands registers the top-level native commands.
func RegisterDefaultViewFactories ¶
func RegisterDefaultViewFactories(e Editor)
RegisterDefaultViewFactories registers the builtins views factories.
func RegisterDocumentCommands ¶
RegisterDocumentCommands registers the top-level native commands to manage documents.
func RegisterEditorDefaults ¶
RegisterEditorDefaults registers the top-level native commands and key bindings.
func RegisterKeyBindingCommands ¶
RegisterKeyBindingCommands registers the keyboard mapping related commands.
func RegisterTodoCommands ¶
RegisterTodoCommands registers the top-level native commands that are yet to be implemented.
TODO(maruel): Implement these commands properly and move to the right place.
func RegisterViewCommands ¶
RegisterViewCommands registers view-related commands
func RegisterWindowCommands ¶
RegisterWindowCommands registers all the commands relative to window management.
Types ¶
type ColorMode ¶
type ColorMode int
ColorMode is the coloring mode in effect.
TODO(maruel): Define coloring modes. Could be:
- A file type. Likely defined by a string, not a int.
- A diff view mode.
- No color at all.
type Editor ¶
type Editor interface { io.Closer wicore.EditorW // EventLoop runs the event loop until the command "quit" executes // successfully. EventLoop() int }
Editor is the inprocess wicore.Editor interface. It adds the process life-time management functions to the public interface wicore.Editor.
It is very important to call the Close() function upon termination.
func MakeEditor ¶
MakeEditor creates an object that implements the Editor interface. The root window doesn't have anything to view in it.
The editor contains a root window and a root view. It's up to the caller to add child Windows in it. Normally it will be done via the command "editor_bootstrap_ui" to add the status bar, then "new" or "open" to create the initial text buffer.
It is fine to run it concurrently in unit test, as no global variable shall be used by the object created by this function.
type Logger ¶
type Logger interface {
Logf(format string, v ...interface{})
}
Logger is the interface to log to. It must be used instead of log.Logger.Printf() or testing.T.Log(). This permits to collect logs for a complete test case.
TODO(maruel): Move elsewhere.
type Plugins ¶
Plugins is the collection of Plugin instances, it represents all the live plugin processes.
type ReadWriteSeekCloser ¶
type ReadWriteSeekCloser interface { io.Closer io.ReadWriteSeeker }
ReadWriteSeekCloser is a generic handle to a file.
TODO(maruel): No idea why package io doesn't provide this interface.
type Terminal ¶
type Terminal interface { // Size returns the current size of the terminal window. Size() (int, int) // SeedEvents() returns a channel where events will be sent to. // // The channel will be closed when the terminal is closed. SeedEvents() <-chan TerminalEvent // Blit updates the terminal output with the buffer specified. // // It is important for the buffer to be the right size, otherwise the display // will be partially updated. Blit(b *raster.Buffer) // SetCursor moves the cursor to a position. SetCursor(col, row int) }
Terminal is the interface to the actual terminal termbox so it can be mocked in unit test or a different implementation than termbox can be used.
type TerminalEvent ¶
type TerminalEvent struct { Type EventType // Type determines which other member will be valid for this event. Key key.Press Size Size }
TerminalEvent represents an event that occured on the terminal.
type TerminalFake ¶
type TerminalFake struct { Width int Height int Events []TerminalEvent Buffer *raster.Buffer }
TerminalFake implements the Terminal and buffers the output.
It is mostly useful in unit tests.
func NewTerminalFake ¶
func NewTerminalFake(width, height int, events []TerminalEvent) *TerminalFake
NewTerminalFake returns an initialized TerminalFake which implements the interface Terminal.
The terminal can be preloaded with fake events.
func (*TerminalFake) SeedEvents ¶
func (t *TerminalFake) SeedEvents() <-chan TerminalEvent
SeedEvents implements Terminal.
func (*TerminalFake) SetCursor ¶
func (t *TerminalFake) SetCursor(col, line int)
SetCursor implements Terminal.