event

package
v0.0.0-...-256bffb Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acme

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

Acme implements the Listener interface for acme events

func (*Acme) GetBufListener

func (a *Acme) GetBufListener(id int) *Buf

GetBufListener returns the running Buf by its ID

func (*Acme) Listen

func (a *Acme) Listen() error

Listen watches the acme event log for events and executes hooks based on those events

func (*Acme) RegisterKeyCmdHook

func (a *Acme) RegisterKeyCmdHook(hook KeyCmdHook)

RegisterKeyCmdHook registers hook for key events

func (*Acme) RegisterPutHook

func (a *Acme) RegisterPutHook(hook PutHook)

RegisterPutHook registers hook on acme 'Put' events

func (*Acme) RegisterWinHook

func (a *Acme) RegisterWinHook(hook WinHook)

RegisterWinHook registers the hook on acme 'New' events

type AcmeOp

type AcmeOp int

AcmeOp contains the acme events that are available

const (
	// NEW represents window creation
	NEW AcmeOp = iota
	// ZEROX reprents window creation via zerox
	ZEROX
	// GET loadr file into window
	GET
	// PUT writes window to the named file
	PUT
	// DEL deletes the window
	DEL
	// FOCUS is received when the window is in focus
	FOCUS
)

type ActionOrigin

type ActionOrigin int

ActionOrigin is the entity that originated the action

const (
	// BodyOrTag represents an action received in the body or tag
	BodyOrTag ActionOrigin = iota
	// WindowFiles represents an action taken in the file
	WindowFiles
	// Keyboard represents an action taken by the keyboard
	Keyboard
	// Mouse represents an action taken by the mouse
	Mouse
	// DelOrigin represents a delete event
	DelOrigin
)

type ActionType

type ActionType int

ActionType describes what kind of action was taken

const (
	// BodyDelete is a deletion in the window body
	BodyDelete ActionType = iota
	// TagDelete is a deletion in the window tag
	TagDelete
	// BodyInsert is an insertion into the window body
	BodyInsert
	// TagInsert is an insert into the window tag
	TagInsert
	// B3Body is a right click event in the window body
	B3Body
	// B3Tag is a right click event in the window tag
	B3Tag
	// B2Body is a middle click event in the window body
	B2Body
	// B2Tag is a middle click event in the window tag
	B2Tag
	// DelType represents a delete event
	DelType
)

type Buf

type Buf struct {
	ID   int
	File string
	Win  *Win
	// contains filtered or unexported fields
}

Buf implements the BufListener interface and runs on opened acme buffers

func (*Buf) GetWin

func (b *Buf) GetWin() *Win

GetWin returns the active acme Window

func (*Buf) RegisterKeyCmdHook

func (b *Buf) RegisterKeyCmdHook(hook KeyCmdHook)

RegisterKeyCmdHook registers hook for key events

func (*Buf) RegisterPutHook

func (b *Buf) RegisterPutHook(hook PutHook)

RegisterPutHook registers hook on acme 'Put' events

func (*Buf) RegisterWinHook

func (b *Buf) RegisterWinHook(hook WinHook)

RegisterWinHook registers the hook on acme 'New' events

func (*Buf) Start

func (b *Buf) Start() error

Start begins the event listener for the window

type BufListener

type BufListener interface {
	GetWin() *Win
	Start() error
	RegisterPutHook(hook PutHook)
	RegisterWinHook(hook WinHook)
	RegisterKeyCmdHook(KeyCmdHook)
}

BufListener processes hooks on acme events

func NewBufListener

func NewBufListener(id int, file string) BufListener

NewBufListener constructs an event loop

type Condition

type Condition func(Event) bool

Condition is a function that returns under what condition to run event

type Event

type Event struct {
	ID                       int
	File                     string
	Origin                   ActionOrigin
	Type                     ActionType
	Text                     []byte
	Builtin                  AcmeOp
	Flag                     Flag
	SelBegin, SelEnd         int
	OrigSelBegin, OrigSelEnd int
	NumBytes                 int
	NumRunes                 int
	ChordArg                 []byte
	ChordLoc                 []byte
}

Event contains metadata for each Acme event

The message includes the text if it is less than 256 chars. If it is longer than that, the fourth number is 0 and the body must be read through the data file

func TokenizeEvent

func TokenizeEvent(event *acme.Event, id int, file string) (Event, error)

TokenizeEvent parses a raw acme event into the Event type

func (*Event) GetLog

func (e *Event) GetLog() acme.Event

GetLog returns a raw acme log event for the Event type

type Flag

type Flag int

Flag contains the flag for the event. For BodyDelete, TagDelete, BodyInsert, and TagInsert the flag is always zero. For messages with the 1 bit on in the flag, writing the message back to the event file, but with the flag, count, and text omitted, will cause the action to be applied to the file exactly as it would have been if the event file had not been open.

const (

	// IsBuiltin represents a built-in command
	IsBuiltin Flag = iota

	// IsNull represents if the text is a null string that has a
	// non-null expansion; if so, another complete message will
	// follow describing the expansion exactly as if it had been
	// indicated explicitly (its flag will always be 0)
	IsNull

	// HasChordedArg says if the command has an extra (chorded)
	// argument; if so, two more complete messages will follow
	// reporting the argument (with all numbers 0 except the
	// character count) and where it originated, in the form of a
	// fully-qualified button 3 style address.
	HasChordedArg

	// NoReloadNeeded says if acme can interpret the action without
	// loading a new file
	NoReloadNeeded

	// PostExpandFollows says if a second (post-expansion) message
	// follows, analogous to that with X messages
	PostExpandFollows

	// IsFileOrWindow says If the text is a file or window name
	// (perhaps with address) rather than plain literal text.
	IsFileOrWindow
)

