summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-10-29 00:11:10 -0700
committerOri Bernstein <ori@eigenstate.org>2017-10-29 00:11:10 -0700
commit895d5fefeacadcdd658f589eaa5530304cd9145e (patch)
treeb39c2e87b9861413e0d418ef6f774686d0a09004
parent3e004af4a5622781f469d228a2bd4eee2ed17071 (diff)
downloadlibtermdraw-895d5fefeacadcdd658f589eaa5530304cd9145e.tar.gz
Improve the implementation of poll()terminfo
-rw-r--r--event.myr17
1 files changed, 9 insertions, 8 deletions
diff --git a/event.myr b/event.myr
index a08d79f..8599ad4 100644
--- a/event.myr
+++ b/event.myr
@@ -53,17 +53,18 @@ const event = {t
const poll = {t
var c = winchanges
- if c > winreported
- winreported = c
- checksize(t)
- -> `std.Some `Winsz (t.x, t.y)
- ;;
-
- if t.nextb == 0
+ if c > winreported || t.nextb != 0 || hasinput(t)
+ -> `std.Some event(t)
+ else
-> `std.None
;;
+}
- -> readkey(t)
+const hasinput = {t
+ var pfd = [
+ [.fd=(t.fd : sys.fd), .events=sys.Pollin]
+ ]
+ -> sys.poll(pfd[:], 0) > 0 && (pfd[0].revents & sys.Pollin != 0)
}
const checksize = {t