editor

package
v0.0.0-...-5a72617 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2016 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package editor provides a graphical, editable text area widget.

Index

Constants

This section is empty.

Variables

View Source
var AcmeBlueTheme = &OptionSet{
	Text:       image.Black,
	BG1:        image.NewUniform(color.RGBA{R: 0xEA, G: 0xFF, B: 0xFF, A: 0xFF}),
	BG2:        image.NewUniform(color.RGBA{R: 0x88, G: 0x88, B: 0xCC, A: 0xFF}),
	Sel:        image.NewUniform(color.RGBA{R: 0x9F, G: 0xEB, B: 0xEA, A: 0xFF}),
	Cursor:     acmeCursor(image.NewUniform(color.RGBA{R: 0xEA, G: 0xFF, B: 0xFF, A: 0xFF})),
	AutoIndent: true,
	ScrollBar:  true,
}
View Source
var AcmeYellowTheme = &OptionSet{
	Text:       image.Black,
	BG1:        image.NewUniform(color.RGBA{R: 0xFF, G: 0xFF, B: 0xEA, A: 0xFF}),
	BG2:        image.NewUniform(color.RGBA{R: 0xA0, G: 0xA0, B: 0x4B, A: 0xFF}),
	Sel:        image.NewUniform(color.RGBA{R: 0xEE, G: 0xEE, B: 0x9E, A: 0xFF}),
	Cursor:     acmeCursor(image.NewUniform(color.RGBA{R: 0xFF, G: 0xFF, B: 0xEA, A: 0xFF})),
	AutoIndent: true,
	ScrollBar:  true,
}
View Source
var SimpleTheme = &OptionSet{
	Text:   image.Black,
	BG1:    image.White,
	BG2:    image.NewUniform(color.Gray{Y: 0xA0}),
	Sel:    image.NewUniform(color.RGBA{R: 0x90, G: 0xB0, B: 0xD0, A: 0xFF}),
	Cursor: simpleCursor,
}

Functions

This section is empty.

Types

type Editor

type Editor struct {
	B2Action func(string) // define an action for the middle mouse button
	B3Action func(string) // define an action for the right mouse button
	// contains filtered or unexported fields
}

An Editor is a graphical, editable text area widget, intended to be compatible with golang.org/x/exp/shiny, or any other graphical window package capable of drawing a widget via an image.RGBA. See sigint.ca/cmd/edit for an example program using this type.

func NewEditor

func NewEditor(face font.Face, opts *OptionSet) *Editor

NewEditor returns a new Editor with a clipping rectangle defined by size, a font face, and an OptionSet opts. If opts is nil, editor.SimpleTheme will be used.

func (*Editor) CanRedo

func (ed *Editor) CanRedo() bool

CanRedo reports whether the Editor has a following history state which can be applied.

func (*Editor) CanUndo

func (ed *Editor) CanUndo() bool

CanUndo reports whether the Editor has a previous history state which can be applied.

func (*Editor) Contents

func (ed *Editor) Contents() []byte

Contents returns the entire contents of the editor.

func (*Editor) Dirty

func (ed *Editor) Dirty() bool

Dirty reports whether the next call to Draw will result in a different image than the previous call.

func (*Editor) Draw

func (ed *Editor) Draw(dst *image.RGBA, dr image.Rectangle) int

Draw draws the editor onto dst within the bounding rectangle dr, and returns the height in pixels of the text that was drawn.

func (*Editor) FindNext

func (ed *Editor) FindNext(s string) (address.Selection, bool)

FindNext searches for s in the Editor's text buffer, and selects the first match starting from the current selection, possibly wrapping around to the beginning of the buffer. If there are no matches, the selection is unchanged.

func (*Editor) GetDot

func (ed *Editor) GetDot() address.Selection

func (*Editor) GetDotContents

func (ed *Editor) GetDotContents() string

func (*Editor) JumpTo

func (ed *Editor) JumpTo(addr string) bool

JumpTo sets the selection to the specified address, as define in sam(1).

func (*Editor) LastAddress

func (ed *Editor) LastAddress() address.Simple

func (*Editor) Load

func (ed *Editor) Load(s []byte)

Load replaces the contents of the Editor's text buffer with s, and resets the Editor's history.

func (*Editor) Replace

func (ed *Editor) Replace(s string)

Replace replaces the current selection with s, updating the Editor's history.

func (*Editor) Saved

func (ed *Editor) Saved() bool

Saved reports whether the Editor has been modified since the last time SetSaved was called.

func (*Editor) SendKeyEvent

func (ed *Editor) SendKeyEvent(e key.Event)

SendKeyEvent sends a key event to be interpreted by the Editor.

func (*Editor) SendMouseEvent

func (ed *Editor) SendMouseEvent(e mouse.Event)

SendMouseEvent sends a mouse event to be interpreted by the Editor.

func (*Editor) SendRedo

func (ed *Editor) SendRedo()

SendRedo attempts to apply the Editor's next history state, if it exists.

func (*Editor) SendUndo

func (ed *Editor) SendUndo()

SendUndo attempts to apply the Editor's previous history state, if it exists.

func (*Editor) SetDot

func (ed *Editor) SetDot(a address.Selection)

func (*Editor) SetFont

func (ed *Editor) SetFont(face font.Face)

SetFont sets the Editor's font face to face.

func (*Editor) SetOpts

func (ed *Editor) SetOpts(opts *OptionSet)

SetOpts reconfigures the Editor according to opts.

func (*Editor) SetSaved

func (ed *Editor) SetSaved()

SetSaved instructs the Editor that the current contents should be considered saved. After calling SetSaved, the client can call Saved to see if the Editor has unsaved content.

type OptionSet

type OptionSet struct {
	Text       *image.Uniform
	BG1        *image.Uniform
	BG2        *image.Uniform
	Sel        *image.Uniform
	Cursor     func(height int) image.Image
	AutoIndent bool
	ScrollBar  bool
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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