summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2024-09-26 06:57:54 +0200
committerEddy Pedroni <epedroni@pm.me>2024-09-26 06:57:54 +0200
commit5931fddd909711fa20ea9afcbf656586b7d30c22 (patch)
treec36d31b124e97bc24ff86e712f5c2364c017a0fc /src
parent3f07b0b8f1a40b5b94622433b349c44267faca4f (diff)
Refactor CLI
Diffstat (limited to 'src')
-rw-r--r--src/flashcard_cli.py37
1 files changed, 15 insertions, 22 deletions
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__':