From 64dd8935b19e49c4e96a2e5232867a695819271e Mon Sep 17 00:00:00 2001 From: phette23 Date: Tue, 28 Jan 2025 20:20:00 -0800 Subject: [PATCH] fix: print leader with --color flag --- marcgrep/color.py | 6 ++++++ test/test_cli.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/marcgrep/color.py b/marcgrep/color.py index 8982525..305de7c 100644 --- a/marcgrep/color.py +++ b/marcgrep/color.py @@ -77,6 +77,12 @@ def color_field(field: Field, invert: bool) -> None: def color_record(record: Record, invert: bool) -> None: + # create COLORS global if we have not already + if not globals().get("COLOR"): + _setup_colors(invert) + + cprint("LDR", COLORS["TAG"], end=" ") + cprint(record.leader, COLORS["DATA"]) for field in record: color_field(field, invert) click.echo() diff --git a/test/test_cli.py b/test/test_cli.py index be5f4b8..b64cc28 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -180,3 +180,9 @@ def test_glob(self): ) assert result.exit_code == 0 assert len(result.output.splitlines()) == 1 + + def test_color_leader(self): + runner = CliRunner() + result = runner.invoke(main, ["--color", ONE_RECORD]) + assert result.exit_code == 0 + assert result.output.splitlines()[0] == "LDR 03292namaa2200793uu 4500"