-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlauncher-base.rkt
40 lines (35 loc) · 1.13 KB
/
launcher-base.rkt
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
#lang racket/base
; launcher-base.rkt
(require rwind/base
rwind/util
rwind/doc-string
racket/file
racket/list)
(define history-max-length 50)
(define rwind-launcher-history-file
(find-user-config-file rwind-dir-name "rwind-launcher-history.txt"))
(define* (launcher-history)
"History of launched commands from the Rwind launcher."
(define hist
(if (file-exists? rwind-launcher-history-file)
(reverse (file->lines rwind-launcher-history-file))
null))
;; If history is too long, truncate it and rewrite the file
;; (we don't want the history to grow indefinitely)
(when (> (length hist) (* 2 history-max-length))
(display-lines-to-file
(reverse (take hist history-max-length))
rwind-launcher-history-file
#:mode 'text
#:exists 'replace))
hist)
(define* (add-launcher-history! command)
"Add to the history of launched commands."
(with-output-to-file rwind-launcher-history-file
(λ ()
(printf "~a~n" command))
#:mode 'text
#:exists 'append))
(define* (open-launcher)
"Show the program launcher."
(rwind-system "racket -l rwind/launcher"))