changelog shortlog graph tags branches changeset files revisions annotate raw help

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

changeset 129: 80a56483f9b5
parent: d0b235557fab
child: 193d1ea7d684
author: ellis <ellis@rwest.io>
date: Tue, 26 Dec 2023 23:44:35 -0500
permissions: -rw-r--r--
description: more organ work
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 (uiop:define-package :cli
22  (:use :cl :std :log :sb-ext)
23  (:import-from :uiop :println)
24  (:import-from :sb-ext :parse-native-namestring)
25  (:shadowing-import-from :sb-ext :exit)
26  (:export
27  :*argv*
28  :init-args
29  :cli-arg0
30  :cli-args
31  :command-line-args
32  :*cli-group-separator*
33  :*cli-opt-kinds*
34  :global-opt-p
35  :exec-path-list
36  :program-list
37  :find-exe
38  :ld-library-path-list
39  :argp
40  :$val
41  :$args
42  :$argc
43  :$opts
44  :$optc
45  :make-shorty
46  :with-cli-handlers
47  :defmain
48  :main
49  :with-cli
50  :make-cli
51  ;; opt-parsers
52  :make-opt-parser
53  :parse-bool-opt
54  :parse-str-opt
55  :parse-form-opt
56  :parse-list-opt
57  :parse-sym-opt
58  :parse-key-opt
59  :parse-num-opt
60  :parse-file-opt
61  :parse-dir-opt
62  :make-opts
63  :make-cmds
64  :active-opts
65  :active-cmds
66  :proc-args
67  :make-cli-node
68  :make-cli-ast
69  :proc-args
70  :parse-args
71  :debug-opts
72  :do-cmd
73  :do-opt
74  :call-opt
75  :call-cmd
76  :apply-cmd
77  :print-help
78  :print-version
79  :print-usage
80  :handle-unknown-argument
81  :handle-missing-argument
82  :handle-invalid-argument
83  :cli-opt
84  :cli-val
85  :cli-cmd-args
86  :cli-cmd
87  :cli-cwd
88  :find-cmd
89  :find-opt
90  :find-short-opt
91  :install-ast
92  ;; :gen-cli-thunk
93  :install-thunk
94  :cli
95  :cli-equal
96  :defopt
97  :defcmd
98  :define-cli
99  ;; ast types
100  :opt
101  :cmd
102  ;; :arg
103  :cli-name
104  :cli-opts
105  :cli-cmds
106  :cli-thunk
107  :cli-description
108  :cli-version
109  :cli-usage))
110 
111 (defpackage :cli/ansi
112  (:use :cl :std)
113  (:shadow :ed)
114  (:nicknames :ansi)
115  (:export
116  ;; ESC sequences
117  :ris :reset-to-initial-state
118  ;; CSI sequences
119  ;; Cursor control
120  :cuu :cursor-up
121  :cud :cursor-down
122  :cuf :cursor-forward
123  :cub :cursor-backward
124  :cnl :cursor-next-line
125  :cpl :cursor-preceding-line
126  :cha :cursor-horizontal-absolute
127  :cup :cursor-position
128  :vpa :vertical-position-absolute
129  :vpr :vertical-position-relative
130  :vpb :vertical-position-backward
131  :scosc :save-cursor-position
132  :scorc :restore-cursor-position
133  :ed :erase-in-display :erase-below :erase-above :erase :erase-saved-lines
134  :el :erase-in-line :erase-right :erase-left :erase-line
135  :sgr :select-graphic-rendition
136  :dsr :device-status-report
137  ;; DEC private mode set and reset
138  :decset :dec-private-mode-set
139  :decrst :dec-private-mode-reset
140  :show-cursor :hide-cursor
141  :use-alternate-screen-buffer :use-normal-screen-buffer
142  ;; common
143  :clear
144  :home
145  ;; stty
146  :set-tty-mode))
147 
148 (defpackage :cli/prompt
149  (:use :cl :std)
150  (:export
151  :completing-read
152  :defprompt))
153 
154 (defpackage :cli/progress
155  (:use :cl :std)
156  (:export
157  :update-progress
158  :with-progress-bar
159  :*progress-bar*
160  :*progress-bar-enabled*
161  :start-progress-display
162  :finish-progress-display
163  :progress-mutex
164  :uncertain-size-progress-bar
165  :progress-bar))
166 
167 (defpackage :cli/spark
168  (:use :cl :std)
169  (:export
170  :spark :*ticks*
171  :vspark :*vticks*))
172 
173 (defpackage :cli/repl
174  (:use :cl :std :cli :cli/progress :cli/spark)
175  (:export))
176 
177 (defpackage :cli/ed
178  (:use :cl :std :cli))