""" Library for generating roff markup. This library is FAR from complete, and supports exactly what these scripts require. For information about roff commands meaning, see groff_man(7). """ import os from datetime import datetime from typing import TypeAlias, Literal Align: TypeAlias = Literal['R', 'L'] def title_heading(topic: str, section: int, *, footer_middle: str | None = None, footer_inside: str | None = None, header_middle: str | None = None): print(f'.TH "{topic.upper()}" {section} "{footer_middle}"') def section_heading(s: str): print(f'.SH "{s.upper()}"') def subsection_heading(s: str): print(f'.SS "{s}"') def roff_table(headers: list[tuple[str, Align]], keys: list[str], entries: list[dict[str, str]]): print(".TS") print("tab(@);") print(' '.join([a for (_, a) in headers] + ['.'])) print("@".join(h for (h, _) in headers)) for entry in entries: print("@".join(entry[key] for key in keys)) print(".TE") def now(): if ct := os.getenv("CURRENT_TIME"): if ct.isnumeric(): return datetime.fromtimestamp(int(ct)) else: return datetime.fromisoformat(ct) else: return datetime.now()