Debugging

package
v0.4.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// PointerArrow is the arrow used to indicate the current position of the pointer.
	PointerArrow string = "^"
)

Variables

This section is empty.

Functions

func DoWithBackup

func DoWithBackup[T Backuper[E], E any](subject T, f uc.EvalOneFunc[T, bool]) error

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

func PrintPointer(distance int) string

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.

func (*Command[T]) Copy added in v0.3.33

func (c *Command[T]) Copy() uc.Copier

Copy implements the Commander interface.

func (*Command[T]) Execute added in v0.3.33

func (c *Command[T]) Execute(data T) error

Execute implements the Commander interface.

func (*Command[T]) Undo added in v0.3.33

func (c *Command[T]) Undo(data T) error

Undo implements the Commander interface.

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

func NewCommand[T any](execute, undo func(data T) error) Commander[T]

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

func NewHistory[T any](data T) *History[T]

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]) Copy added in v0.3.33

func (h *History[T]) Copy() uc.Copier

Copy implements the uc.Copier interface.

func (*History[T]) ExecuteCommand added in v0.3.33

func (h *History[T]) ExecuteCommand(cmd Commander[T]) error

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

func (h *History[T]) Reject() error

Reject rejects the history, undoing all commands.

Returns:

  • error: An error if the undo fails.

func (*History[T]) UndoLastCommand added in v0.3.33

func (h *History[T]) UndoLastCommand() error

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

func (v *Verbose) Activate(active bool)

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

func (v *Verbose) IsActive() bool

IsActive returns true if the verbose output is active.

Returns:

  • bool: True if the verbose output is active, false otherwise.

func (*Verbose) Printf added in v0.3.34

func (v *Verbose) Printf(format string, args ...interface{})

Printf prints a formatted string if the verbose output is active.

Parameters:

  • format: The format string.

func (*Verbose) Println added in v0.3.34

func (v *Verbose) Println(args ...interface{})

Println prints a string if the verbose output is active.

Parameters:

  • args: The arguments to print.

Jump to

Keyboard shortcuts

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