Löschen geht noch nicht

This commit is contained in:
Ratatoskr 2023-12-02 13:45:50 +01:00
parent 88ea38d4e8
commit e98332455a
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

View File

@ -3,6 +3,7 @@ from curses import wrapper
import time
import random
import locale
import sys
# Set the locale to support UTF-8
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:
current_row_idx += 1
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:
quit()
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)
def load_text():
with open("text.txt", "r", encoding="utf-8") as f:
def load_text(filename):
with open(filename, "r", encoding="utf-8") as f:
lines = f.readlines()
return random.choice(lines).strip()
# -*- coding: utf-8 -*-
def wpm_test(stdscr):
target_text = load_text()
def wpm_test(stdscr, filename):
target_text = load_text(filename)
current_text = []
wpm = 0
cpm = 0
@ -132,17 +133,23 @@ def wpm_test(stdscr):
except KeyboardInterrupt:
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(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)
while True:
wpm_test(stdscr)
stdscr.addstr(5, 0, "Press [ENTER] key to continue or [ESC] to go back!")
wpm_test(stdscr, filename)
stdscr.addstr(6, 0, "Press [ENTER] key to continue or [ESC] to go back!")
key = stdscr.getkey()
if ord(key) == 27:
if ord(key) == 28:
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)