Article View: comp.lang.lisp
Article #25REPL, streams, SBCL
From: steve g
Date: Mon, 12 Oct 2026 21:32
Date: Mon, 12 Oct 2026 21:32
99 lines
4680 bytes
4680 bytes
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
Technical Details
Message-ID:
<87wlrmeha9.fsf@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.nrbbs.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-2.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.nrbbs.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-2.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 12 Oct 2026 21:32:48 +0000 From: steve g <Sgonedes1977@gmail.com> Newsgroups: comp.lang.lisp Subject: REPL, streams, SBCL Date: Mon, 12 Oct 2026 17:32:46 -0400 Message-ID: <87wlrmeha9.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:bkfQFEzumvVCqd1xfggVPcQJo/M= MIME-Version: 1.0 Content-Type: text/plain Lines: 99 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-kGemIh+z2JcF/xsL6tzM8dCVrddRVpTcjPZO3NxBptIaC4rn3GmSTUGqFjZEuhfPP8sSq9pyFfVEf7W!Rw9pkgO2wc+RropbDP3+Li4SVtefcQw66p3fkXxen7eEwCw= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40