Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the length of characters for current_word #66

Merged
merged 4 commits into from Nov 1, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions mitype/app.py
Expand Up @@ -58,6 +58,9 @@ def __init__(self):
self.window_width = 0
self.line_count = 0

self.current_word_limit = 25
self.current_word_limit_reached = False

self.test_complete = False

self.current_speed_wpm = 0
Expand Down Expand Up @@ -247,6 +250,8 @@ def erase_key(self):
self.current_word = self.current_word[0 : len(self.current_word) - 1]
self.current_string = self.current_string[0 : len(self.current_string) - 1]

self.current_word_limit_reached = False

def check_word(self):
"""Accept finalized word."""
spc = get_space_count_after_ith_word(len(self.current_string), self.text)
Expand All @@ -264,8 +269,14 @@ def appendkey(self, key):
Args:
key (key): character to append
"""
self.current_word += key
self.current_string += key

jai-dewani marked this conversation as resolved.
Show resolved Hide resolved
if len(self.current_word) < self.current_word_limit:
self.current_word += key
self.current_string += key

# Update status of word limit
if len(self.current_word) >= self.current_word_limit:
self.current_word_limit_reached = True

def print_realtime_wpm(self, win):
"""Print realtime wpm during the test.
Expand Down Expand Up @@ -297,7 +308,10 @@ def update_state(self, win):
win.addstr(self.line_count, 0, " " * self.window_width)
win.addstr(self.line_count + 2, 0, " " * self.window_width)
win.addstr(self.line_count + 4, 0, " " * self.window_width)
win.addstr(self.line_count, 0, self.current_word)
if self.current_word_limit_reached:
jai-dewani marked this conversation as resolved.
Show resolved Hide resolved
win.addstr(self.line_count, 0, self.current_word, curses.color_pair(2))
else:
win.addstr(self.line_count, 0, self.current_word)

win.addstr(2, 0, self.text, curses.A_BOLD)
win.addstr(2, 0, self.text[0 : len(self.current_string)], curses.A_DIM)
Expand Down