state_machine_viz

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorGreen  = "\033[32m"
	ColorRed    = "\033[31m"
	ColorGray   = "\033[90m"
	ColorYellow = "\033[33m"
)

Color constants for terminal output

View Source
const (
	SymbolPassed    = "🟢"
	SymbolFailed    = "🔴"
	SymbolUnvisited = "⚪"
	SymbolFailedTx  = "❌"
)

Symbol constants for visualization

Variables

This section is empty.

Functions

func Render added in v0.0.12

func Render[T any](sm *state_machine.StateMachine[T], passedStates []string, failedStates []string, failedTransition string, options VisualizationOptions) string

Render generates a text-based visualization of a state machine with color-coded states based on their status.

Parameters: - sm: The state machine to visualize. Can be any type of StateMachine[T]. - passedStates: Slice of state names that have been successfully traversed - failedStates: Slice of state names that failed during traversal - failedTransition: Optional name of the transition/event that failed - options: Optional visualization options

Returns: - string: A formatted string representation of the state machine diagram

func RenderAllPassed added in v0.0.12

func RenderAllPassed[T any](sm *state_machine.StateMachine[T]) string

RenderAllPassed generates a visualization where all states are marked as passed, using default visualization options. This is the simplest API for state machine visualization.

Parameters: - sm: The state machine to visualize. Can be any type of StateMachine[T].

Returns: - string: A formatted string representation of the state machine diagram with all states marked as passed

func RenderAllPassedOptions added in v0.0.12

func RenderAllPassedOptions[T any](sm *state_machine.StateMachine[T], options VisualizationOptions) string

RenderAllPassedOptions generates a visualization where all states are marked as passed. This is a simplified API for VisualizeStateMachine that marks all states as passed.

Parameters: - sm: The state machine to visualize. Can be any type of StateMachine[T]. - options: Visualization options

Returns: - string: A formatted string representation of the state machine diagram with all states marked as passed

func RenderFailed added in v0.0.12

func RenderFailed[T any](sm *state_machine.StateMachine[T], failedTransition string) string

RenderFailed is a convenience function that visualizes a state machine with a failed transition using default visualization options. This is the simplest API for visualizing a failed transition.

Parameters: - sm: The state machine to visualize - failedTransition: The name of the transition that failed

Returns: - string: A formatted string representation of the state machine diagram

func RenderFailedOptions added in v0.0.12

func RenderFailedOptions[T any](
	sm *state_machine.StateMachine[T],
	failedTransition string,
	options VisualizationOptions,
) string

RenderFailedOptions generates a visualization by automatically determining passed states and failed states based on a failed transition.

Parameters: - sm: The state machine to visualize - failedTransition: The name of the transition that failed - options: Optional visualization options

Returns: - string: A formatted string representation of the state machine diagram

Types

type VisualizationOptions

type VisualizationOptions struct {
	UseUnicode bool // Whether to use Unicode symbols (true) or ASCII (false)
	UseColors  bool // Whether to use ANSI color codes
	Compact    bool // Whether to use a compact representation
}

VisualizationOptions contains configuration options for the visualization

func DefaultOptions

func DefaultOptions() VisualizationOptions

DefaultOptions returns the default visualization options

Jump to

Keyboard shortcuts

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