Files
7000pctAUTO 72bec60e37
Some checks failed
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / test (3.10) (push) Has been cancelled
Add formatters (table, JSON, text)
2026-02-02 10:09:25 +00:00

29 lines
694 B
Python

"""Base formatter class."""
from abc import ABC, abstractmethod
from typing import Any, Optional, TextIO
class OutputFormatter(ABC):
"""Abstract base class for output formatters."""
def __init__(self, output: Optional[TextIO] = None):
self.output = output
@abstractmethod
def format(self, data: Any) -> str:
"""Format data for output."""
pass
def write(self, text: str) -> None:
"""Write to output stream."""
if self.output:
self.output.write(text)
else:
print(text, end="")
def flush(self) -> None:
"""Flush output stream."""
if self.output:
self.output.flush()