-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.ss
57 lines (48 loc) · 1.75 KB
/
command.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(library
(melt command)
(export create-command
command-add!
command-remove!
command-proc
command-desc
command-name
command-query
show-commands)
(import (scheme)
(melt data)
(melt lib console))
;; command itself is a data
;; symbol, which specifics string in command line
;; string, one line description
;; procedure for the command, accept arguments
(define (create-command name desc proc)
(create-data '(name desc proc)
`(,name ,desc ,proc)))
(define (command-name command)
(data-value-query 'name command))
(define (command-desc command)
(data-value-query 'desc command))
(define (command-proc command)
(data-value-query 'proc command))
;; add one command to command data
(define (command-add! command data)
(update-data! (create-data (list (command-name command))
(list command))
data))
;; remove one command in command data
(define (command-remove! command data)
(update-data! (list (command-name command)) data))
;; query command in a data
(define (command-query name data)
(data-value-query name data))
;; display command names and its description
(define (show-commands command-data)
(define (show-command command)
(format #t " ~8a>>> ~a~%" (symbol->string (command-name command)) (command-desc command)))
; (gem:format " ~10@a-->~10a~%"
; `(("[37;1m" . ,(symbol->string (command-name command)))
; ("[38;5;166m" . ,(command-desc command)))))
(do ((command-list (data-values command-data) (cdr command-list)))
((null? command-list) #t)
(show-command (car command-list))))
)