scheme shell
about
download
support
resources
docu
links
 
scsh.net

Read Single Char

The following procedure might be useful for writing interactive, menu driven applications with scsh. This function reads a single character from a given terminal and returns immediately. (Calling READ-CHAR or READ usually waits for a return key to end the input.) See the UNIX FAQ (at http://www.faqs.org/faqs/unix-faq/programmer/faq/ ), question 3.2 for a more detailed description of what is done here.

  (define (wait-for-key . optionals)
    (let-optionals optionals
        ((tty-port (current-input-port)))
      (let* ((old (tty-info tty-port))
         (copy (copy-tty-info old)))
        (set-tty-info:local-flags 
         copy
         (bitwise-and (tty-info:local-flags copy)
              (bitwise-not ttyl/canonical)))
        (set-tty-info:min copy 1)
        (set-tty-info:time copy 0)
        (set-tty-info/now tty-port copy)
        (let ((c (read-char tty-port)))
      (set-tty-info/now tty-port old)
      c))))

-Eric


ReadSingleChar - raw wiki source | code snippets archive