Skip to content

Commit acdcad7

Browse files
committed
Automatic backup 2025-08-29
1 parent 4c49c8f commit acdcad7

File tree

5 files changed

+89
-65
lines changed

5 files changed

+89
-65
lines changed

rich_tables/diff.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ def _(before: HashableDict, after: HashableDict) -> dict[str, str]:
147147
return data
148148

149149

150+
@diff.register
151+
def _(before: HashableDict, after: None) -> dict[str, str]:
152+
return diff(before, HashableDict())
153+
154+
155+
@diff.register
156+
def _(before: None, after: HashableDict) -> dict[str, str]:
157+
return diff(HashableDict(), after)
158+
159+
150160
def pretty_diff(before: Any, after: Any) -> str:
151161
"""Generate a Rich Text object showing differences between any two Python objects.
152162

rich_tables/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from rich.console import RenderableType
4141

4242

43-
MATCH_COUNT_HEADER = re.compile(r"duration|(?:_sum$|_count$)")
43+
MATCH_COUNT_HEADER = re.compile(r"duration|(?:_sum$|_?count$)")
4444
MAX_BPM_COLOR = (("green", 135), ("yellow", 165), ("red", 400))
4545

4646

rich_tables/table.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_args() -> argparse.Namespace:
8484
parser.add_argument("-v", "--verbose", action="store_true")
8585
parser.add_argument("-j", "--json", action="store_true", help="output as JSON")
8686
parser.add_argument(
87-
"-s", "--save", action="store_true", help="save the output as HTML"
87+
"-o", "--output-file", type=Path, help="save as SVG to provided file"
8888
)
8989

9090
subparsers = parser.add_subparsers(
@@ -137,23 +137,20 @@ def _draw_data_list(data: list[JSONDict], **__: Any) -> None:
137137

138138

139139
@contextmanager
140-
def handle_save(save: bool) -> Iterator[None]:
141-
if save:
142-
yield
143-
144-
if save:
145-
with tempfile.NamedTemporaryFile(suffix=".html", delete=False) as file:
146-
filename = file.name
147-
console.save_html(filename)
148-
print(f"Saved output as {filename}", file=sys.stderr)
149-
else:
150-
yield
140+
def handle_save(output_file: Path | None) -> Iterator[None]:
141+
if output_file:
142+
console.record = True
143+
144+
yield
145+
146+
if output_file:
147+
console.save_svg(str(output_file))
151148

152149

153150
def main() -> None:
154151
args = get_args()
155152

156-
with handle_save(args.save):
153+
with handle_save(args.output_file):
157154
if args.command == "diff":
158155
console.print(pretty_diff(args.before, args.after), highlight=False)
159156
else:

0 commit comments

Comments
 (0)