tiny8.utils module

Utility functions for Tiny8, including tqdm-like progress bar.

The ProgressBar class provides a simple, tqdm-like progress indicator that can be used to visualize long-running CPU executions or other iterative processes. The progress bar automatically adapts to the terminal width.

Example usage with CPU:
>>> from tiny8 import CPU, assemble
>>> asm = assemble("ldi r16, 10\nloop:\ndec r16\njmp loop")
>>> cpu = CPU()
>>> cpu.load_program(asm)
>>> cpu.run(max_steps=1000, show_progress=True)
CPU execution: 100.0%|████████████| 1000/1000 [00:00<00:00, 5000.00it/s]
Example usage standalone (auto-detect width):
>>> from tiny8 import ProgressBar
>>> with ProgressBar(total=100, desc="Processing") as pb:
...     for i in range(100):
...         # do work
...         pb.update(1)
Example usage with custom width:
>>> with ProgressBar(total=100, desc="Processing", ncols=60) as pb:
...     for i in range(100):
...         pb.update(1)
class tiny8.utils.ProgressBar(total=None, desc='', disable=False, ncols=None, mininterval=0.1)[source]

Bases: object

A simple tqdm-like progress bar for Tiny8 CPU execution.

Usage:
with ProgressBar(total=1000, desc=”Running”) as pb:
for i in range(1000):

# do work pb.update(1)

Or:

pb = ProgressBar(total=1000) for i in range(1000):

# do work pb.update(1)

pb.close()

Parameters:
__init__(total=None, desc='', disable=False, ncols=None, mininterval=0.1)[source]

Initialize progress bar.

Parameters:
  • total (int | None) – Total number of iterations (None for indeterminate)

  • desc (str) – Description prefix for the progress bar

  • disable (bool) – If True, disable the progress bar completely

  • ncols (int | None) – Width of the progress bar in characters (None for auto-detect)

  • mininterval (float) – Minimum time between updates in seconds

__enter__()[source]

Context manager entry.

__exit__(exc_type, exc_val, exc_tb)[source]

Context manager exit.

update(n=1)[source]

Update progress by n steps.

Parameters:

n (int) – Number of steps to increment

set_description(desc)[source]

Update the description.

Parameters:

desc (str) – New description string

close()[source]

Close the progress bar and print newline.

reset()[source]

Reset the progress bar to initial state.