Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions simple_typing_application/typing_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from logging import getLogger, Logger
import os


from .const.color import EColor
from .const.keys import EMetaKey
from .key_monitor.base import BaseKeyMonitor
Expand Down Expand Up @@ -93,6 +92,39 @@ def __init__(

os.makedirs(self._record_direc, exist_ok=True)

self._ui.system_anounce(self.title)
self._ui.system_anounce(self.instructions)

@property
def title(self) -> str:
from . import __version__

title_line = f" Simple Typing Application {__version__} "
return "\n".join(
[
"=" * len(title_line),
"",
title_line,
"",
"=" * len(title_line),
]
)

@property
def instructions(self) -> str:
return """Type the displayed characters as quickly and accurately as possible!

- How to Play:
1. A typing target will be displayed on the screen.
2. Type the characters exactly as shown.
3. Your input will be displayed in real-time, with correct inputs shown in green and incorrect inputs in red.
4. Once you complete the typing target, a new one will be generated automatically.

Key Commands:
- Press 'Esc' to exit the game at any time.
- Press 'Tab' to skip the current typing target.
"""

def start(self):
asyncio.run(self._main_loop())

Expand All @@ -110,6 +142,7 @@ async def _main_loop(self):
typing_target, _ = await asyncio.gather(task1, task2)

def _show_typing_target(self, typing_target: TypingTargetModel):
self._ui.system_anounce("")
self._ui.show_typing_target(
typing_target.text,
title="Typing Target",
Expand Down Expand Up @@ -149,9 +182,7 @@ async def _typing_step(self, typing_target: TypingTargetModel):
output.records = sorted(list(self.__current_records), key=lambda x: x.timestamp) # noqa
self._logger.debug(f"The following data has been saved to {output_path}: {output.model_dump(mode='json')}") # noqa
with open(output_path, "a", encoding="utf-8") as f:
json.dump(
output.model_dump(mode="json"), f, indent=4, ensure_ascii=False
) # noqa
json.dump(output.model_dump(mode="json"), f, indent=4, ensure_ascii=False) # noqa

# clean up
self.__clean_up_typing_step()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_typing_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def test_typing_game__skip_typing_step(typing_game_with_mocks: tuple[TypingGame,
typing_game, _ = typing_game_with_mocks

# execute
typing_game._ui.system_anounce.reset_mock() # type: ignore # noqa
typing_game._TypingGame__skip_typing_step() # type: ignore

# assert
Expand All @@ -309,6 +310,7 @@ def test_typing_game__done_typing_step(typing_game_with_mocks: tuple[TypingGame,
typing_game, _ = typing_game_with_mocks

# execute
typing_game._ui.system_anounce.reset_mock() # type: ignore # noqa
typing_game._TypingGame__done_typing_step() # type: ignore

# assert
Expand All @@ -324,6 +326,7 @@ def test_typing_game__exit_typing_step(typing_game_with_mocks: tuple[TypingGame,
typing_game, mocks = typing_game_with_mocks

# execute
typing_game._ui.system_anounce.reset_mock() # type: ignore # noqa
typing_game._TypingGame__exit_typing_step() # type: ignore

# assert
Expand Down
Loading