summaryrefslogtreecommitdiffstats
path: root/src/flashcard_cli.py
blob: 8017c4d989ba73eed1c1f6aad2d7f2ea6e708c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import click
from random import shuffle

from scheduler import SCHEDULERS
from session import Session
from card import Card

@click.group()
def cli():
    pass

@cli.command()
@click.argument("state_file", nargs=1, type=click.Path())
@click.argument("card_files", nargs=-1, type=click.Path(exists=True))
@click.option("--scheduler", "scheduler_name", default="brutal", type=click.Choice(SCHEDULERS, case_sensitive=False), help="Name of desired scheduler")
@click.option("--count", default=20, type=int, help="Number of cards to show during the session")
@click.option("--random_flip", is_flag=True, help="Prompt with card front or back randomly instead of always front")
def practice(state_file, card_files, scheduler_name, count, random_flip):
    """
    Run a practice session with the specified scheduler, using the provided state and card files.
    """
    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))

@cli.command()
@click.argument("state_file", nargs=1, type=click.Path())
@click.argument("card_files", nargs=-1, type=click.Path(exists=True))
@click.option("--scheduler", "scheduler_name", default="brutal", type=click.Choice(SCHEDULERS, case_sensitive=False), help="Name of desired scheduler")
@click.option("--count", default=20, type=int, help="Number of cards to show during the session")
@click.option("--random_flip", is_flag=True, help="Prompt with card front or back randomly instead of always front")
def test(state_file, card_files, scheduler_name, count, random_flip):
    """
    Run a test session with the specified scheduler, using the provided state and card files.
    """
    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()

        correct(click.confirm(click.style("Correct?", bold=True)))

if __name__ == '__main__':
    cli()