demodel

package
v0.0.0-...-0efad91 Latest Latest
Warning

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

Go to latest
Published: May 3, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectionNone = ScrollDirection(iota)
	DirectionUp
	DirectionDown
)

Variables

View Source
var ErrNoTagline = errors.New("No tagline exists for buffer")
View Source
var ErrUnsupportedOption = errors.New("Unsupported Option")

Functions

func ConfigHome

func ConfigHome() string

ConfigHome returns the directory where configuration files are written

func DataHome

func DataHome() string

DataHome returns the directory where data files may be written

Types

type Action

type Action func(From, To Position, buf *CharBuffer) error

An action performs some sort of action to a character buffer, which would generally involve modifying it in some way.

type CharBuffer

type CharBuffer struct {
	// The CharBuffer.Buffer is a slice of the bytes which are currently
	// being manipulated. It's read from the filesystem when a file is opened,
	// and written to the filesystem when it's saved.
	Buffer []byte

	// Dot represents the current cursor position or selected text inside of
	// the character buffer.
	Dot Dot

	// AltDot represents the selection used for middle clicking or pressing "Enter"
	// to execute a word. Since the execution might need Dot as a parameter, we
	// need a second selection to determine what we're executing, otherwise commands
	// like "Cut" would always cut the word "Cut", since it had to be selected
	// to be executed.
	AltDot Dot

	// Filename represents the name that the CharBuffer.Buffer will be written
	// to on save.
	Filename string

	// The most recently deleted text, which can be pasted with the 'p' command
	// Each CharBuffer only has one SnarfBuffer associated with it, and it's not
	// a tree.
	SnarfBuffer []byte

	// The tagline to display with this buffer. May be nil (for instance, taglines
	// are CharBuffers, but taglines don't have their own tagline..)
	Tagline *CharBuffer

	// Undo represents the previous CharBuffer that got the buffer into this state.
	// It's effectively a singly-linked list of Undos.
	Undo *CharBuffer
	// Dirty represents if the file has been modified since being open, or since the last
	// save.
	Dirty bool
}

A CharBuffer is a set of bytes being manipulated. Generally, a text file.

func (*CharBuffer) AppendTag

func (c *CharBuffer) AppendTag(val string) error

func (*CharBuffer) JoinLines

func (c *CharBuffer) JoinLines(from, to uint)

func (*CharBuffer) LoadSnarfBuffer

func (c *CharBuffer) LoadSnarfBuffer()

func (*CharBuffer) ResetTagline

func (c *CharBuffer) ResetTagline() error

func (*CharBuffer) SaveSnarfBuffer

func (c *CharBuffer) SaveSnarfBuffer()

func (*CharBuffer) Write

func (c *CharBuffer) Write(p []byte) (int, error)

type Dot

type Dot struct {
	Start, End uint
}

Dot generally represents a selection or position in a buffer. It holds the start and the end of the selection. If Start==End, it's a position.

type ImageMap

type ImageMap interface {
	// At returns the index into the charbuffer that this image map is representing
	// at point x,y for the image which is being mapped.
	At(x, y int) (uint, error)

	// Get returns the bounding rectangle for the glyph at index idx of the CharBuffer
	// being mapped in the image being mapped to.
	Get(idx uint) (image.Rectangle, error)
}

An ImageMap represents a way to convert points in an image into indexes into a character buffer and vice versa. They generally, internally, have a pointer to a char buffer that they're rendering and an image that they're mapping to.

type Map

type Map interface {
	HandleKey(key.Event, *CharBuffer, Viewport) (Map, ScrollDirection, error)
}

A Map maps a keystroke to a command. It performs a command, and then returns a new map which represents the keyboard mapping to be used for the next keystroke.

type Position

type Position func(buf CharBuffer) (uint, error)

A position calculates the index into a CharBuffer for something to use as a reference, generally to perform an action on it. For instance, the position of the start of the previous word, or the next paragraph, or the containing block of the cursor. Built in positions are in the positions package.

type Renderer

type Renderer interface {
	// Determines whether this renderer knows how to render this character buffer.
	// The most recently registered plugin that can handle it wins (because otherwise
	// everything would use the default renderer, which claims it can render anything.)
	CanRender(*CharBuffer) bool

	// Given a character buffer, and a clipping region (viewport) to be displayed, renders an image that
	// should be shown on the screen, a rectangle determining what the size of the *entire* buffer rendered
	// would be (even if it didn't render it), an ImageMap that, at least for the portion rendered, can
	// be used to determine what any pixel represents, and an error (hopefully nil.)
	RenderInto(dst draw.Image, buffer *CharBuffer, viewport image.Rectangle) error

	// Returns the bounds that would render the entire buffer, if the viewport were big enough.
	Bounds(buffer *CharBuffer) image.Rectangle

	// Returns an ImageMap covering the entire bounds
	GetImageMap(buffer *CharBuffer, viewport image.Rectangle) ImageMap
	// This being in the interface is a temporary hack until the renderers are refactored to share
	// more code. It requests that any cache of the image size be invalidated, because the DPI
	// changed. It doesn't belong here, but it's got nowhere else to go right now.
	InvalidateCache()
}

A Renderer takes a character buffer and renders it to an image to be displayed in a viewport.

type ScrollDirection

type ScrollDirection uint8

type Viewport

type Viewport interface {
	Renderer
	// Returns the current KBMap mode that the viewport is in.
	GetKeyboardMode() Map
	// Requests that the KBMap be changed to a new mode for this viewport.
	SetKeyboardMode(Map) error
	// Requests that the KBMap be changed to a new mode, and further changes
	// be disallowed until it's explicitly unlocked. This is mostly for plugins
	// such as Shell
	LockKeyboardMode(Map) error
	// Informs the viewport that the keyboard map should be unlocked from Map.
	// The current map must be passed as a parameter, mostly to prevent accidentally
	//unlocking someone else's lock, not for security reasons.
	UnlockKeyboardMode(Map) error

	// Registers a channel to be notified after a mouse event is processed.
	RegisterMouseListener(chan interface{})
	DeregisterMouseListener(chan interface{})

	// Request a change of the renderer to be used to render the main contents
	// of this viewport
	SetRenderer(Renderer) error

	// Request that the viewport be rerendered.
	Rerender()

	ResetLocation() error

	SetOption(option string, value interface{}) error
}

A Viewport represents the state of the window being rendered.

Jump to

Keyboard shortcuts

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