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.
.



Relevant Pages

  • Re: Implementing REPL...
    ... line-buffering terminal with Gray streams. ... and then feed characters from this line one by one. ... name READ-CHAR, thinking that it should behave like getchin C programs... ... In what way do you think READ-CHAR differs from getch() in C programs? ...
    (comp.lang.lisp)
  • Re: A problem with read-char
    ... Is it possible to make read-char behave like getch in ó ... In SBCL read-char wants "enter" key to unhang from REPL, ... C's getcharreads and returns one byte from the stdin file stream. ... the portability of these languages ...
    (comp.lang.lisp)
  • Re: grabbing key presses
    ... |> SBCL certainly provides such a way, but it's not at all surprising ... the program finishes before doing the next thing [your READ-CHAR], ... then SBCL may be saving/restoring the terminal state across sub-process ... SB-POSIX:TCGETATTR (fbound) ...
    (comp.lang.lisp)
  • Re: grabbing key presses
    ... |> SBCL certainly provides such a way, but it's not at all surprising ... the program finishes before doing the next thing [your READ-CHAR], ... program method for twiddling the terminal state, ... then SBCL may be saving/restoring the terminal state across sub-process ...
    (comp.lang.lisp)
  • Re: Reading *standard-input* as a byte stream
    ... nikodemus writes: ... both READ-BYTE and READ-CHAR on them directly. ... My previous sbcl was only 3 days old. ...
    (comp.lang.lisp)