-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (55 loc) · 980 Bytes
/
Copy pathmain.go
File metadata and controls
64 lines (55 loc) · 980 Bytes
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
63
64
package main
import (
"fmt"
"os"
"strings"
cl "dlsh/utils/cmdline"
eu "dlsh/utils/execunit"
)
func main() {
fmt.Println("$HOME=" + os.Getenv("HOME"))
tty := cl.NewTty()
tty.GetPrompt()
for {
tty.ReflectPrompt()
tty.Raw()
line := tty.Read()
tty.Restore()
line = strings.Trim(line, " \t")
tokens := cl.Tokenize(&line)
fmt.Println(tokens, len(tokens))
dlsh := eu.NewExecUnit()
dlsh.Instructions = cl.Parse(tokens)
for _, ins := range dlsh.Instructions {
dlsh.Ins = ins
cmd := ins.Cmd
if cmd.Path == "cd" {
if !ins.Chdir() {
break
}
tty.GetPrompt()
if ins.InsType != cl.PIPE {
continue
}
} else if cmd.Path == "exit" {
tty.DumpHist()
return
}
switch ins.InsType {
case cl.EXEC:
if dlsh.Piped {
dlsh.DrainExec()
} else {
dlsh.Run()
}
case cl.PIPE:
dlsh.ExecPipe()
case cl.WAIT:
dlsh.DrainPipeline()
}
if dlsh.Err != nil {
break
}
}
}
}