From 774e97260aa04d7bb6618395a003ed417993828e Mon Sep 17 00:00:00 2001 From: mat ess Date: Sun, 13 Aug 2023 17:50:40 -0400 Subject: [PATCH] more housekeeping --- justfile | 9 ++++++--- roll/cli/__init__.py | 16 +++++++++------- tests/cli/cli_test.py | 6 +++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/justfile b/justfile index b11262f..a64e4ae 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,5 @@ +set shell := ["fish", "-c"] + build: hatch build @@ -13,12 +15,13 @@ fmt: # run all checks test: typing lint hatch run check + @echo + @echo (set_color green)"all good ᕕ( ᐛ )ᕗ"(set_color normal) # create hatch envs env: - #!/usr/bin/env fish - for env in (hatch env show --json | jq 'keys[]' --raw-output) - hatch env create $env + for env in (hatch env show --json | jq 'keys[]' --raw-output); \ + hatch env create $env; \ end clean: diff --git a/roll/cli/__init__.py b/roll/cli/__init__.py index de2dbee..2b5a281 100644 --- a/roll/cli/__init__.py +++ b/roll/cli/__init__.py @@ -59,11 +59,12 @@ def cli(roll: Roll | Literal["advantage"] | Literal["disadvantage"]) -> None: throw = _advantage(roll) else: throw = _throw(roll) - click.echo(f"total:\t{throw.total: >5}") + total = f" {throw.total}" + click.secho(f"total:\t╰{total:╶>5}", bold=True) if throw.is_critical_hit: # pragma: no cover (random) - click.echo("critical hit!") + click.secho("critical hit!", fg="green", bold=True) elif throw.is_critical_miss: # pragma: no cover (random) - click.echo("critical miss!") + click.secho("critical miss!", fg="red", bold=True) def _advantage(advantage: str) -> Throw: @@ -72,8 +73,8 @@ def _advantage(advantage: str) -> Throw: roll = Roll() fst = roll.throw() snd = roll.throw() - click.echo(f"1:\t|{fst.total: >4}") - click.echo(f"2:\t|{snd.total: >4}") + click.echo(f"1:\t┆{fst.total: >5}") + click.echo(f"2:\t┆{snd.total: >5}") if advantage == "advantage": throw = fst if fst.total > snd.total else snd else: @@ -86,7 +87,8 @@ def _throw(roll: Roll) -> Throw: click.echo(f"throwing {roll.to_str()}:") throw = roll.throw() for i, result in enumerate(throw.results, start=1): - click.echo(f"{i}:\t|{result: >4}") + click.echo(f"{i}:\t┆{result: >5}") if roll.modifier: - click.echo(f"mod:\t{roll.modifier_str(): >5}") + color = "green" if roll.modifier > 0 else "red" + click.secho(f"mod:\t┆{roll.modifier_str(): >5}", fg=color) return throw diff --git a/tests/cli/cli_test.py b/tests/cli/cli_test.py index 72b365f..0789a45 100644 --- a/tests/cli/cli_test.py +++ b/tests/cli/cli_test.py @@ -13,7 +13,7 @@ def runner() -> CliRunner: def test_cli_smoke(runner: CliRunner): result = runner.invoke(cli, []) assert result.exit_code == 0 - assert result.output.startswith("throwing 1d20:\n1:\t|") + assert result.output.startswith("throwing 1d20:\n1:\t┆") assert "total" in result.output @@ -22,7 +22,7 @@ def test_cli_roll(runner: CliRunner, value: str): result = runner.invoke(cli, [value]) roll = Roll.from_str(value) assert result.exit_code == 0 - assert result.output.startswith(f"throwing {value}:\n1:\t|") + assert result.output.startswith(f"throwing {value}:\n1:\t┆") assert len(result.output.splitlines()) >= roll.dice_count + 2 assert "total" in result.output @@ -31,5 +31,5 @@ def test_cli_roll(runner: CliRunner, value: str): def test_cli_advantage(runner: CliRunner, advantage: str): result = runner.invoke(cli, [advantage]) assert result.exit_code == 0 - assert result.output.startswith(f"throwing 2d20 with {advantage}:\n1:\t|") + assert result.output.startswith(f"throwing 2d20 with {advantage}:\n1:\t┆") assert "total" in result.output