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

Revamp looks and colors #68

Merged
merged 2 commits into from
Nov 6, 2020
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
Binary file modified docs/source/_static/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 30 additions & 26 deletions mitype/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
is_tab,
is_valid_initial_key,
)
from mitype.timer import get_elapsed_minutes_since_first_keypress


class App:
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self):

self.current_speed_wpm = 0
self.accuracy = 0
self.time_taken = 0

self.total_chars_typed = 0
self.text_without_spaces = self.original_text_formatted.replace(" ", "")
Expand Down Expand Up @@ -105,9 +107,9 @@ def main(self, win):
# Again mode
elif self.mode == 1 and is_tab(key):
win.clear()
self.reset_test()
self.setup_print(win)
self.update_state(win)
self.reset_test()

# Replay mode
elif self.mode == 1 and is_enter(key):
Expand Down Expand Up @@ -173,17 +175,12 @@ def initialize(self, win):
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_YELLOW)
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_CYAN)
curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_WHITE)

win.nodelay(True)
win.timeout(100)

win.addstr(
0,
int(self.window_width) - 14,
" 0.00 ",
curses.color_pair(1),
)
win.addstr(" WPM ")
self.print_realtime_wpm(win)

self.setup_print(win)

Expand All @@ -195,14 +192,16 @@ def setup_print(self, win):
"""
# Top strip
# Display text ID
win.addstr(0, 0, " ID:{} ".format(self.text_id), curses.color_pair(3))
win.addstr(0, 0, " ID:{} ".format(self.text_id), curses.color_pair(5))

# Display Title
win.addstr(0, int(self.window_width / 2) - 4, " MITYPE ", curses.color_pair(3))

# Print text in BOLD from 3rd line
win.addstr(2, 0, self.text, curses.A_BOLD)

self.print_realtime_wpm(win)

# Set cursor position to beginning of text
win.move(2, 0)

Expand Down Expand Up @@ -287,7 +286,7 @@ def print_realtime_wpm(self, win):
0,
int(self.window_width) - 14,
" " + "{0:.2f}".format(current_wpm) + " ",
curses.color_pair(1),
curses.color_pair(5),
)
win.addstr(" WPM ")

Expand Down Expand Up @@ -322,21 +321,22 @@ def update_state(self, win):
win.addstr(self.line_count, 0, " Your typing speed is ")
if self.mode == 0:
self.current_speed_wpm = speed_in_wpm(self.tokens, self.start_time)
wrongly_typed_chars = self.total_chars_typed - len(
self.text_without_spaces
)
self.accuracy = accuracy(self.total_chars_typed, wrongly_typed_chars)
self.time_taken = get_elapsed_minutes_since_first_keypress(
self.start_time
)

win.addstr(" " + self.current_speed_wpm + " ", curses.color_pair(1))
win.addstr(" " + self.current_speed_wpm + " ", curses.color_pair(6))
win.addstr(" WPM ")

wrongly_typed_chars = self.total_chars_typed - len(self.text_without_spaces)
if self.mode == 0:
self.accuracy = accuracy(self.total_chars_typed, wrongly_typed_chars)
win.addstr(self.window_height - 1, 0, " " * (self.window_width - 1))

win.addstr(self.line_count + 2, 2, " Enter ", curses.color_pair(6))

win.addstr(" to see replay ")

win.addstr(self.line_count + 3, 2, " TAB ", curses.color_pair(5))

win.addstr(self.line_count + 2, 1, " Enter ", curses.color_pair(7))
win.addstr(" to see replay, ")
win.addstr(" Tab ", curses.color_pair(7))
win.addstr(" to retry ")

self.print_stats(win)
Expand Down Expand Up @@ -372,6 +372,7 @@ def reset_test(self):
self.current_speed_wpm = 0
self.total_chars_typed = 0
self.accuracy = 0
self.time_taken = 0
curses.curs_set(1)

def replay(self, win):
Expand All @@ -389,7 +390,7 @@ def replay(self, win):
0,
int(self.window_width) - 14,
" " + str(self.current_speed_wpm) + " ",
curses.color_pair(1),
curses.color_pair(5),
)
win.addstr(" WPM ")

Expand Down Expand Up @@ -430,15 +431,18 @@ def print_stats(self, win):
win.addstr(
self.window_height - 1,
0,
" WPM:" + self.current_speed_wpm + " ",
" WPM: " + self.current_speed_wpm + " ",
curses.color_pair(6),
)

win.addstr(
" Time: " + "{:.2f}".format(self.time_taken) + "s ",
curses.color_pair(1),
)

win.addstr(
self.window_height - 1,
12,
" ACCURACY:" + "{:.2f}".format(self.accuracy) + "% ",
curses.color_pair(6),
" Accuracy: " + "{:.2f}".format(self.accuracy) + "% ",
curses.color_pair(5),
)

@staticmethod
Expand Down