Skip to content

Commit

Permalink
Revamp looks and colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mithil467 committed Nov 6, 2020
1 parent 8194a37 commit a75b582
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 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 @@ -173,6 +175,7 @@ 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)
Expand All @@ -181,7 +184,7 @@ def initialize(self, win):
0,
int(self.window_width) - 14,
" 0.00 ",
curses.color_pair(1),
curses.color_pair(5),
)
win.addstr(" WPM ")

Expand All @@ -195,7 +198,7 @@ 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))
Expand Down Expand Up @@ -287,7 +290,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 +325,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 +376,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 +394,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 +435,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

0 comments on commit a75b582

Please sign in to comment.