-
-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathmain.pony
More file actions
58 lines (46 loc) · 1.25 KB
/
main.pony
File metadata and controls
58 lines (46 loc) · 1.25 KB
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
use "signals"
use "term"
use "promises"
class Handler is ReadlineNotify
let _commands: Array[String] = _commands.create()
var _i: U64 = 0
new create() =>
_commands.push("quit")
_commands.push("happy")
_commands.push("hello")
fun ref apply(line: String, prompt: Promise[String]) =>
if line == "quit" then
prompt.reject()
else
_i = _i + 1
prompt(_i.string() + " > ")
end
_update_commands(line)
fun ref _update_commands(line: String) =>
for command in _commands.values() do
if command.at(line, 0) then
return
end
end
_commands.push(line)
fun ref tab(line: String): Seq[String] box =>
let r = Array[String]
for command in _commands.values() do
if command.at(line, 0) then
r.push(command)
end
end
r
actor Main
new create(env: Env) =>
env.out.print("Use 'quit' to exit.")
// Building a delegate manually
let term = ANSITerm(SignalAuth(env.root),
Readline(recover Handler end, env.out), env.input)
term.prompt("0 > ")
let notify = object iso
let term: ANSITerm = term
fun ref apply(data: Array[U8] iso) => term(consume data)
fun ref dispose() => term.dispose()
end
env.input(consume notify)