view

package
v0.0.0-...-2842cdc Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

Package view provides a View type, which is an editor client that maintains a local, consistent copy of a segment of its buffer, and a set of marks.

A View tracks text within line boundaries defined by a starting line and a number of following lines. The View text and marks can be read atomically, giving a consistent view of the tracked segment of the buffer. It can also be scrolled or warped to new starting line, and it can be resized to track a different number of lines.

A typical user will:

In one go routine:
1. Receive from the Notify channel to wait for a change.
2. Call View to read the updated text and marks.
3. Goto 1.

In another go routine:
• Call Scroll, Resize, and Do as desired.

Index

Constants

View Source
const (
	// ViewMark is the mark rune indicating the start
	// of the text tracked by a View.
	ViewMark = '0'

	// TmpMark is a mark used temporarily to save and restore dot.
	TmpMark = '1'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mark

type Mark struct {
	// Name is the mark rune.
	Name rune
	// Where is the address of the mark as rune offsets.
	Where [2]int64
}

A Mark is a mark tracked by a View.

type View

type View struct {
	// Notify is used to notify of changes to the View.
	// An empty struct is sent on Notify when the view changes.
	// Notify is closed when the View is closed.
	// Notify is single-buffered; if a send cannot proceed, it is dropped.
	Notify <-chan struct{}
	// contains filtered or unexported fields
}

A View is an editor client that maintains a local, consistent copy of a segment of its buffer, and a set of marks.

All methods of a View are safe to call concurrently.

func New

func New(bufferURL *url.URL, markRunes ...rune) (*View, error)

New returns a new View for a buffer. The new view tracks the empty string at line 0 and the given marks.

func (*View) Close

func (v *View) Close() error

Close closes the view, and deletes its editor.

func (*View) Do

func (v *View) Do(edits ...edit.Edit) ([]editor.EditResult, error)

Do performs edits using the View's Editor and returns the results. If there is an error requesting the edits, it is returned through the error return. If there is an error performing any of the individual edits, it is reported in the EditResult.

func (*View) DoAsync

func (v *View) DoAsync(edits ...edit.Edit)

DoAsync performs edits asynchronously using the View's Editor. If there is an error requesting the edits, it is logged, and discarded. The EditResults are silently discarded.

func (*View) Resize

func (v *View) Resize(nLines int) bool

Resize resizes the View to track the given number of lines, and returns whether the size actually changed.

func (*View) Scroll

func (v *View) Scroll(deltaLines int)

Scroll scrolls the View by the given delta.

func (*View) View

func (v *View) View(f func(text []byte, marks []Mark))

View calls the function with the current text and marks. The text and marks will not change until f returns.

func (*View) Warp

func (v *View) Warp(addr edit.Address)

Warp moves the first line of the view to the line containin the beginning of an Address.

Jump to

Keyboard shortcuts

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