unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* non-blocking keyboard input inside customized repl
@ 2003-01-29  1:46 Peter Santoro
  2003-01-29 19:00 ` Paul Jarc
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Santoro @ 2003-01-29  1:46 UTC (permalink / raw)


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?

Thanks for your help,


Peter



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: non-blocking keyboard input inside customized repl
  2003-01-29  1:46 non-blocking keyboard input inside customized repl Peter Santoro
@ 2003-01-29 19:00 ` Paul Jarc
  2003-01-29 20:01   ` Peter Santoro
  2003-01-30  2:24   ` Peter Santoro
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Jarc @ 2003-01-29 19:00 UTC (permalink / raw)
  Cc: guile-user

Peter Santoro <peter@pscomp.com> 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


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: non-blocking keyboard input inside customized repl
  2003-01-29 19:00 ` Paul Jarc
@ 2003-01-29 20:01   ` Peter Santoro
  2003-01-30  2:24   ` Peter Santoro
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Santoro @ 2003-01-29 20:01 UTC (permalink / raw)
  Cc: guile-user

Paul Jarc wrote:

>Peter Santoro <peter@pscomp.com> 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
>
>  
>
Paul, you are correct.  I did mean to use "raw terminal" input instead 
of "non-blocking" input.  I actually got this working in mzscheme and 
will endeavor to port over to guile.

Thanks,

Peter



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: non-blocking keyboard input inside customized repl
  2003-01-29 19:00 ` Paul Jarc
  2003-01-29 20:01   ` Peter Santoro
@ 2003-01-30  2:24   ` Peter Santoro
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Santoro @ 2003-01-30  2:24 UTC (permalink / raw)
  Cc: guile-user

Paul Jarc wrote:

>Peter Santoro <peter@pscomp.com> 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 )))




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-01-30  2:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-29  1:46 non-blocking keyboard input inside customized repl Peter Santoro
2003-01-29 19:00 ` Paul Jarc
2003-01-29 20:01   ` Peter Santoro
2003-01-30  2:24   ` Peter Santoro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).