type KeyCmdHandler

type KeyCmdHandler func(Event) Event

KeyCmdHandler modifies keyboard mappings

type KeyCmdHook

type KeyCmdHook struct {
	Key       rune
	Condition Condition
	Handler   KeyCmdHandler
}

KeyCmdHook contains properties for key handlers

type Listener

type Listener interface {
	Listen() error
	RegisterPutHook(hook PutHook)
	RegisterWinHook(hook WinHook)
	RegisterKeyCmdHook(KeyCmdHook)
	GetBufListener(id int) *Buf
}

Listener can listen for acme Event and Window hooks

func NewListener

func NewListener() Listener

NewListener constructs an Acme Listener

type PutHandler

type PutHandler func(Event) Event

PutHandler listens for acme Events

type PutHook

type PutHook struct {
	Handler PutHandler
}

PutHook contains properties for event handlers

type Win

type Win struct {
	ID        int
	File      string
	Lastpoint int
	// contains filtered or unexported fields
}

Win represents the active Acme window

func NewWin

func NewWin(w *acme.Win) *Win

NewWin constructs a Win object from acme window

func OpenWin

func OpenWin(id int, file string) (*Win, error)

OpenWin opens an acme window

func (*Win) ClearTagText

func (w *Win) ClearTagText() error

ClearTagText removes all text in the tag after the vertical bar.

func (*Win) Close

func (w *Win) Close()

Close closes down the window with associated files

func (*Win) DisableNoMark

func (w *Win) DisableNoMark() error

DisableNoMark cancels nomark, returning the window to the usual state wherein each modification to the body must be undone individually.

func (*Win) EnableNoMark

func (w *Win) EnableNoMark() error

EnableNoMark turns off automatic ‘marking’ of changes, so a set of related changes may be undone in a single Undo interactive command.

func (*Win) ExecDelete

func (w *Win) ExecDelete() error

ExecDelete is the equivalent to the Del interactive command.

func (*Win) ExecDumpToFile

func (w *Win) ExecDumpToFile(file string) error

ExecDumpToFile sets the command string to recreate the window from a dump file.

func (*Win) ExecGet

func (w *Win) ExecGet() error

ExecGet is the equivalent to the Get interactive command with no arguments; accepts no arguments.

func (*Win) ExecInTag

func (w *Win) ExecInTag(exec string, args ...string) error

ExecInTag executes the given command in the window tag

func (*Win) ExecPut

func (w *Win) ExecPut() error

ExecPut is the equivalent to the Put interactive command with no arguments; accepts no arguments.

func (*Win) ExecShow

func (w *Win) ExecShow() error

ExecShow guarantees at least some of the selected text is visible on the display.

func (*Win) MarkWinClean

func (w *Win) MarkWinClean() error

MarkWinClean marks the window clean as though it has just been written.

func (*Win) MarkWinDirty

func (w *Win) MarkWinDirty() error

MarkWinDirty marks the window dirty, the opposite of clean.

func (*Win) OpenEventChan

func (w *Win) OpenEventChan() <-chan *acme.Event

OpenEventChan opens a channel to raw acme events

func (*Win) ReadAddr

func (w *Win) ReadAddr() ([]byte, error)

ReadAddr returns the current address of the window

func (*Win) ReadBody

func (w *Win) ReadBody() ([]byte, error)

ReadBody returns the window body

func (*Win) ReadTag

func (w *Win) ReadTag() ([]byte, error)

ReadTag returns the tag contents

func (*Win) RestrictSearchToAddr

func (w *Win) RestrictSearchToAddr() error

RestrictSearchToAddr restricts subsequent searches to the current addr address.

func (*Win) SetAddr

func (w *Win) SetAddr(addr string) error

SetAddr takes an addr which may be written with any textual address in the format understood by button 3 but without the initial colon

func (*Win) SetAddrToSelText

func (w *Win) SetAddrToSelText() error

SetAddrToSelText sets the addr address to that of the user’s selected text in the window.

func (*Win) SetData

func (w *Win) SetData(data []byte) error

SetData is used in conjunction with addr for random access to the contents of the body. The file offset is ignored when writing the data file; instead the location of the data to be read or written is determined by the state of the addr file. Text, which must contain only whole characters (no ‘partial runes’), written to data replaces the characters addressed by the addr file and sets the address to the null string at the end of the written text. A read from data returns as many whole characters as the read count will permit starting at the beginning of the addr address (the end of the address has no effect) and sets the address to the null string at the end of the returned characters.

func (*Win) SetDumpDir

func (w *Win) SetDumpDir(dir string) error

SetDumpDir sets the directory in which to run the command to recreate the window from a dump file.

func (*Win) SetTextToAddr

func (w *Win) SetTextToAddr() error

SetTextToAddr sets the user’s selected text in the window to the text addressed by the addr address.

func (*Win) SetWinName

func (w *Win) SetWinName(name string) error

SetWinName sets the name of the window to name.

func (*Win) WriteEvent

func (w *Win) WriteEvent(e Event) error

WriteEvent writes the acme event to the log

func (*Win) WriteToTag

func (w *Win) WriteToTag(text string) error

WriteToTag writes to the windows tag

type WinHandler

type WinHandler func(*Win)

WinHandler listens for new acme Windows

type WinHook

type WinHook struct {
	Handler WinHandler
}

WinHook contains properties for window handlers

Jump to

Keyboard shortcuts

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