Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.lisp > #61736

REPL, streams, SBCL

From steve g <Sgonedes1977@gmail.com>
Newsgroups comp.lang.lisp
Subject REPL, streams, SBCL
Date 2026-10-12 17:32 -0400
Message-ID <87wlrmeha9.fsf@gmail.com> (permalink)

Show all headers | View raw


I was interested in changing the REPL for SBCL. I cannot figure out
sb-aclrepl.

I have tried closing *standard-output* and *standard-input*; that
doesn't word very well.

I have been doing this:

(defstruct (screen (:copier nil))
    "The main screen for the program."
   (namestring  "Standard Screen" :type string :read-only t)
   ;; io
   (input        (make-instance 'sb-sys:fd-stream ) :type SB-SYS:FD-STREAM)
   (output       (make-instance 'sb-sys:fd-stream ) :type SB-SYS:FD-STREAM)
   (ofd          0 :type sb-posix:file-descriptor)
   (ifd          0 :type sb-posix:file-descriptor)
   ;; [ ... ]
   )



(DEFUN TIDEVICE-OPEN (TTY)
  (LET ((CURDEV (CURRENT-TIDEVICE)))
    (IF (NULL TTY)
        (SETQ TTY "/dev/pts/1"))
    (SETQ TTY (NAMESTRING TTY))
    (LET* ((OFD
            (SB-POSIX:OPEN TTY SB-POSIX:O-WRONLY
                           (LOGIOR SB-POSIX:O-NOCTTY SB-POSIX:O-NONBLOCK SB-POSIX:O-DIRECT SB-POSIX:O-NDELAY)))
           (IFD (SB-POSIX:OPEN TTY SB-POSIX:O-RDONLY SB-POSIX:O-NOCTTY))
           (OUTPUT
            (SB-SYS:MAKE-FD-STREAM OFD :NAME "Device Output" :AUTO-CLOSE T :OUTPUT T :INPUT NIL :BUFFERING :NONE
                                   :ELEMENT-TYPE 'CHARACTER :EXTERNAL-FORMAT :ASCII))
           (INPUT
            (SB-SYS:MAKE-FD-STREAM IFD :NAME "Device Input" :AUTO-CLOSE T :BUFFERING :NONE :OUTPUT NIL :INPUT T
                                   :ELEMENT-TYPE '(UNSIGNED-BYTE 8) :TIMEOUT 127/400))
           (SB-POSIX:TCGETATTR IFD (TIDEVICE-TERMIOS-OLD CURDEV))
           (SB-POSIX:TCGETATTR IFD (TIDEVICE-TERMIOS-NEW CURDEV)))))
    [ ... ]
    )


;; these are fd-streams
(define-symbol-macro *cm-in* (tidevice-stream-input (current-tidevice)))
(define-symbol-macro *cm-out* (tidevice-stream-output (current-tidevice)))

;; These are for the fildes (needed for system io control (ioctl)

(define-symbol-macro *ifd* (tidevice-ifd (current-tidevice)))
(define-symbol-macro *ofd* (tidevice-ofd (current-tidevice)))

(defun read-some ()
  "Reads input bytes from stdin."
  (let ((sap (sb-sys:vector-sap resbuf))
        (nbytes 0)
        (tmr (sb-ext:make-timer #'exit-repl :name "REPL Kill 2")))
    (tidevice-termios-mode :raw)
    (sb-ext:schedule-timer tmr 15)
    (until *exit-repl-p*
           (setq nbytes (sb-posix:read (tidevice-ifd (current-tidevice)) sap 18))
           (input-push resbuf nbytes)
           (cm-save-cursor)
           (display-vector (length (car *q*)) (car *q*))
           (display-xy)
           (cm-restore-cursor)
           (fill resbuf 0))
    (display-prompt)))


(defun start ()
  (tidevice-termios-mode :libkbd)
  (tidevice-termios-mode :NONL)
  (setup-screen)
  (setq sb-int:*repl-prompt-fun* #'display-prompt)
  (setq *standard-output* *cm-out*)
  (setq *standard-input* *cm-in*)
  (display-prompt)
  )



I cannot get the file descriptor for dup with the synonym streams. and
if I close them SBCL is reluctant to take input.

I also noticed that *stdin* was listed in the code. I have been using a
pty in X windows /dev/pts/1, and /dev/tty on the terminal. These are
working so far, but the many of the terminfo sequences go unnoticed,
such as cm-cursor-to-ll or vpa.

The problem is that everytime I call tput the cursor is moved with the
sbcl prompt. The code does work better in raw mode, but that is a lot of
coding left.

Can I replace *standard-input* with fd-streams?

thanks
steve

Back to comp.lang.lisp | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

REPL, streams, SBCL steve g <Sgonedes1977@gmail.com> - 2026-10-12 17:32 -0400
  Re: REPL, streams, SBCL Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-10-12 23:23 +0000

csiph-web