editor

package
v0.0.0-...-a007d9a Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2015 License: Apache-2.0 Imports: 22 Imported by: 0

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

View Source
const (
	EventKey = iota
	EventResize
)

Supported event types.

Variables

This section is empty.

Functions

func RegisterCommandCommands

func RegisterCommandCommands(dispatcher wicore.CommandsW)

RegisterCommandCommands registers the top-level native commands.

func RegisterDefaultViewFactories

func RegisterDefaultViewFactories(e Editor)

RegisterDefaultViewFactories registers the builtins views factories.

func RegisterDocumentCommands

func RegisterDocumentCommands(dispatcher wicore.CommandsW)

RegisterDocumentCommands registers the top-level native commands to manage documents.

func RegisterEditorDefaults

func RegisterEditorDefaults(view wicore.ViewW)

RegisterEditorDefaults registers the top-level native commands and key bindings.

func RegisterKeyBindingCommands

func RegisterKeyBindingCommands(dispatcher wicore.CommandsW)

RegisterKeyBindingCommands registers the keyboard mapping related commands.

func RegisterTodoCommands

func RegisterTodoCommands(dispatcher wicore.CommandsW)

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

func RegisterViewCommands(dispatcher wicore.CommandsW)

RegisterViewCommands registers view-related commands

func RegisterWindowCommands

func RegisterWindowCommands(dispatcher wicore.CommandsW)

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

func MakeEditor(terminal Terminal, noPlugin bool) (Editor, error)

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 EventType

type EventType int

EventType is the type of supported terminal event.

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

type Plugins []wicore.Plugin

Plugins is the collection of Plugin instances, it represents all the live plugin processes.

func (Plugins) Close

func (p Plugins) Close() error

Close implements io.Closer.

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 Size

type Size struct {
	Width  int
	Height int
}

Size represents the size of an UI element.

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

func (t *TerminalFake) Blit(b *raster.Buffer)

Blit implements Terminal.

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.

func (*TerminalFake) Size

func (t *TerminalFake) Size() (int, int)

Size implements Terminal.

Jump to

Keyboard shortcuts

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