Documentation ¶
Index ¶
Constants ¶
const ( // PointerArrow is the arrow used to indicate the current position of the pointer. PointerArrow string = "^" )
Variables ¶
This section is empty.
Functions ¶
func DoWithBackup ¶
DoWithBackup executes a function with a backup of the subject object.
Parameters:
- subject: The object to create a backup of.
- f: The function to execute.
Returns:
- error: An error if the function fails.
Behaviors:
- If the function fails or does not accept the subject object, the subject object is restored from the backup. Otherwise, the subject object is left as is.
func PrintPointer ¶
PrintPointer generates a string representation of a pointer at a given distance.
Parameters:
- distance: The distance of the pointer from the current position.
Returns:
- string: A string representation of the pointer.
Behaviors:
- Negative distance: The pointer is to the left of the current position.
- Positive distance: The pointer is to the right of the current position.
- 0: The pointer is at the current position.
Types ¶
type Backuper ¶
type Backuper[T any] interface { // Backup creates a backup of the object. // // Returns: // - T: The backup of the object. Backup() T // Restore restores the object from a backup. // // Parameters: // - backup: The backup of the object. // // Returns: // - error: An error if the restoration fails. Restore(backup T) error }
Backuper is an interface that represents a type that can be backed up and restored.
type Command ¶ added in v0.3.33
type Command[T any] struct { // contains filtered or unexported fields }
Command represents a generic command that can be executed and undone.
type Commander ¶ added in v0.3.33
type Commander[T any] interface { // Execute executes the command. // // Parameters: // - data: The data to execute the command on. // // Returns: // - error: An error if the execution fails. Execute(data T) error // Undo undoes the command. // // Parameters: // - data: The data to undo the command on. // // Returns: // - error: An error if the undo fails. Undo(data T) error uc.Copier }
Commander is an interface that represents a command that can be executed and undone.
func NewCommand ¶ added in v0.3.33
NewCommand creates a new command with the given execute and undo functions.
Parameters:
- execute: The function to execute the command.
- undo: The function to undo the command.
Returns:
- Commander: The new command.
Behaviors:
- If either the execute or undo functions are nil, nil is returned.
type History ¶ added in v0.3.33
type History[T any] struct { // contains filtered or unexported fields }
History represents a history of commands that can be executed and undone.
func NewHistory ¶ added in v0.3.33
NewHistory creates a new history with the given data.
Parameters:
- data: The data to create the history with.
Returns:
- *History: The new history.
func (*History[T]) Accept ¶ added in v0.3.33
func (h *History[T]) Accept()
Accept accepts the history, clearing the commands.
WARNING: Because the commands are cleared, they cannot be undone after accepting the history. Thus, be sure to use this method only when you are certain that you will never need to undo the commands.
func (*History[T]) ExecuteCommand ¶ added in v0.3.33
ExecuteCommand executes a command on the history.
Parameters:
- cmd: The command to execute.
Returns:
- error: An error if the execution fails.
Behaviors:
- If the command is nil, no action is taken.
func (*History[T]) GetData ¶ added in v0.3.34
func (h *History[T]) GetData() T
GetData returns the data from the history.
func (*History[T]) ReadData ¶ added in v0.3.33
func (h *History[T]) ReadData(f func(data T))
ReadData reads the data from the history.
Parameters:
- f: The function to read the data.
Behaviors:
- The function is called with the data from the history.
func (*History[T]) Reject ¶ added in v0.3.33
Reject rejects the history, undoing all commands.
Returns:
- error: An error if the undo fails.
func (*History[T]) UndoLastCommand ¶ added in v0.3.33
UndoLastCommand undoes the last command executed on the history.
Returns:
- error: An error if the undo fails.
Behaviors:
- If there are no commands to undo, no action is taken.
type Verbose ¶ added in v0.3.34
type Verbose struct {
// contains filtered or unexported fields
}
Verbose is a struct that can be used to print verbose output.
func NewVerbose ¶ added in v0.3.34
func NewVerbose() *Verbose
NewVerbose creates a new Verbose struct.
Returns:
- *Verbose: The new Verbose struct.
func (*Verbose) Activate ¶ added in v0.3.34
Activate activates or deactivates the verbose output.
Parameters:
- active: The boolean that determines if the verbose output is active.
func (*Verbose) IsActive ¶ added in v0.3.34
IsActive returns true if the verbose output is active.
Returns:
- bool: True if the verbose output is active, false otherwise.