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
- type Mark
- type View
- func (v *View) Close() error
- func (v *View) Do(edits ...edit.Edit) ([]editor.EditResult, error)
- func (v *View) DoAsync(edits ...edit.Edit)
- func (v *View) Resize(nLines int) bool
- func (v *View) Scroll(deltaLines int)
- func (v *View) View(f func(text []byte, marks []Mark))
- func (v *View) Warp(addr edit.Address)
Constants ¶
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 ¶
New returns a new View for a buffer. The new view tracks the empty string at line 0 and the given marks.
func (*View) Do ¶
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 ¶
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 ¶
Resize resizes the View to track the given number of lines, and returns whether the size actually changed.