Löschen geht noch nicht
This commit is contained in:
parent
88ea38d4e8
commit
e98332455a
@ -3,6 +3,7 @@ from curses import wrapper
|
|||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
import locale
|
import locale
|
||||||
|
import sys
|
||||||
|
|
||||||
# Set the locale to support UTF-8
|
# Set the locale to support UTF-8
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
@ -66,7 +67,7 @@ def start_scr(stdscr):
|
|||||||
elif key == curses.KEY_DOWN and current_row_idx < len(menu) - 1:
|
elif key == curses.KEY_DOWN and current_row_idx < len(menu) - 1:
|
||||||
current_row_idx += 1
|
current_row_idx += 1
|
||||||
elif key == curses.KEY_ENTER or key in [10, 13] and current_row_idx == 0:
|
elif key == curses.KEY_ENTER or key in [10, 13] and current_row_idx == 0:
|
||||||
wpm_test(stdscr)
|
wpm_test(stdscr, filename)
|
||||||
elif key == curses.KEY_ENTER or key in [10, 13] and current_row_idx == 1:
|
elif key == curses.KEY_ENTER or key in [10, 13] and current_row_idx == 1:
|
||||||
quit()
|
quit()
|
||||||
print_menu(stdscr, current_row_idx)
|
print_menu(stdscr, current_row_idx)
|
||||||
@ -86,15 +87,15 @@ def display_text(stdscr, target, current, wpm=0, cpm=0):
|
|||||||
stdscr.addstr(1, i, char, color)
|
stdscr.addstr(1, i, char, color)
|
||||||
|
|
||||||
|
|
||||||
def load_text():
|
def load_text(filename):
|
||||||
with open("text.txt", "r", encoding="utf-8") as f:
|
with open(filename, "r", encoding="utf-8") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
return random.choice(lines).strip()
|
return random.choice(lines).strip()
|
||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
def wpm_test(stdscr):
|
def wpm_test(stdscr, filename):
|
||||||
target_text = load_text()
|
target_text = load_text(filename)
|
||||||
current_text = []
|
current_text = []
|
||||||
wpm = 0
|
wpm = 0
|
||||||
cpm = 0
|
cpm = 0
|
||||||
@ -132,17 +133,23 @@ def wpm_test(stdscr):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass # Ignore KeyboardInterrupt to exit gracefully
|
pass # Ignore KeyboardInterrupt to exit gracefully
|
||||||
|
|
||||||
def main(stdscr):
|
def main(stdscr, filename):
|
||||||
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
||||||
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
|
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
|
||||||
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK)
|
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLACK)
|
||||||
start_scr(stdscr)
|
start_scr(stdscr)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
wpm_test(stdscr)
|
wpm_test(stdscr, filename)
|
||||||
stdscr.addstr(5, 0, "Press [ENTER] key to continue or [ESC] to go back!")
|
stdscr.addstr(6, 0, "Press [ENTER] key to continue or [ESC] to go back!")
|
||||||
key = stdscr.getkey()
|
key = stdscr.getkey()
|
||||||
if ord(key) == 27:
|
if ord(key) == 28:
|
||||||
break
|
break
|
||||||
|
|
||||||
wrapper(main)
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: python tipptrainer.py <filename>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
filename = sys.argv[1]
|
||||||
|
wrapper(main, filename)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user