changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/cli/repl.lisp

changeset 404: 66059a1117bd
parent: 386d51cf61ca
author: Richard Westhaver <ellis@rwest.io>
date: Mon, 03 Jun 2024 22:08:03 -0400
permissions: -rw-r--r--
description: begin clap refactor, upgrade cli/prompt
1 ;;; lib/cli/repl.lisp --- REPL utils
2 
3 ;;; Code:
4 (in-package :cli/repl)
5 
6 ;; *command-char* alias make-repl-fun
7 
8 ;;; Allegro-style REPL
9 ;; this should be used as a light layer on top of the standard Lisp
10 ;; REPL provided by SBCL. Basically whenever we're typing input
11 ;; destined for a Lisp reader this is our best bet.
12 (defun load-acl-repl ()
13  "Load the SB-ACLREPL package, applying changes to the default SBCL
14 REPL."
15  (require 'sb-aclrepl))
16 
17 ;;; Readline-style REPL
18 ;; this is suited for non-Lisp input which should skip the Lisp
19 ;; reader. Input is interpreted as strings and handled by the GNU
20 ;; Readline library via FFI. Features include History, Custom
21 ;; Functions, and Custom Keybinds (not available in ACLREPL above).
22 (defun input-novelty-check (x y)
23  (string/= (trim x)
24  (trim y)))
25 
26 #+readline
27 (defun start-rl-repl ()
28  "Start a GNU Readline REPL."
29  (do ((i 0 (1+ i))
30  (input ""))
31  ((string= "quit" (trim input)))
32  (setf input (readline :prompt (format nil "[~a]> " i)
33  :add-history t
34  :novelty-check #'input-novelty-check))))