vidar: github.com/nelsam/vidar/command/input Index | Files

package input

import "github.com/nelsam/vidar/command/input"

Index

Package Files

applied_hook.go canceler.go change_hook.go confirmer.go context_change_hook.go handler.go

type AppliedChangeHook Uses

type AppliedChangeHook interface {
    Applied(input.Editor, []input.Edit)
}

An AppliedChangeHook is a hook that needs to be informed about edits immediately after they are applied, before the call to Apply is finished. Its Applied method will be called synchronously in the Handler, so it should be as minimal as possible.

type Binder Uses

type Binder interface {
    Bindable(name string) bind.Bindable
    Execute(bind.Bindable)
}

type Canceler Uses

type Canceler interface {
    // Cancel is called when the hook should be cancelled.  It should
    // return true if it should consume the cancel event.
    Cancel(input.Editor) (cancelled bool)
}

Canceler is a type that needs to know when it's being cancelled. This could be anything from a long-running process that can't make use of the context.Context (for whatever reason) to a type that adds itself to the UI and needs to know when it should be removed.

type ChangeHook Uses

type ChangeHook interface {
    // Init is called when a file is opened, to initialize the
    // hook.  The full text of the editor will be passed in.
    Init(input.Editor, []rune)

    // TextChanged is called for every text edit.
    //
    // TextChanged may be called multiple times prior to Apply if
    // more edits happen before Apply is called.
    //
    // Hooks that have to start over from scratch when new updates
    // are made should implement ContextChangeHook, instead.
    TextChanged(input.Editor, input.Edit)

    // Apply is called when there is a break in text changes, to
    // apply the hook's event.  Unlike TextChanged, Apply is
    // called in the main UI thread.
    Apply(input.Editor) error
}

ChangeHook is a hook that triggers events on text changing. Each ChangeHook gets its own goroutine that will be used to process events. When there is a lull in the number of events coming through (i.e. there is a pause in typing), Apply will be called from the UI goroutine.

For plugins that need to process all events at once, or apply to the entire file instead of one edit at a time, implement ContextChangeHook.

type Confirmer Uses

type Confirmer interface {
    // Confirm will be called when a confirmation key is pressed.
    // It should return true if it should consume the confirmation
    // event.
    Confirm(input.Editor) (confirmed bool)
}

Confirmer is a type that needs to know when a user is confirming an action. It is typically a type that adds itself to the UI requesting that the user respond in some way. The input handler will interpret user key presses and call all confirmers when a confirmation key (enter, in the default handler) is pressed.

type ContextChangeHook Uses

type ContextChangeHook interface {
    // Init is called when a file is opened, to initialize the
    // hook.  The full text of the editor will be passed in.
    Init(input.Editor, []rune)

    // TextChanged is called in a new goroutine whenever any text
    // is changed in the editor.  Any changes to the UI should be
    // saved for Apply, since most of those calls must be called
    // in the UI goroutine.
    //
    // If TextChanged is currently running and new edits come
    // through, the context.Context will be cancelled and
    // TextChanged will be called again with the new edits appended
    // to those from the previous call.
    TextChanged(context.Context, input.Editor, []input.Edit)

    // Apply is called when there is a break in text changes, to
    // apply the hook's event.  Unlike TextChanged, Apply is
    // called in the main UI thread.
    Apply(input.Editor) error
}

ContextChangeHook is similar to a ChangeHook, but takes a context.Context that will be cancelled if new changes show up before Apply is called.

type Handler Uses

type Handler struct {
    // contains filtered or unexported fields
}

Handler is vidar's default input handler. It takes the runes typed and writes them to the editor's text box, allowing plugins to bind to text change events.

It can be overridden by installing a plugin that implements commander.Handler.

TODO: Remove the need for so much of the editor's methods. Ideally, we should be able to do what we need to do with just input.Editor. This may require expanding input.Editor some, but we shouldn't need editor.Controller for so much of what we're doing. Basic editing should be handleable by the editor.

func New Uses

func New(d gxui.Driver, b Binder) *Handler

func (*Handler) Apply Uses

func (h *Handler) Apply(e input.Editor, edits ...input.Edit)

func (*Handler) Bind Uses

func (e *Handler) Bind(b bind.Bindable) (input.Handler, error)

func (*Handler) HandleEvent Uses

func (e *Handler) HandleEvent(focused input.Editor, ev gxui.KeyboardEvent)

func (*Handler) HandleInput Uses

func (e *Handler) HandleInput(focused input.Editor, ev gxui.KeyStrokeEvent)

func (*Handler) Init Uses

func (e *Handler) Init(newEditor input.Editor, contents []rune)

func (*Handler) Name Uses

func (e *Handler) Name() string

func (*Handler) New Uses

func (e *Handler) New() input.Handler

Package input imports 11 packages (graph) and is imported by 1 packages. Updated 2018-05-25. Refresh now. Tools for package owners.