Application API¶
Import these objects from anihmm in normal application code.
anihmm
¶
Application-facing API for terminal HMM animations.
AnihmmError
¶
Bases: Exception
Base exception for public anihmm API failures.
AnimationConfigError
¶
Bases: AnihmmError, ValueError
Invalid playback or rendering configuration.
AnimationSession
¶
Background animation session for embedding in terminal workflows.
__exit__
¶
__exit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Stop the session and preserve any exception from the context body.
__init__
¶
__init__(
frames: FrameSource,
*,
options: PlaybackOptions | None = None,
fps: float = DEFAULT_FPS,
columns: int | None = None,
repeat: bool = True,
hold_final_seconds: float | None = None,
console: Console | None = None,
enabled: bool | None = None,
alternate_screen: bool = False,
) -> None
Create a reusable background session for frames.
wait
¶
Wait for the active run and surface its timeout or worker error.
AnimationTimeoutError
¶
Bases: SessionError, TimeoutError
Animation session did not finish before the requested timeout.
AsyncAnimationSession
¶
Async wrapper around :class:AnimationSession.
__aenter__
async
¶
Start the wrapped session on async context entry.
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Stop the session and preserve any exception from the context body.
__init__
¶
__init__(
frames: FrameSource,
*,
options: PlaybackOptions | None = None,
fps: float = DEFAULT_FPS,
columns: int | None = None,
repeat: bool = True,
hold_final_seconds: float | None = None,
console: Console | None = None,
enabled: bool | None = None,
alternate_screen: bool = False,
) -> None
Create an async wrapper around a background animation session.
start
async
¶
Start the wrapped background session and return this wrapper.
wait
async
¶
Await completion and surface timeout or worker errors.
FrameCompilationError
¶
Bases: AnihmmError, ValueError
Failure while compiling semantic steps into renderable frames.
HMMFrame
dataclass
¶
A single renderable HMM lattice frame.
HMMSequence
¶
Stateful builder for semantic HMM animation steps.
__init__
¶
Create a sequence at a canonical node with optional bounds.
cycle
¶
Add a transient preview of the next state without committing it.
emit
¶
Emit one visible terminal-cell symbol from the current state.
finish
¶
Fill remaining bounded columns with deletions, then commit E.
flash_current
¶
Add a transient flash overlay to the current state.
settle
¶
Commit a transition to the next state of kind.
InvalidTransitionError
¶
Bases: SequenceError
Invalid lattice transition or node reference.
PlaybackOptions
dataclass
¶
Runtime playback configuration.
background
classmethod
¶
background(
*,
fps: float = DEFAULT_FPS,
hold_final_seconds: float | None = None,
console: Console | None = None,
enabled: bool | None = None,
alternate_screen: bool = False,
) -> PlaybackOptions
Build options for looping background playback sessions.
ProcessingOptions
dataclass
¶
ProgressSession
¶
Cycle candidate transitions until application work advances the path.
__exit__
¶
__exit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Stop playback while preserving exceptions raised by the work block.
__init__
¶
__init__(
*,
columns: int = 8,
fps: float = DEFAULT_FPS,
settle_seconds: float = _DEFAULT_SETTLE_SECONDS,
console: Console | None = None,
enabled: bool | None = None,
alternate_screen: bool = False,
) -> None
Create a single-use progress session for a bounded HMM lattice.
advance
¶
Settle on the chosen state, then begin scanning its outgoing transitions.
wait
¶
Wait for playback to stop and surface timeout or worker errors.
SequenceError
¶
Bases: AnihmmError, ValueError
Invalid semantic sequence construction.
SessionError
¶
Bases: AnihmmError, RuntimeError
Failure while starting, stopping, or monitoring a background session.
animate_frames
¶
animate_frames(
frames: FrameSource,
*,
fps: float = DEFAULT_FPS,
columns: int | None = None,
repeat: bool = False,
hold_final_seconds: float | None = None,
console: Console | None = None,
stop_event: Event | None = None,
enabled: bool | None = None,
alternate_screen: bool = False,
) -> None
Render frames synchronously with optional repetition and cancellation.
async_processing_animation
¶
async_processing_animation(
processing: ProcessingOptions | None = None,
playback: PlaybackOptions | None = None,
) -> AsyncAnimationSession
Build an asynchronous background animation session from reusable options.
compile_steps
¶
Compile semantic steps with a shared explicit or inferred column count.
print_frame_in_place
¶
print_frame_in_place(
frame: HMMFrame,
*,
console: Console | None = None,
columns: int | None = None,
) -> None
Replace the previous fixed-height lattice region with frame.
processing_animation
¶
processing_animation(
processing: ProcessingOptions | None = None,
playback: PlaybackOptions | None = None,
) -> AnimationSession
Build a synchronous background animation session from reusable options.
progress_animation
¶
progress_animation(
*,
columns: int = 8,
fps: float = DEFAULT_FPS,
settle_seconds: float = _DEFAULT_SETTLE_SECONDS,
console: Console | None = None,
enabled: bool | None = None,
alternate_screen: bool = False,
) -> ProgressSession
Build a work-driven progress session for use as a context manager.