File tree 1 file changed +23
-6
lines changed
1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
(provide readline)
4
4
5
+ (require (prefix-in readline: readline/readline))
6
+
5
7
(require "types.rkt " )
6
8
9
+ (define history-loaded #f )
10
+ (define HISTORY-FILE (format "~a/.mal-history " (find-system-path 'home-dir )))
11
+
12
+ (define (load-history path)
13
+ (map
14
+ (lambda (line) (readline:add-history line))
15
+ (string-split
16
+ (port->string (open-input-file path))
17
+ #px"\n " )))
18
+
7
19
(define (readline prompt)
8
- (_printf "~a " prompt)
9
- (let ([line (read-line (current-input-port) 'any )])
20
+ (when (not history-loaded)
21
+ (set! history-loaded #t )
22
+ (load-history HISTORY-FILE))
23
+ (let ([line (readline:readline prompt)])
10
24
(if (eq? eof line)
11
25
nil
12
- line)))
13
-
14
-
15
-
26
+ (begin
27
+ (readline:add-history line)
28
+ (with-output-to-file
29
+ HISTORY-FILE
30
+ (lambda () (printf "~a~n " line))
31
+ #:exists 'append )
32
+ line))))
You can’t perform that action at this time.
0 commit comments