pyfcstm.entry.simulate.display

State display formatting for the simulation REPL.

This module provides the StateDisplay class for formatting state machine information with ANSI color support for terminal output.

StateDisplay

class pyfcstm.entry.simulate.display.StateDisplay(use_color: bool = True, logger: Logger | None = None)[source]

Formatter for displaying state machine information in the terminal.

This class handles formatting of current state, variables, and events with ANSI color support. Colors are automatically disabled on terminals that don’t support them.

Variables:
  • use_color (bool) – Whether to use ANSI color codes

  • logger (logging.Logger) – Logger instance for log messages

__init__(use_color: bool = True, logger: Logger | None = None)[source]

Initialize the state display formatter.

Parameters:
  • use_color (bool, optional) – Whether to use ANSI colors, defaults to True

  • logger (logging.Logger, optional) – Logger instance for log messages, defaults to None

format_current_state(runtime) str[source]

Format current state and variable information.

Parameters:

runtime (SimulationRuntime) – The simulation runtime instance

Returns:

Formatted state and variables display

Return type:

str

format_events(events: List[Tuple[str, str | None]]) str[source]

Format event list.

Parameters:

events (List[Tuple[str, Optional[str]]]) – List of (full_path, short_name) tuples

Returns:

Formatted events display

Return type:

str

format_table(headers: list, rows: list, var_names: list | None = None) str[source]

Format data as a centered table with colors.

Parameters:
  • headers (list) – List of column headers

  • rows (list) – List of row data (each row is a list)

  • var_names (list, optional) – List of variable names for coloring, defaults to None

Returns:

Formatted table string

Return type:

str

log(message: str, level: str = 'info')[source]

Output log message using the configured logger.

This method delegates to the logger instance configured during initialization. If no logger is configured, the message is silently ignored.

Parameters:
  • message (str) – The log message

  • level (str, optional) – Log level (debug, info, warning, error), defaults to “info”