-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77b7aeb
commit d0ae13a
Showing
6 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Project exclude paths | ||
*.pyc | ||
**/__pycache__/ | ||
__pycache__/ | ||
.idea/ | ||
.vscode/ | ||
typertype/src/__pycache__ | ||
typertype/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"WORDS_PER_SET": 20, | ||
"CORRECTIONS": "None", | ||
"TEST_TIMER": 60, | ||
"SPACE_STOP": true, | ||
"WORD_MODIFICATION": "Normal" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from .words_mode import Typer_words | ||
from .time_mode import Typer_time | ||
from .quotes_mode import Typer_quotes | ||
|
||
|
||
class Typer(Typer_words,Typer_time): | ||
class Typer(Typer_words,Typer_time, Typer_quotes): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import requests | ||
import random | ||
import curses | ||
import time | ||
from . import main | ||
|
||
quotes = requests.get('https://type.fit/api/quotes').json() | ||
|
||
def get_quote(): | ||
return quotes[random.randint(0, 1600)]['text'] | ||
|
||
class Typer_quotes(main.Typer_base): | ||
def quotes_set(self,stdscr): | ||
started = False | ||
l, r = 0, self.WIN_X-self.X-1 | ||
accuracy = {"correct": 0, "incorrect": 0, "extra": 0} | ||
stdscr.clear() | ||
raw_set = get_quote().split() | ||
chr_set = list(" ".join(raw_set)) | ||
cur_set = [[chr, curses.color_pair(1)] for chr in chr_set] | ||
self.draw(stdscr, self.Y, self.X, cur_set[l:r+1]) | ||
i = 0 | ||
while i < len(cur_set): | ||
cur_key = stdscr.getch() | ||
if not started: | ||
started = True | ||
t0 = time.time() | ||
if cur_key == ord(chr_set[i]): | ||
if self.CORRECTIONS == "Stop": | ||
if cur_set[i][1] == curses.color_pair(2) | curses.A_BLINK: | ||
cur_set[i][1] = curses.color_pair(2) | ||
else: | ||
cur_set[i][1] = curses.color_pair(3) | ||
else: | ||
cur_set[i][1] = curses.color_pair(3) | ||
|
||
if i < len(cur_set)-1: | ||
cur_set[i+1][1] = curses.color_pair(1) | curses.A_BLINK | ||
|
||
i += 1 | ||
if i >= self.WIN_X//2: | ||
l += 1 | ||
r += 1 | ||
accuracy["correct"] += 1 | ||
elif cur_key == 27 or cur_key == curses.KEY_COPY or cur_key == curses.KEY_END or cur_key == curses.KEY_BREAK: | ||
return | ||
# backspace: | ||
elif cur_key == 8 or cur_key == curses.KEY_BACKSPACE: | ||
if cur_set[i-1][1] == curses.color_pair(2) and self.CORRECTIONS == "Backspace": | ||
cur_set[i][1] = curses.color_pair(1) | ||
cur_set[i-1][1] = curses.color_pair(2) | curses.A_BLINK | ||
i -= 1 | ||
if i >= self.WIN_X//2: | ||
l -= 1 | ||
r -= 1 | ||
elif not(self.SPACE_STOP and cur_key == ord(" ")): | ||
cur_set[i][1] = curses.color_pair(2) | ||
if self.CORRECTIONS == "Stop": | ||
cur_set[i][1] = curses.color_pair(2) | curses.A_BLINK | ||
if i < len(cur_set)-1 and self.CORRECTIONS != "Stop": | ||
cur_set[i+1][1] = curses.color_pair(1) | curses.A_BLINK | ||
if chr_set[i] == " ": | ||
accuracy["extra"] += 1 | ||
else: | ||
accuracy["incorrect"] += 1 | ||
if self.CORRECTIONS == "None" or self.CORRECTIONS == "Backspace": | ||
i += 1 | ||
if i >= self.WIN_X//2: | ||
l += 1 | ||
r += 1 | ||
self.draw(stdscr, self.Y, self.X, cur_set[l:r+1]) | ||
t1 = time.time() | ||
my_time = t1-t0 | ||
cpm = accuracy["correct"]*(60/my_time) | ||
wpm = self.WORDS_PER_SET*(60/my_time) | ||
if self.score(stdscr, wpm, cpm, accuracy): | ||
self.practice_set(stdscr) | ||
else: | ||
return |