|
From: | Peter Santoro |
Subject: | Re: non-blocking keyboard input inside customized repl |
Date: | Wed, 29 Jan 2003 21:24:48 -0500 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3a) Gecko/20021212 |
Paul Jarc wrote:
Peter Santoro <address@hidden> wrote:I would like to be able use non-blocking keyboard input in my customized REPL user interface. Is there a non-blocking read-char available in guile, so that the ENTER key doesn't always have to be pressed?It sounds like what you want is raw terminal input. Non-blocking input is different: it means that (read-char) will return immediately (possibly throwing an exception) even if there is nothing to read yet. For raw terminal input, you'd need tcsetattr, which doesn't seem to be directly available in Guile. But maybe you can use the readline module to do what you want. paul
Thanks for the suggestions. I tried the following in guile 1.6.1 and it works ok. As I'm not a scheme guru, any suggestions for improvement are welcomed. Peter (define (term:reset settings) (system (string-append "stty " settings))) (define (term:get-tty-settings) (shell-command-to-string "stty -g")) (define (term:set-raw) (system "stty -icanon -echo min 1 time 0")) (define (read-char-immediate) (if (not (isatty? (current-output-port))) (error "Not running with a tty.")) (let ((tty-settings (term:get-tty-settings))) (term:set-raw) (let ((ch (read-char))) (term:reset tty-settings) ch ))) (define (with-immediate-read-char thunk) (if (not (isatty? (current-output-port))) (error "Not running with a tty.")) (let ((tty-settings (term:get-tty-settings))) (term:set-raw) (let ((res (thunk))) (term:reset tty-settings) res )))
[Prev in Thread] | Current Thread | [Next in Thread] |