Re: A problem with read-char



meta.person@xxxxxxxxx writes:

Hi.

Is it possible to make read-char behave like getch in С when working
with interactive stream (*standard-input*)?
In SBCL read-char wants "enter" key to unhang from REPL, in C getchar
returns immediately after user press key on keyboard.
Probably is possible to run code that uses read-char with direct
console access, aside REPL?

No. It is not possible.

That is, it's not possible with COMMON-LISP:READ-CHAR and neither with
COMMON-LISP:READ-CHAR-NO-HANG.

By the way, you are totally wrong about the standard C library getchar
functions. It behaves exactly like COMMON-LISP:READ-CHAR.

About the curses routine getch, the situation is different.


And what is this difference would you guess? Here lies the answer to
your question.

The difference is that curses puts the terminal in raw mode to be able
to receive the characters from the keyboard one at a time, instead of
leaving the terminal in cooked mode, where the unix driver bufferize
lines and handles backspace, amongst other niceties.

Now, I don't know about SBCL, (check the manual of SBCL). I only have
the Implementation Notes of CLISP loaded in my wetware. In CLISP you
can use the EXT:WITH-KEYBOARD macro (while the basic output features
of curses are provided by the SCREEN package).

--
__Pascal Bourguignon__ http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
.