From 5931fddd909711fa20ea9afcbf656586b7d30c22 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Thu, 26 Sep 2024 06:57:54 +0200 Subject: Refactor CLI --- src/flashcard_cli.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/flashcard_cli.py b/src/flashcard_cli.py index 8017c4d..be05be8 100644 --- a/src/flashcard_cli.py +++ b/src/flashcard_cli.py @@ -9,6 +9,19 @@ from card import Card def cli(): pass +def displayCard(card: Card, index: int, random_flip: bool) -> None: + click.echo(click.style(f"{index + 1} ===========================================================", fg="blue")) + + faces = [card.front, card.back] + + if random_flip: + shuffle(faces) + + click.echo(click.style(faces.pop(0), fg="yellow")) + input() + click.echo(faces.pop(0)) + + @cli.command() @click.argument("state_file", nargs=1, type=click.Path()) @click.argument("card_files", nargs=-1, type=click.Path(exists=True)) @@ -22,16 +35,7 @@ def practice(state_file, card_files, scheduler_name, count, random_flip): session = Session(scheduler_name, card_files, state_file) for i, card in enumerate(session.practice(count)): - click.echo(click.style(f"{i + 1} ===========================================================", fg="blue")) - - faces = [card.front, card.back] - - if random_flip: - shuffle(faces) - - click.echo(click.style(faces.pop(0), fg="yellow")) - input() - click.echo(faces.pop(0)) + displayCard(card, i, random_flip) @cli.command() @click.argument("state_file", nargs=1, type=click.Path()) @@ -46,18 +50,7 @@ def test(state_file, card_files, scheduler_name, count, random_flip): session = Session(scheduler_name, card_files, state_file) for i, (card, correct) in enumerate(session.test(count)): - click.echo(click.style(f"{i + 1} ===========================================================", fg="blue")) - - faces = [card.front, card.back] - - if random_flip: - shuffle(faces) - - click.echo(click.style(faces.pop(0), fg="yellow")) - input() - click.echo(faces.pop(0)) - click.echo() - + displayCard(card, i, random_flip) correct(click.confirm(click.style("Correct?", bold=True))) if __name__ == '__main__': -- cgit v1.2.3