-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.go
55 lines (40 loc) · 924 Bytes
/
shell.go
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
package main
import (
"fmt"
"os"
)
var status parseStatus
//loop forever: get line from readch and treat it accordingly
func Gosh() {
readch := make(chan string)
exch := make(chan *command)
initializeVars()
initializePrompt()
initializeCommands()
parser := initializeParser()
go prompter(readch)
go execute(exch)
var line string
var cmd *command
status = READY
for {
line = <-readch
cmd, status = parser.parse(line)
switch status {
case READY:
if cmd != nil {
//FIXME there's still some kind of
// race condition happenning with pagers
exch <- cmd
_ = <-exch //block until execution releases
}
readch <- "" //release prompt
//case READING, SELECTING, TRACING:
}
}
}
func Status() parseStatus {
return status
}
func error(msg string) { fmt.Fprintln(os.Stderr, msg) }
func debug(msg string) { fmt.Fprint(os.Stdout, "DEBUG "); fmt.Fprintln(os.Stdout, msg) }