action

package
v0.9.11 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Do()

	Undo()
	Undoable() bool

	Explain() string
}

Action models a "doable" and potentially "undoable" action.

If an action can be undone, its Undoable member is to return true, otherwise false. Iff Undoable returns false, Undo should be a no-op.

Actions can also -- e.g. for the purposes of help generation -- be described by Explain. Explain is to return a string describing the action Do would perform.

type Simple

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

Simple implements the Action interface. It models a simple, non-undoable action as a func() which is called on Do.

func NewSimple

func NewSimple(explainer func() string, action func()) *Simple

NewSimple returns a pointer to a new simple action, which stores the given action function and the given explainer to use when prompted with Do or Explain respectively.

func (*Simple) Do

func (a *Simple) Do()

Do performs this simple action. A simple action is not undoable.

func (*Simple) Explain

func (a *Simple) Explain() string

Explain returns the explanation for this simple action's Do member.

func (*Simple) Undo

func (a *Simple) Undo()

Undo does nothing. A simple action is not undoable.

func (*Simple) Undoable

func (a *Simple) Undoable() bool

Undoable always returns false. A simple action is not undoable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