forked from rain-1/linenoise-mob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.sps
executable file
·62 lines (55 loc) · 1.79 KB
/
example.sps
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
58
59
60
61
62
#!/usr/bin/env scheme-script
;; -*- mode: scheme; coding: utf-8 -*- !#
;; R6RS Scheme version of example.c.
#!r6rs
(import
(rnrs)
(only (srfi :13 strings) string-prefix?)
(linenoise))
(when (file-exists? "history.txt")
(linenoise-history-load "history.txt"))
(linenoise-set-completion-callback
(lambda (line add-completion add-history-completions)
(add-history-completions)
(when (string-prefix? "h" line)
(add-completion "hello こんにちは")
(add-completion "hello こんにちは there"))))
(linenoise-set-hints-callback
(lambda (line)
(cond ((string-ci=? "hello" line)
(values " World" 'magenta #f))
((string-ci=? "こんにちは" line)
(values " 世界" 'magenta #f))
(else
(values #f #f #f)))))
(for-each
(lambda (arg)
(cond ((string=? "--multiline" arg)
(linenoise-set-multi-line #t))
((string=? "--keycodes" arg)
(linenoise-print-key-codes))
(else
(display "Usage: example.sps [--multiline] [--keycodes]\n"
(current-error-port))
(exit 1))))
(cdr (command-line)))
(define (main)
(let ((line (linenoise "\x1b;[32mこんにちは\x1b;[0m> ")))
(unless (eof-object? line)
(cond
((and (not (string=? line "")) (not (string-prefix? "/" line)))
(display "echo: ")
(write line)
(newline)
(linenoise-history-add line)
(linenoise-history-save "history.txt"))
((string-prefix? "/historylen" line)
(let ((len (string->number
(substring line 12 (string-length line)))))
(linenoise-history-set-max-len len)))
((string-prefix? "/" line)
(display "Unrecognized command: ")
(display line)
(newline)))
(main))))
(main)