dagascii: don't use unreleased wait_for_input method

Fixes #1359

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-11-23 04:38:26 +02:00
parent 77555e94ce
commit 532c9df053
4 changed files with 43 additions and 7 deletions
+6 -5
View File
@@ -7,7 +7,7 @@ from grandalf.routing import route_with_lines, EdgeViewer
class AsciiCanvas(object):
TIMEOUT = 1
TIMEOUT = 10
def __init__(self, cols, lines):
assert cols > 1
@@ -27,6 +27,7 @@ class AsciiCanvas(object):
print(''.join(line))
def _do_draw(self, screen): # pragma: no cover
from dvc.system import System
from asciimatics.event import KeyboardEvent
offset_x = 0
@@ -66,12 +67,12 @@ class AsciiCanvas(object):
# NOTE: get_event() doesn't block by itself,
# so we have to do the blocking ourselves.
#
# NOTE: using formally private method while waiting for PR [1]
# to get merged. After that need to adjust asciimatics version
# requirements.
# NOTE: using this workaround while waiting for PR [1]
# to get merged and released. After that need to adjust
# asciimatics version requirements.
#
# [1] https://github.com/peterbrittain/asciimatics/pull/188
screen._wait_for_input(self.TIMEOUT)
System.wait_for_input(self.TIMEOUT)
event = screen.get_event()
if not isinstance(event, KeyboardEvent):
+35
View File
@@ -205,3 +205,38 @@ class System(object):
assert inode >= 0
assert inode < 2**64
return inode
@staticmethod
def _wait_for_input_windows(timeout):
import sys
import ctypes
import msvcrt
from ctypes.wintypes import DWORD, HANDLE
# https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 0x00000102
func = ctypes.windll.kernel32.WaitForSingleObject
func.argtypes = [HANDLE, DWORD]
func.restype = DWORD
rc = func(msvcrt.get_osfhandle(sys.stdin.fileno()), timeout * 1000)
if rc not in [WAIT_OBJECT_0, WAIT_TIMEOUT]:
raise RuntimeError(rc)
@staticmethod
def _wait_for_input_posix(timeout):
import sys
import select
try:
select.select([sys.stdin], [], [], timeout)
except select.error:
pass
@staticmethod
def wait_for_input(timeout):
if System.is_unix():
return System._wait_for_input_posix(timeout)
else:
return System._wait_for_input_windows(timeout)
+1 -1
View File
@@ -22,5 +22,5 @@ wheel>=0.31.1
futures>=3.2.0; python_version == "2.7"
grandalf==0.6
pydot>=1.2.4
asciimatics==1.10.0
asciimatics>=1.10.0
distro>=1.3.0
+1 -1
View File
@@ -22,7 +22,7 @@ install_requires = [
"jsonpath-rw==1.4.0",
"requests>=2.18.4",
"grandalf==0.6",
"asciimatics==1.10.0",
"asciimatics>=1.10.0",
"distro>=1.3.0",
]