Ejemplo n.º 1
0
def ask_for_work() -> Optional[str]:
    author_with_works = ask_for_author.prompt()

    if not author_with_works:
        return None

    options: list[WorkOption] = build_work_options(author_with_works.works)

    selected_work = None

    while selected_work is None:

        selected_work = radio_list.prompt(
            title="Select work:",
            options=options,
        )

        if selected_work is None:
            break

    if not selected_work:
        return None

    if confirm("{0}?".format(selected_work.title)):
        return selected_work.slug

    return ask_for_work()
Ejemplo n.º 2
0
def prompt() -> Optional[booklog_api.AuthorWithWorks]:
    name = None

    while name is None:
        name = ask.prompt("Author: ")

    authors = booklog_api.search_authors(name)

    options: list[AuthorOption] = build_author_options(authors)

    selected_author = None

    while selected_author is None:

        selected_author = radio_list.prompt(
            title="Select author:",
            options=options,
        )

        if selected_author is None:
            break

    if not selected_author:
        return None

    if confirm("{0}?".format(selected_author.name)):
        return selected_author

    return prompt()
Ejemplo n.º 3
0
def prompt() -> Optional[booklog_api.WorkWithAuthors]:
    title = None

    while title is None:
        title = ask.prompt("Title: ")

    works = booklog_api.search_works(title)

    options: list[WorkOption] = build_work_options(works)

    selected_work = None

    while selected_work is None:

        selected_work = radio_list.prompt(
            title="Select work:",
            options=options,
        )

        if selected_work is None:
            break

    if not selected_work:
        return None

    if confirm("{0}?".format(selected_work.title)):
        return selected_work

    return prompt()
Ejemplo n.º 4
0
def prompt() -> None:
    options = [
        (None, "Go back"),
        (add_author.prompt, "<cyan>Add Author</cyan>"),
        (add_work.prompt, "<cyan>Add Work</cyan>"),
    ]

    option_function = radio_list.prompt(
        title="Manage Data:",
        options=options,
    )

    if option_function:
        option_function()
        prompt()
Ejemplo n.º 5
0
def prompt() -> None:
    options = [
        (manage_data.prompt, "<cyan>Manage Data</cyan>"),
        (add_review.prompt, "<cyan>Add Review</cyan>"),
        (export, "<cyan>Export Data</cyan>"),
        (None, "Exit"),
    ]

    option_function = radio_list.prompt(
        title="Booklog options:",
        options=options,
    )
    if option_function:
        option_function()
        prompt()
Ejemplo n.º 6
0
def ask_for_kind() -> Optional[str]:
    options: list[Option] = build_kind_options()

    selected_kind = None

    while selected_kind is None:

        selected_kind = radio_list.prompt(
            title="Select kind:",
            options=options,
        )

        if selected_kind is None:
            break

    return selected_kind
Ejemplo n.º 7
0
def ask_for_edition() -> Optional[str]:
    options: List[Option] = build_edition_options()

    selected_edition = None

    while selected_edition is None:

        selected_edition = radio_list.prompt(
            title="Select edition:",
            options=options,
        )

        selected_edition = selected_edition or new_edition()

        if selected_edition is None:
            break

    if not selected_edition:
        return None

    if confirm("{0}?".format(selected_edition)):
        return selected_edition

    return ask_for_edition()
Ejemplo n.º 8
0
def test_can_use_home_to_jump_to_top(mock_input: MockInput, options: Options) -> None:
    mock_input([End, Home, Enter])

    assert radio_list.prompt("Test", options) == 1
Ejemplo n.º 9
0
def test_can_use_end_to_jump_to_bottom(mock_input: MockInput, options: Options) -> None:
    mock_input([End, Enter])

    assert radio_list.prompt("Test", options) == 4
Ejemplo n.º 10
0
def test_can_use_down_to_wrap_to_top(mock_input: MockInput, options: Options) -> None:
    mock_input([Up, Down, Enter])

    assert radio_list.prompt("Test", options) == 1