How do I write a string to the Slime REPL's input buffer?

63 views Asked by At

I'm writting a shell in Common Lisp that reads command from the user's input and returns the output after executing. When the user types a "meta" command I want to write a placeholder so that the user can either press enter and send that command to the shell, or edit this command as if it were their own input.

This what I have now:

(defun eval-print (command-executor command)
  (format t "~a~%" (funcall command-executor command)))

(defun cmd-exec-local (command)
  "Execute a command in the local shell"
  (trim (uiop:run-program command :output :string)))

(defun shell (command-executor &optional placeholder)
  "Simulate a REPL"
  (progn
    (if placeholder
        (format t ">>> ~a" placeholder) ; This is were I try to show a placeholder
        (format t ">>> "))
    (let ((command (read-line))) ; Check if the user wrote a meta command, else just execute whatever they wrote
      (cond ((string= "@exit" command) (format t "Bye!~%")) ; Exit the shell
            ((string= "@bashrev" command) (shell command-executor *bash-rev*)) ; Bash reverse shell
            ((string= "@info" command) (shell command-executor "whoami")) ; System info
            (t (eval-print command-executor command) (shell command-executor)))))) ; Execute the command

But this is the output I get:

PENTESTING> (shell #'cmd-exec-local)
>>> @info
>>> whoami ; This has been written to the standard output, so even if I press enter, nothing gets executed

>>> whoami ; This was written by the user so when pressing enter, I get the results I need
kali
>>> @exit
Bye!

My guess is I need some kind of buffer that I can write to but I've tried terminal-io and it didn't seem to work.

0

There are 0 answers