Exemplo n.º 1
0
def menu(two_way_card, single_line_mode, editor_mode):

    print()
    print_instruction('q: Discard this card and quit.')
    print_instruction('d: Discard this card and start over.')
    print_instruction('t: Toggle two-way card and start over.')
    print_instruction('s: Toggle single-line mode and start over.')
    print_instruction('e: Toggle editor-mode and start over.')

    while True:
        selection = colored_prompt('[q/d/t/s/e]: ')
        if selection in ['q', 'd', 't', 's', 'e']:
            break
    
    if selection == 'q':
        return None, None, None, None
    
    if selection == 'd':
        return new_card(two_way_card, single_line_mode, editor_mode)

    if selection == 't':
        return new_card(not two_way_card, single_line_mode, editor_mode)

    if selection == 's':
        return new_card(two_way_card, not single_line_mode, editor_mode)

    if selection == 'e':
        return new_card(two_way_card, single_line_mode, not editor_mode)
Exemplo n.º 2
0
def compose_in_editor(two_way_card):

    if two_way_card:
        print_info('Two-way mode is ON.')
    else:
        print_info('Two-way mode is OFF.')
    print_instruction('Hit Enter to continue in editor mode, or enter one of these options:')
    print_instruction('q: Quit.')
    print_instruction('t: Toggle two-way card and continue in editor mode.')
    print_instruction('m: Continue in normal multi-line mode.')
    print_instruction('s: Continue in single-line mode.')
    while True:
        selection = colored_prompt('[q/t/m/s]: ')
        if selection in ['q', 't', 'm', 's', '']:
            break

    if selection == 'q':
        return None, None, None, None

    if selection == 't':
        two_way_card = not two_way_card

    if selection == 'm':
        return new_card(two_way_card, single_line_mode=False, editor_mode=False)

    if selection == 's':
        return new_card(two_way_card, single_line_mode=True, editor_mode=False)

    bogus_timestamp = '1991-08-25 20:57:08'
    empty_card = Card('', '', 0, bogus_timestamp)

    card = edit(empty_card, two_way_card)

    return card, two_way_card, False, True
Exemplo n.º 3
0
def review_card(card):
    
    print(card.front)
    colored_getpass('[Enter to flip the card.]')
    print(card.back)

    while True:
        score = colored_prompt("[Score yourself from 0 to 5, or enter 'o' for options:] ")
        if score == 'o':
            return menu(card)
        if score.isdigit() and int(score) in list(range(6)):
            break
    
    contents_changed = False

    last_viewed = get_timestamp()

    updated_card = Card(
        card.front, 
        card.back, 
        score, 
        last_viewed
    )

    return updated_card, contents_changed
Exemplo n.º 4
0
def read_input(single_line_mode):

    try:
        if single_line_mode:
            line = colored_prompt(prompt)
            return line
        else:
            lines = []
            while True:
                try:
                    line = colored_prompt(prompt)
                    lines.append(line)
                except EOFError:
                    print(end = '\r')
                    return '\n'.join(lines)
    except KeyboardInterrupt:
        return None
Exemplo n.º 5
0
def include_flipped_card():

    print_info('This is a two-way card.')
    print_info('Should your changes also affect the flipped version of this card?')
    while True:
        answer = colored_prompt('[y/n]: ')
        if answer in ['y', 'n']:
            break
    if answer == 'y':
        return True
    else:
        return False
Exemplo n.º 6
0
def menu(card):
    
    contents_changed = True

    print_instruction('e: Edit this card.')
    print_instruction('d: Delete this card.')

    while True:
        selection = colored_prompt('[e/d]: ')
        if selection in ['e', 'd']:
            break

    if selection == 'e':
        two_way_card = False
        return edit(card, two_way_card), contents_changed
    elif selection == 'd':
        return None, contents_changed
Exemplo n.º 7
0
def pick_db_file():

    db_files = parse_db_files()
    
    garrick_dir, _ = locate_config_file()

    if len(db_files) == 1:

        db_file = db_files[0]

    else:

        for i in range(len(db_files)):
            print('{}. {}'.format(i + 1, db_files[i]))

        while True:
            selection = colored_prompt('Enter the number of the database file to use: ')
            if selection.isdigit() and int(selection) in range(1, len(db_files) + 1):
                db_number = int(selection)
                break

        db_file = db_files[db_number - 1]

    return os.path.join(garrick_dir, db_file)
Exemplo n.º 8
0
def iterate(conn, cursor, iterator, count):

    if count == 0:
        print_error('No results.')
    elif count == 1:
        print_info('[1 CARD.]')
    else:
        print_info('[{} CARDS.]'.format(count))

    try:
        for card in iterator:

            print_instruction('[Ctrl+C to quit.]')

            updated_card, contents_changed = review_card(card)

            is_two_way_card = card_repository.is_two_way_card(cursor, card)

            if is_two_way_card and contents_changed:
                flipped_card_too = include_flipped_card()
            else:
                flipped_card_too = False

            if updated_card == None:
                card_repository.delete(conn, cursor, card)
                if flipped_card_too:
                    card_repository.delete_flipped_card(conn, cursor, card)
                    count -= 1
                # Not an error, but I feel this should be red.
                print_error('DELETED.')
                table_is_empty = card_repository.check_if_empty(cursor)
                if table_is_empty:
                    print_info('You have no more cards!')
                    break
            else:
                if contents_changed:

                    while True:
                        card_repository.insert(conn, cursor, updated_card)
                        if flipped_card_too:
                            card_repository.insert_flipped_card(conn, cursor, updated_card)
                        else:
                            bump_flipped_card_timestamp(conn, cursor, card)
                        print_instruction('Create another version based on this same card?')
                        print_info('Protip: This is how you split one card into several cards.')
                        while True:
                            answer = colored_prompt('[y/n]: ')
                            if answer in ['y', 'n']:
                                break
                        if answer == 'n':
                            break
                        else:
                            updated_card = edit(card, flipped_card_too)

                    card_repository.delete(conn, cursor, card)
                    if flipped_card_too:
                        card_repository.delete_flipped_card(conn, cursor, card)
                else:
                    card_repository.insert(conn, cursor, updated_card)
                    card_repository.delete(conn, cursor, card)
                    bump_flipped_card_timestamp(conn, cursor, card)
            
            count -= 1

            if count > 0:
                print_info('[{} MORE:]'.format(count))

    except KeyboardInterrupt:
        print()
Exemplo n.º 9
0
def browse_by_score(conn, cursor):
    score = colored_prompt('Show cards with the following score: ')
    results = card_repository.select_by_score(cursor, score)
    browse(conn, cursor, results)
Exemplo n.º 10
0
def browse_by_regex_back(conn, cursor):
    regex = colored_prompt('Enter regular expression: ')
    results = card_repository.select_by_regex_back(cursor, regex)
    browse(conn, cursor, results)