Esempio 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)
Esempio 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
Esempio n. 3
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
Esempio n. 4
0
def new_card(two_way_card, single_line_mode, editor_mode):

    if editor_mode:

        return compose_in_editor(two_way_card)

    else:

        if single_line_mode:
            print_instruction('[Ctrl+C: Discard this card and get a menu.]')
        else:
            print_instruction(
                '[Ctrl+D: Finish current side. Ctrl+C: Discard this card and get a menu.]'
            )

        if two_way_card:
            print_side('Side 1:')
        else:
            print_side('Front:')
            
        front = read_input(single_line_mode)
        if front == None:
            return menu(two_way_card, single_line_mode, editor_mode)

        if two_way_card:
            print_side('Side 2:')
        else:
            print_side('Back:')

        back = read_input(single_line_mode)
        if back == None:
            return menu(two_way_card, single_line_mode, editor_mode)

        last_viewed = get_timestamp()

        card = Card(front, back, 0, last_viewed)

        return card, two_way_card, single_line_mode, editor_mode
Esempio n. 5
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()
Esempio n. 6
0
def main():

    # Initialise colorama
    colorama.init()

    valid_args = ['-n', '-n2', '-s', '-s2', '-e', '-e2', '-b', '-bf', '-bb', '-bs', '-bl', '-br']

    if len(sys.argv) > 1 and sys.argv[1] not in valid_args:
        print_usage_info(sys.argv)        
        if sys.argv[1] not in ['-h', '--help']:
            sys.exit(1)
        sys.exit()

    db_file = pick_db_file()
    conn, cursor = db_connection.connect(db_file)
    card_repository.create_table_if_not_exists(conn, cursor)
    
    if len(sys.argv) == 1:
        table_is_empty = card_repository.check_if_empty(cursor)
        if table_is_empty:
            print_error("You don't have any cards yet.")
            print_instruction(
                'Create some cards by launching garrick with one of the following options first:'
            )
            print_instruction('\t-n\tCreate cards starting in one-way mode.')
            print_instruction('\t-n2\tCreate cards starting in two-way mode.')
            print_instruction('\t-s\tCreate cards starting in single-line and one-way mode.')
            print_instruction('\t-s2\tCreate cards starting in single-line and two-way mode.')
            print_instruction('\t-e\tCreate cards starting in editor mode and in one-way mode.')
            print_instruction('\t-s2\tCreate cards starting in editor mode and in two-way mode.')
        else:
            review.review(conn, cursor)
    elif sys.argv[1] == '-n':
        new_cards(conn, cursor, two_way_card=False, single_line_mode=False, editor_mode=False)
    elif sys.argv[1] == '-n2':
        new_cards(conn, cursor, two_way_card=True, single_line_mode=False, editor_mode=False)
    elif sys.argv[1] == '-s':
        new_cards(conn, cursor, two_way_card=False, single_line_mode=True, editor_mode=False)
    elif sys.argv[1] == '-s2':
        new_cards(conn, cursor, two_way_card=True, single_line_mode=True, editor_mode=False)
    elif sys.argv[1] == '-e':
        new_cards(conn, cursor, two_way_card=False, single_line_mode=False, editor_mode=True)
    elif sys.argv[1] == '-e2':
        new_cards(conn, cursor, two_way_card=True, single_line_mode=False, editor_mode=True)
    elif sys.argv[1] == '-b':
        review.browse_by_regex(conn, cursor) 
    elif sys.argv[1] == '-bf':
        review.browse_by_regex_front(conn, cursor) 
    elif sys.argv[1] == '-bb':
        review.browse_by_regex_back(conn, cursor) 
    elif sys.argv[1] == '-bs':
        review.browse_by_score(conn, cursor)
    elif sys.argv[1] == '-bl':
        review.browse_by_last_viewed(conn, cursor)
    elif sys.argv[1] == '-br':
        review.browse_by_last_viewed_reverse(conn, cursor)
    
    print_info('Kbai')
    
    db_connection.disconnect(conn, cursor)