changelog shortlog graph tags branches changeset files revisions annotate raw help

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

changeset 381: 386d51cf61ca
parent: 49357f8b5e65
child: 66059a1117bd
author: Richard Westhaver <ellis@rwest.io>
date: Tue, 28 May 2024 23:12:31 -0400
permissions: -rw-r--r--
description: add ffi/readline, net updates
1 ;;; cli.lisp --- cli programming api and utils
2 
3 ;; This package contains a simple api and macros for building lisp CLI
4 ;; programs.
5 
6 ;;; Commentary:
7 
8 ;; - inspired by: clingon, uiop
9 
10 ;; Basic assumptions at runtime:
11 ;; - running in a POSIX-compliant shell
12 ;; - output stream supports UTF-8
13 
14 ;; TODO 2023-10-14: install-ast, install-thunk, proc-args, etc should
15 ;; return IR types - CLI-IR THUNK and CLI-IR respectively.
16 
17 ;; TODO 2023-10-14: rename cli-ast to cli-ir, install-ast to
18 ;; install-ir, etc.
19 
20 ;;; Code:
21 (defpackage :cli/shell
22  (:use :cl :std)
23  (:nicknames :shell)
24  (:export :*shell* :*shell-directory* :*shell-input*))
25 
26 (defpackage :cli/ansi
27  (:use :cl :std)
28  (:nicknames :ansi)
29  (:export
30  ;; ESC sequences
31  :.ris :reset-to-initial-state
32  ;; CSI sequences
33  ;; Cursor control
34  :.cuu :cursor-up
35  :.cud :cursor-down
36  :.cuf :cursor-forward
37  :.cub :cursor-backward
38  :.cnl :cursor-next-line
39  :.cpl :cursor-preceding-line
40  :.cha :cursor-horizontal-absolute
41  :.cup :cursor-position
42  :.vpa :vertical-position-absolute
43  :.vpr :vertical-position-relative
44  :.vpb :vertical-position-backward
45  :.scosc :save-cursor-position
46  :.scorc :restore-cursor-position
47  :.ed :erase-in-display :erase-below :erase-above :erase :erase-saved-lines
48  :.el :erase-in-line :erase-right :erase-left :erase-line
49  :.sgr :select-graphic-rendition
50  :.dsr :device-status-report
51  ;; DEC private mode set and reset
52  :.decset :dec-private-mode-set
53  :.decrst :dec-private-mode-reset
54  :show-cursor :hide-cursor
55  :use-alternate-screen-buffer :use-normal-screen-buffer
56  ;; common
57  :clear
58  :home
59  ;; stty
60  :set-tty-mode))
61 
62 (defpackage :cli/prompt
63  (:use :cl :std)
64  (:export
65  :completing-read
66  :defprompt))
67 
68 (defpackage :cli/progress
69  (:use :cl :std)
70  (:export
71  :update-progress
72  :with-progress-bar
73  :*progress-bar*
74  :*progress-bar-enabled*
75  :start-progress-display
76  :finish-progress-display
77  :progress-mutex
78  :uncertain-size-progress-bar
79  :progress-bar))
80 
81 (defpackage :cli/spark
82  (:use :cl :std)
83  (:export
84  :spark :*ticks*
85  :vspark :*vticks*))
86 
87 (defpackage :cli/repl
88  (:use :cl :std :cli/progress :cli/spark)
89  (:export :load-acl-repl :start-rl-repl))
90 
91 (defpackage :cli/ed
92  (:use :cl :std)
93  (:export :run-emacs :run-emacsclient
94  :org-store-link))
95 
96 (defpackage :cli/clap
97  (:nicknames :clap)
98  (:use :cl :std :log :sb-ext)
99  (:import-from :cli/ansi :.ris)
100  (:import-from :uiop :println)
101  (:import-from :sb-ext :parse-native-namestring)
102  (:shadowing-import-from :sb-ext :exit)
103  (:export
104  :*argv*
105  :*no-exit*
106  :init-args
107  :cli-arg0
108  :cli-args
109  :command-line-args
110  :*cli-group-separator*
111  :*cli-opt-kinds*
112  :cli-opt-kind-p
113  :global-opt-p
114  :*std-local-env-var-names*
115  :*std-global-env-var-names*
116  :exec-path-list
117  :program-list
118  :find-exe
119  :ld-library-path-list
120  :argp
121  :$val
122  :$args
123  :$argc
124  :$opts
125  :$optc
126  :make-shorty
127  :with-cli-handlers
128  :defmain
129  :with-cli
130  :make-cli
131  ;; opt-parsers
132  :make-opt-parser
133  :parse-bool-opt
134  :parse-str-opt
135  :parse-form-opt
136  :parse-list-opt
137  :parse-sym-opt
138  :parse-key-opt
139  :parse-num-opt
140  :parse-file-opt
141  :parse-dir-opt
142  :make-opts
143  :make-cmds
144  :active-opts
145  :active-cmds
146  :proc-args
147  :make-cli-node
148  :make-cli-ast
149  :proc-args
150  :parse-args
151  :debug-opts
152  :do-cmd
153  :do-opt
154  :call-opt
155  :call-cmd
156  :apply-cmd
157  :print-help
158  :print-version
159  :print-usage
160  :handle-unknown-argument
161  :handle-missing-argument
162  :handle-invalid-argument
163  :cli-opt
164  :cli-opt-val
165  :cli-val
166  :cli-cmd-args
167  :cli-cmd
168  :cli-cd
169  :find-cmd
170  :find-opts
171  :find-short-opts
172  :install-ast
173  ;; :gen-cli-thunk
174  :install-thunk
175  :cli
176  :cli-equal
177  :defopt
178  :defcmd
179  :define-cli
180  ;; ast types
181  :opt
182  :cmd
183  ;; :arg
184  :cli-name
185  :cli-opts
186  :cli-cmds
187  :cli-thunk
188  :cli-description
189  :cli-version
190  :cli-usage))
191 
192 (defpackage :cli/tmux
193  (:use :cl :std)
194  (:export))
195 
196 (in-package :std-user)
197 
198 (defpkg :cli
199  (:use :cl :std)
200  (:use-reexport :cli/shell :cli/ansi :cli/prompt
201  :cli/progress :cli/spark :cli/prompt :cli/ed
202  :cli/repl :cli/clap))
203 
204 (defpkg :cli-user (:use :cl :std :cli))
205