mirror of
https://gitlab.com/vindarel/ciel.git
synced 2025-12-06 02:30:39 -08:00
REPL: run visual commands in a terminal window
[ci skip]
This commit is contained in:
parent
a21f6b0f99
commit
db259c7f56
3 changed files with 64 additions and 0 deletions
10
docs/repl.md
10
docs/repl.md
|
|
@ -65,6 +65,16 @@ The result is concatenated into a string and printed on stdout.
|
|||
|
||||
This feature is only available in CIEL's REPL, not on the CIEL-USER package.
|
||||
|
||||
Some programs are **visual** / interactive / ncurses-based, and need
|
||||
to be run in their own terminal window. CIEL recognizes a few (`vim`,
|
||||
`htop`, `man`…) and runs them in the first terminal emulator found on
|
||||
the system of `terminator`, `xterm`, `gnome-terminal`). See the
|
||||
`*visual-commands*` variable.
|
||||
|
||||
> Note: this feature is experimental.
|
||||
|
||||
> Note: we encourage our users to use Emacs rather than a terminal!
|
||||
|
||||
We use the [Clesh](https://github.com/Neronus/clesh) library.
|
||||
|
||||
See also [SHCL](https://github.com/bradleyjensen/shcl) for a more unholy union of posix-shell and Common Lisp.
|
||||
|
|
|
|||
|
|
@ -46,3 +46,50 @@ bar:qux
|
|||
(when (= rl:+end+ rl:*point*)
|
||||
(format t "~c[1C" #\esc))
|
||||
(finish-output)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Run visual / interactive / ncurses commands in their terminal window.
|
||||
;;;
|
||||
;;; How to guess a program is interactive?
|
||||
;;; We currently look from a hand-made list (à la Eshell).
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defparameter *visual-commands*
|
||||
'(;; "emacs -nw" ;; in eshell, concept of visual-subcommands.
|
||||
"vim" "vi"
|
||||
"nano"
|
||||
"htop" "top"
|
||||
"man" "less" "more"
|
||||
"screen" "tmux"
|
||||
"lynx" "links" "mutt" "pine" "tin" "elm" "ncftp" "ncdu"
|
||||
"ranger"
|
||||
;; last but not least
|
||||
"ciel-repl")
|
||||
"List of visual/interactive/ncurses-based programs that will be run in their own terminal window.")
|
||||
|
||||
(defparameter *visual-terminal-emulator-choices*
|
||||
'("terminator" "x-terminal-emulator" "xterm" "gnome-terminal"))
|
||||
|
||||
(defparameter *visual-terminal-switches* '("-e")
|
||||
"Default options to the terminal. `-e' aka `--command'.")
|
||||
|
||||
(defun find-terminal ()
|
||||
"Return the first terminal emulator found on the system from the `*visual-terminal-emulator-choices*' list."
|
||||
(loop for program in *visual-terminal-emulator-choices*
|
||||
when (which:which program)
|
||||
return program))
|
||||
|
||||
(defun visual-command-p (text)
|
||||
"The command TEXT starts by a known visual command, listed in `*visual-commands*'."
|
||||
(let* ((cmd (string-left-trim "!" text)) ;; strip clesh syntax.
|
||||
(first-word (first (str:words cmd))))
|
||||
;; This will be smarter. https://github.com/ruricolist/cmd/issues/10
|
||||
(find first-word *visual-commands* :test #'equalp)))
|
||||
|
||||
(defun run-visual-command (text)
|
||||
"Run this text command into another terminal window."
|
||||
(let ((cmd (string-left-trim "!" text)))
|
||||
(uiop:launch-program `( ,(find-terminal)
|
||||
;; quick way to flatten the list of switches:
|
||||
,@*visual-terminal-switches*
|
||||
,cmd))))
|
||||
|
|
|
|||
|
|
@ -458,8 +458,15 @@ strings to match candidates against (for example in the form \"package:sym\")."
|
|||
(sbcli::sbcli "" *prompt*))
|
||||
(when *hist-file* (sbcli::update-hist-file text))
|
||||
(cond
|
||||
;; Handle documentation lookup.
|
||||
((str:ends-with-p " ?" text)
|
||||
(sbcli::symbol-documentation (last-nested-expr text)))
|
||||
|
||||
;; Handle visual commands: run in their own terminal window.
|
||||
((visual-command-p text)
|
||||
(run-visual-command text))
|
||||
|
||||
;; Default: run the lisp command (with the lisp-critic and other add-ons).
|
||||
(t
|
||||
(sbcli::handle-input txt text)))
|
||||
(finish-output nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue