def initialize(self, win): """Configure the initial state of the curses interface. Args: win (any): Curses window. """ # Find window dimensions self.window_height, self.window_width = self.get_dimensions(win) # Adding word wrap to text self.text = word_wrap(self.text, self.window_width) self.screen_size_check(self.window_height, self.window_width, self.text) curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLUE) 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) self.print_realtime_wpm(win) self.setup_print(win)
def resize(self, win): """Respond to window resize events. Args: win (any): Curses window. """ win.clear() self.window_height, self.window_width = self.get_dimensions(win) self.text = word_wrap(self.original_text_formatted, self.window_width) self.line_count = (number_of_lines_to_fit_text_in_window( self.text, self.window_width) + 2 + 1) self.setup_print(win) self.update_state(win)
def resize(self, win): """Respond to window resize events. Args: win (any): Curses window. """ win.clear() self.window_height, self.window_width = self.get_dimensions(win) self.text = word_wrap(self.original_text_formatted, self.window_width) self.screen_size_check(self.window_height, self.window_width, self.text) self.print_realtime_wpm(win) self.setup_print(win) self.update_state(win)
def initialize(self, win): """Configure the initial state of the curses interface. Args: win (any): Curses window. """ # Find window dimensions self.window_height, self.window_width = self.get_dimensions(win) # Adding word wrap to text self.text = word_wrap(self.text, self.window_width) # Find number of lines required to print text self.line_count = ( number_of_lines_to_fit_text_in_window(self.text, self.window_width) + 2 # Top 2 lines + 1 # One empty line after text ) # If required number of lines are more than the window height, exit # +3 for printing stats at the end of the test if self.line_count + 3 > self.window_height: curses.endwin() sys.stdout.write("Window too small to print given text") sys.exit(1) curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLUE) 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) win.nodelay(True) win.timeout(100) win.addstr( 0, int(self.window_width) - 14, " 0.00 ", curses.color_pair(1), ) win.addstr(" WPM ") self.setup_print(win)