elvish/main/main.go

63 lines
940 B
Go
Raw Normal View History

2013-06-14 17:22:55 +08:00
package main
2013-06-16 16:08:08 +08:00
import (
"os"
"fmt"
"syscall"
2013-09-18 16:40:47 +08:00
"../parse"
2013-09-18 16:42:10 +08:00
"../edit"
"../eval"
2013-06-16 16:08:08 +08:00
)
func lackeol() {
fmt.Println("\033[7m%\033[m")
}
2013-06-14 17:22:55 +08:00
func main() {
fmt.Printf("My pid is %d\n", syscall.Getpid())
cmd_no := 0
for {
cmd_no++
name := fmt.Sprintf("<interactive code %d>", cmd_no)
2013-09-18 16:42:10 +08:00
ed, err := edit.Init(os.Stdin)
if err != nil {
panic(err)
}
lr := ed.ReadLine("das> ")
err = ed.Cleanup()
if err != nil {
panic(err)
}
if lr.Eof {
lackeol()
break
} else if lr.Err != nil {
panic(lr.Err)
}
line := lr.Line
2013-09-18 19:13:57 +08:00
tree, err := parse.Parse(name, line, false)
if err != nil {
fmt.Println("Parser error:", err)
continue
}
cmd := tree.Root.(*parse.ListNode).Nodes[0].(*parse.CommandNode)
pid, err := eval.ExecCommand(cmd)
if err != nil {
fmt.Println(err)
continue
2013-08-17 20:06:06 +08:00
}
var ws syscall.WaitStatus
var ru syscall.Rusage
// TODO Should check ws
syscall.Wait4(pid, &ws, 0, &ru)
}
2013-06-14 17:22:55 +08:00
}