From b3b6da8ae08a738b5548109e42eaad749d3234e3 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Thu, 2 Mar 2017 20:45:53 +0100 Subject: Added colouring for card fronts, card numbering and clean exit --- flashcards | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'flashcards') diff --git a/flashcards b/flashcards index 7ba5fa6..e0ba548 100755 --- a/flashcards +++ b/flashcards @@ -5,8 +5,7 @@ import sys from pathlib import Path from random import shuffle -''' -class color: +class Color: PURPLE = '\033[95m' CYAN = '\033[96m' DARKCYAN = '\033[36m' @@ -18,8 +17,7 @@ class color: UNDERLINE = '\033[4m' END = '\033[0m' -print color.BOLD + 'Hello World !' + color.END -''' +#print color.BOLD + 'Hello World !' + color.END cardRegex = "CARD: " prefixLength = len(cardRegex) @@ -63,15 +61,21 @@ def extractCards(f): cards.append([front.strip(), back.strip()]) return cards +# Waits for user input and reacts accordingly +def wait(): + cmd = input().strip() + if cmd.startswith("q") or cmd.startswith("quit") or cmd.startswith("exit"): + sys.exit(0) + # Loops serving cards to the user until the program is exited def serveCards(cards): while True: - for card in cards: - print("----------------------------------------------------------------------------") - print(card[0]) - input() + for i, card in enumerate(cards): + print("----------------------------------------------------------------------------(" + str(i + 1) + "/" + str(len(cards)) + ")") + print(Color.BLUE + Color.BOLD + card[0] + Color.END) + wait() print(card[1]) - input() + wait() def debugCards(cardList): for c in cardList: -- cgit v1.2.3