Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.

Commit 10e5f5a

Browse files
feat(Watch mode): improve console outputs
1 parent 46e9c86 commit 10e5f5a

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/prompt.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from colorama import init, Fore, Style
2+
3+
init(autoreset=True)
4+
5+
6+
def on_watch_start(exercise_path):
7+
print(f"{Style.BRIGHT}🤖🤖🤖 Watch mode started.")
8+
print(f"You can start to work on exercise {exercise_path}.\n")
9+
10+
11+
def on_exercise_success(exercise_path):
12+
print(f"{Style.BRIGHT}{Fore.GREEN}🥳🥳🥳 Exercise {exercise_path} completed!")
13+
print("You can keep working on this exercise,")
14+
print("or move on to the next one by removing the `I AM NOT DONE` comment.\n")
15+
16+
17+
def on_exercise_failure(exercise_path, error_message):
18+
print(f"{Fore.RED}🚧 Exercise {exercise_path} failed. Please try again.")
19+
print(error_message)
20+
21+
22+
def on_exercise_check(exercise_path):
23+
print(f"{Style.DIM}👀 Checking exercise {exercise_path}...")

src/runner.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from time import sleep
44
from src.exercise_checker.checker import ExerciceFailed, ProtostarExerciseChecker
55
from src.file_watcher.watcher import FileWatcher
6+
from src import prompt
67
from src.verify import ExerciseSeeker
78
from src.constants import exercise_files_architecture
89

@@ -12,20 +13,24 @@ def __init__(self, root_path: Path):
1213
self._file_watcher = FileWatcher(root_path)
1314
self._exercise_checker = ProtostarExerciseChecker(root_path)
1415
self._exercise_seeker = ExerciseSeeker(exercise_files_architecture, root_path)
16+
prompt.on_watch_start(self._exercise_seeker.find_next_exercise())
1517

1618
def on_file_changed(self, _):
1719
asyncio.run(self._check_exercise())
1820

1921
async def _check_exercise(self):
2022
next_exercise_path = self._exercise_seeker.find_next_exercise()
21-
print(f"Checking exercise {next_exercise_path}...")
23+
prompt.on_exercise_check(next_exercise_path)
2224
try:
23-
test_result = await self._exercise_checker.run(str(next_exercise_path))
24-
print(test_result)
25+
await self._exercise_checker.run(str(next_exercise_path))
26+
prompt.on_exercise_success(next_exercise_path)
2527
except ExerciceFailed as error:
26-
print(error.message)
28+
prompt.on_exercise_failure(next_exercise_path, error.message)
2729

2830
def run(self):
29-
self._file_watcher.start(self.on_file_changed)
30-
while True:
31-
sleep(5)
31+
try:
32+
self._file_watcher.start(self.on_file_changed)
33+
while True:
34+
sleep(5)
35+
except KeyboardInterrupt:
36+
pass

0 commit comments

Comments
 (0)