Keyboard input/Obtain a Y or N response: Difference between revisions
Keyboard input/Obtain a Y or N response (view source)
Revision as of 22:44, 20 June 2017
, 6 years ago→{{header|TXR}}: Add tcsaflush call to meet requirement; discuss go-raw and show how it's implemented.
(→{{header|TXR}}: Loop until Y, y, N or n obtained.) |
(→{{header|TXR}}: Add tcsaflush call to meet requirement; discuss go-raw and show how it's implemented.) |
||
Line 1,384:
This works not only on Unix-like platforms, but also on Microsoft Windows, because TXR is ported to Windows using a [https://www.kylheku.com/cygnal/index.html modified version of Cygwin].
<lang txrlisp>(with-resources ((tio-orig (tcgetattr) (tcsetattr tio-orig)))
(let ((tio (copy tio-orig)))
tio.(go-raw)
(tcsetattr tio tcsaflush) ;; third arg optional, defaults to
(whilet ((k (get-char))
((not (member k '(#\y #\n #\Y #\N))))))))
The <code>go-raw</code> method on the <code>termios</code> structure only manipulates the structure contents; <code>tcsetattr</code> pushes it down to the TTY driver.
<code>go-raw</code> is defined in the TXR standard library like this:
<lang txrlisp>(defmeth termios go-raw (tio)
tio.(clear-iflags ignbrk brkint parmrk istrip inlcr igncr icrnl ixon)
tio.(clear-oflags opost)
tio.(clear-cflags csize parenb)
tio.(clear-lflags echo echonl icanon isig)
(if (boundp 'iexten)
tio.(clear-lflags iexten))
tio.(set-cflags cs8)
(set tio.[cc vmin] 1)
(set tio.[cc vtime] 0))</lang>
=={{header|UNIX Shell}}==
|