-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_guide.py
107 lines (88 loc) · 3.96 KB
/
print_guide.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
This module will print the heading with title in every prompt so that
the user will have an option to view the instructions
or quit the application anywhere in the program.
"""
import sys
from textwrap import dedent
from colorama import Fore, Style
import emoji
def display_guide_on_top() -> None:
"""
Display the heading in every prompt.
"""
# Print new lines to have an illusion that clears the previous outputs
print('\n' * 200)
# Print separator line of hyphens
print('-' * 95) # print separator line of hyphens
# Print the Pregnancy Tracker app title
print(Fore.GREEN + Style.BRIGHT + emoji.emojize('\n :red_heart: Pregnancy Tracker App\n') + Style.RESET_ALL)
# Print separator line of hyphens
print('-' * 95) # print separator line of hyphens
print(Fore.CYAN + emoji.emojize(dedent('''
:open_book: Guide:
♦ Type 'INSTRUCTIONS' to display the instructions.
♦ Type 'QUIT' to exit the Pregnancy Tracker app.
♦ Hit enter after selecting an option or typing a command.
''')) + Style.RESET_ALL)
def guide_user_response(response: str) -> bool:
"""
Check if user enters 'INSTRUCTIONS' or 'QUIT' case-insensitive
Args:
response (str): User can enter 'INSTRUCTIONS' or 'QUIT' at any given time
Returns:
bool: True if the response matches "INSTRUCTIONS" (case-insensitive), otherwise False
"""
# Check if user wants to view the instructions
if response.lower() == 'instructions':
instructions()
# Display the guide for instructions and for quitting the app
display_guide_on_top() # From print_guide module
return True
# Check if user wants to exit the app
if response.lower() == 'quit':
print('\n' * 200)
print(Fore.GREEN + 'Thank you for using the Pregnancy Tracker app. Goodbye!\n' + Style.RESET_ALL)
sys.exit()
return False
def instructions() -> None:
"""
Display the instructions on how to use the Pregnancy Tracker app.
"""
while True:
print('-' * 110) # print separator line of hyphens as aesthetics only
# Display the instructions
print(Fore.CYAN + emoji.emojize('''
:open_book: Instructions
1. The Pregnancy Tracker App has three main features as follows.
Feature 1: Pregnancy Information :pregnant_woman:
Description: View details about your pregnancy.
Details:
a. Gestational age in weeks.
b. Trimester range (First, Second or Third)
c. Estimated Due Date or EDD
d. Countdown until EDD
Feature 2: Safety Information :safety_vest:
Description: Explore safety guidelines about pregnancy.
Details:
a. Food Safety - check safety of specific foods
b. Travel Safety - learn about safe travel practices
c. Activities Safety - know the safe activities during pregnancy
Feature 3: Note-taking :mobile_phone:
Description: Record personal notes on your pregnancy journey
2. Type the option number to select a feature.
3. Enter date in format DD/MM/YYYY.
4. Type 'INSTRUCTIONS' to view these instructions at any given time.
5. Type 'QUIT' to exit the Pregnancy Tracker app at any given time.
6. Hit ENTER after you type a command in the prompt (e.g., option number, INSTRUCTIONS, QUIT)
''') + Style.RESET_ALL)
# User can exit the instructions by entering 'CLOSE'
user_input = input('Enter "CLOSE" to exit these instructions.\n')
if user_input.lower() == 'close':
return None
if user_input.lower() == 'instructions':
continue
if user_input.lower() == 'quit':
sys.exit()
else:
print(Fore.RED + emoji.emojize(f':cross_mark: ERROR: "{user_input}" is an invalid choice.') + Style.RESET_ALL)