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"