From a76f59498caa11ad696f3b5edf4b539e63f41581 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 7 Feb 2026 09:18:51 +0100 Subject: [PATCH] forge: improve repl: use readline, better output formatting; join input lines with newline character --- forge/forge.lisp | 14 ++++++++++---- scopes-core.asd | 2 +- util/iter.lisp | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/forge/forge.lisp b/forge/forge.lisp index 0d49906..b8f1df7 100644 --- a/forge/forge.lisp +++ b/forge/forge.lisp @@ -82,13 +82,19 @@ ;;;; 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 () - (do ((input (read-line) (read-line))) + (do ((input (input-line) (input-line))) ((string= input "q") (stack *forge-env*)) (handler-bind ((end-of-file (lambda (c) - (invoke-restart 'iter:try-with-more-input (read-line))))) + (invoke-restart 'iter:try-with-more-input + (input-line :prompt ".. "))))) (exec-string input)))) (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 'drop #'f:popd) -(f:reg '? #'(lambda () (format t "~a~%" (f:popd)))) -(f:reg '?? #'(lambda () (format t "~a~%" (f:stack f:*forge-env*)))) +(f:reg '? #'(lambda () (format t "~s~%" (f:popd)))) +(f:reg '?? #'(lambda () (format t "~{~s ~}~%" (f:stack f:*forge-env*)))) (f:reg1 'ptr #'util:ptr) (f:reg1 'get #'aref) diff --git a/scopes-core.asd b/scopes-core.asd index b15ba68..8927d42 100644 --- a/scopes-core.asd +++ b/scopes-core.asd @@ -6,7 +6,7 @@ :version "0.0.1" :homepage "https://www.cyberconcepts.org" :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 :lparallel :qbase64 :serapeum :str) :components ((:file "config" :depends-on ("util/util")) diff --git a/util/iter.lisp b/util/iter.lisp index 324f98b..72a812f 100644 --- a/util/iter.lisp +++ b/util/iter.lisp @@ -75,7 +75,7 @@ nil) t)) (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)))) ;;;; stream iterator implementation