Skip to content

Commit

Permalink
Fix delayed exit in replay mode
Browse files Browse the repository at this point in the history
The app would sleep for the time between 2 consecutive key presses.
This would stop input for ESC key during the replay for that
period of time. Fix #10
  • Loading branch information
Mithil467 committed Jun 30, 2020
1 parent 1d80340 commit 0f05aaf
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions mitype/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mitype.commandline
import mitype.keycheck

from datetime import datetime, timedelta

class App:

Expand Down Expand Up @@ -275,24 +276,20 @@ def replay(self, win):
self.setup_print(win)

for j in self.key_strokes:

time.sleep(j[0])

self.key_printer(win, j[1])

timer = time.time()
key = ""

try:
if sys.version_info[0] < 3:
key = win.getkey()
else:
key = win.get_wch()
except curses.error:
pass

if mitype.keycheck.is_escape(key):
sys.exit(0)

while time.time() - timer < j[0]:
try:
if sys.version_info[0] < 3:
key = win.getkey()
else:
key = win.get_wch()
except curses.error:
pass
if mitype.keycheck.is_escape(key):
sys.exit(0)

self.key_printer(win, j[1])
win.refresh()

def word_wrap(self, text, width):
Expand Down

0 comments on commit 0f05aaf

Please sign in to comment.