kopia lustrzana https://github.com/micropython/micropython-lib
ucurses: Allow typical pattern for KEY_ESC detection.
This pattern makes use of nodelay curses mode, implement that.pull/26/head
rodzic
7cb60c33b8
commit
d086d00b51
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tty, termios
|
import tty, termios
|
||||||
|
import select
|
||||||
|
|
||||||
COLOR_BLACK = 0
|
COLOR_BLACK = 0
|
||||||
COLOR_RED = 1
|
COLOR_RED = 1
|
||||||
|
@ -54,7 +55,7 @@ KEY_QUIT = 1009
|
||||||
KEY_ENTER = 1010
|
KEY_ENTER = 1010
|
||||||
KEY_BACKSPACE = 1011
|
KEY_BACKSPACE = 1011
|
||||||
KEY_DELETE = 1012
|
KEY_DELETE = 1012
|
||||||
KEY_ESC = 1020
|
KEY_ESC = 0x1b
|
||||||
|
|
||||||
KEY_DC = KEY_DELETE
|
KEY_DC = KEY_DELETE
|
||||||
KEY_PPAGE = KEY_PGUP
|
KEY_PPAGE = KEY_PGUP
|
||||||
|
@ -140,6 +141,7 @@ class Window:
|
||||||
self.bkgattr = A_NORMAL
|
self.bkgattr = A_NORMAL
|
||||||
self.keybuf = None
|
self.keybuf = None
|
||||||
self.keyi = 0
|
self.keyi = 0
|
||||||
|
self.keydelay = -1
|
||||||
|
|
||||||
def _goto(self, row, col):
|
def _goto(self, row, col):
|
||||||
_move(self.y + row, self.x + col)
|
_move(self.y + row, self.x + col)
|
||||||
|
@ -210,7 +212,13 @@ class Window:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def timeout(self, delay):
|
def timeout(self, delay):
|
||||||
assert delay < 0
|
self.keydelay = delay
|
||||||
|
|
||||||
|
def nodelay(self, yes):
|
||||||
|
if yes:
|
||||||
|
self.keydelay = 0
|
||||||
|
else:
|
||||||
|
self.keydelay = -1
|
||||||
|
|
||||||
def getch(self):
|
def getch(self):
|
||||||
if self.keybuf and self.keyi < len(self.keybuf):
|
if self.keybuf and self.keyi < len(self.keybuf):
|
||||||
|
@ -218,6 +226,19 @@ class Window:
|
||||||
self.keyi += 1
|
self.keyi += 1
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
if self.keydelay >= 0:
|
||||||
|
USE_EPOLL = 1
|
||||||
|
if USE_EPOLL:
|
||||||
|
poll = select.epoll()
|
||||||
|
poll.register(0, select.EPOLLIN)
|
||||||
|
res = poll.poll(self.keydelay / 1000)
|
||||||
|
poll.unregister(0)
|
||||||
|
poll.close()
|
||||||
|
else:
|
||||||
|
res = select.select([0], [], [], self.keydelay / 1000)[0]
|
||||||
|
if not res:
|
||||||
|
return -1
|
||||||
|
|
||||||
key = os.read(0, 32)
|
key = os.read(0, 32)
|
||||||
if key[0] != 0x1b:
|
if key[0] != 0x1b:
|
||||||
self.keybuf = key
|
self.keybuf = key
|
||||||
|
|
Ładowanie…
Reference in New Issue