forge: improve repl: use readline, better output formatting; join input lines with newline character

This commit is contained in:
Helmut Merz 2026-02-07 09:18:51 +01:00
parent 3c3e9b15d7
commit a76f59498c
3 changed files with 12 additions and 6 deletions

View file

@ -82,13 +82,19 @@
;;;; code compilation and execution ;;;; code compilation and execution
(defun input-line (&key prompt)
(if (null prompt)
(setf prompt (format nil "~a> " (length (stack *forge-env*)))))
(rl:readline :prompt prompt))
(defun repl () (defun repl ()
(do ((input (read-line) (read-line))) (do ((input (input-line) (input-line)))
((string= input "q") (stack *forge-env*)) ((string= input "q") (stack *forge-env*))
(handler-bind (handler-bind
((end-of-file ((end-of-file
(lambda (c) (lambda (c)
(invoke-restart 'iter:try-with-more-input (read-line))))) (invoke-restart 'iter:try-with-more-input
(input-line :prompt ".. ")))))
(exec-string input)))) (exec-string input))))
(defun exec-list (lst) (defun exec-list (lst)
@ -184,8 +190,8 @@
(f:reg 'swp #'(lambda () (let ((a (f:popd)) (b (f:popd))) (f:pushd a) (f:pushd b)))) (f:reg 'swp #'(lambda () (let ((a (f:popd)) (b (f:popd))) (f:pushd a) (f:pushd b))))
(f:reg 'drop #'f:popd) (f:reg 'drop #'f:popd)
(f:reg '? #'(lambda () (format t "~a~%" (f:popd)))) (f:reg '? #'(lambda () (format t "~s~%" (f:popd))))
(f:reg '?? #'(lambda () (format t "~a~%" (f:stack f:*forge-env*)))) (f:reg '?? #'(lambda () (format t "~{~s ~}~%" (f:stack f:*forge-env*))))
(f:reg1 'ptr #'util:ptr) (f:reg1 'ptr #'util:ptr)
(f:reg1 'get #'aref) (f:reg1 'get #'aref)

View file

@ -6,7 +6,7 @@
:version "0.0.1" :version "0.0.1"
:homepage "https://www.cyberconcepts.org" :homepage "https://www.cyberconcepts.org"
:description "Core packages of the scopes project." :description "Core packages of the scopes project."
:depends-on (:alexandria :cl-dotenv :com.inuoe.jzon :depends-on (:alexandria :cl-dotenv :cl-readline :com.inuoe.jzon
:flexi-streams :ironclad :local-time :log4cl :flexi-streams :ironclad :local-time :log4cl
:lparallel :qbase64 :serapeum :str) :lparallel :qbase64 :serapeum :str)
:components ((:file "config" :depends-on ("util/util")) :components ((:file "config" :depends-on ("util/util"))

View file

@ -75,7 +75,7 @@
nil) nil)
t)) t))
(try-with-more-input (more) (try-with-more-input (more)
(setf (data it) (str:join " " (list (data it) more))) (setf (data it) (str:join #\newline (list (data it) more)))
(next it)))) (next it))))
;;;; stream iterator implementation ;;;; stream iterator implementation