Keyboard input/Obtain a Y or N response: Difference between revisions

(→‎{{header|UNIX Shell}}: Add shell version)
Line 542:
break</lang>
=={{header|Racket}}==
<lang Racket>
#lang racket
 
;; GUI version
(require racket/gui)
(message-box "Yes/No example" "Yes or no?" #f '(yes-no))
 
;; Text version, via stty
(define stty
(let ([exe (find-executable-path "stty")])
( args (void (apply system* exe args)))))
(define tty-settings (string-trim (with-output-to-string ( () (stty "-g")))))
(printf "Yes or no? ") (flush-output)
(stty "-icanon" "-echo" "min" "1")
(let loop () (when (char-ready?) (loop)))
(let loop ()
(define ch (read-char))
(case (char-downcase ch)
[(#\y #\Y #\n #\N) (displayln ch) (if (memq ch '(#\y #\Y)) 'yes 'no)]
[else (loop)]))
(stty tty-settings)
</lang>
 
=={{header|Retro}}==
<lang Retro>