2013-06-14 17:22:55 +08:00
|
|
|
package main
|
|
|
|
|
2013-06-16 16:08:08 +08:00
|
|
|
import (
|
2013-07-29 14:39:21 +08:00
|
|
|
"os"
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
2013-09-18 16:40:47 +08:00
|
|
|
"../parse"
|
2013-09-18 16:42:10 +08:00
|
|
|
"../edit"
|
2013-09-18 22:51:48 +08:00
|
|
|
"../eval"
|
2013-09-22 18:49:37 +08:00
|
|
|
"../async"
|
2013-06-16 16:08:08 +08:00
|
|
|
)
|
|
|
|
|
2013-06-16 16:37:17 +08:00
|
|
|
func lackeol() {
|
2013-07-29 14:39:21 +08:00
|
|
|
fmt.Println("\033[7m%\033[m")
|
2013-06-16 16:37:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 17:22:55 +08:00
|
|
|
func main() {
|
2013-09-18 19:53:07 +08:00
|
|
|
fmt.Printf("My pid is %d\n", syscall.Getpid())
|
2013-07-29 14:39:21 +08:00
|
|
|
|
2013-08-15 16:36:29 +08:00
|
|
|
cmd_no := 0
|
|
|
|
|
2013-09-27 12:19:06 +08:00
|
|
|
tr, err := async.NewTimedReader(os.Stdin)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-09-22 18:49:37 +08:00
|
|
|
|
2013-07-29 14:39:21 +08:00
|
|
|
for {
|
2013-08-15 16:36:29 +08:00
|
|
|
cmd_no++
|
2013-10-17 10:21:35 +08:00
|
|
|
name := fmt.Sprintf("<tty %d>", cmd_no)
|
2013-08-15 16:36:29 +08:00
|
|
|
|
2013-09-27 12:19:06 +08:00
|
|
|
ed, err := edit.Init(os.Stdin, tr)
|
2013-09-03 22:22:28 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-09-18 22:58:50 +08:00
|
|
|
|
2013-09-05 16:59:57 +08:00
|
|
|
lr := ed.ReadLine("das> ")
|
|
|
|
err = ed.Cleanup()
|
2013-07-29 14:39:21 +08:00
|
|
|
if err != nil {
|
2013-09-03 22:22:28 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if lr.Eof {
|
2013-07-29 14:39:21 +08:00
|
|
|
lackeol()
|
|
|
|
break
|
2013-09-03 22:22:28 +08:00
|
|
|
} else if lr.Err != nil {
|
|
|
|
panic(lr.Err)
|
2013-07-29 14:39:21 +08:00
|
|
|
}
|
2013-09-18 22:58:50 +08:00
|
|
|
|
2013-10-17 10:21:35 +08:00
|
|
|
tree, pe := parse.Parse(name, lr.Line, false)
|
|
|
|
if pe != nil {
|
|
|
|
fmt.Print(pe.Pprint())
|
2013-08-15 16:36:29 +08:00
|
|
|
continue
|
|
|
|
}
|
2013-09-18 19:46:34 +08:00
|
|
|
|
2013-10-02 19:25:25 +08:00
|
|
|
updates, err := eval.ExecPipeline(tree.Root.(*parse.ListNode))
|
2013-09-18 16:36:04 +08:00
|
|
|
if err != nil {
|
2013-09-18 22:51:48 +08:00
|
|
|
fmt.Println(err)
|
2013-10-02 19:25:25 +08:00
|
|
|
continue
|
2013-08-17 20:06:06 +08:00
|
|
|
}
|
|
|
|
|
2013-10-02 19:25:25 +08:00
|
|
|
for i, update := range updates {
|
|
|
|
// TODO Should check update.Msg
|
|
|
|
for up := range update {
|
2013-10-02 22:42:08 +08:00
|
|
|
switch up.Msg {
|
2013-10-02 22:44:28 +08:00
|
|
|
case "0", "":
|
2013-10-02 22:42:08 +08:00
|
|
|
default:
|
|
|
|
fmt.Printf("Command #%d update: %s\n", i, up.Msg)
|
|
|
|
}
|
2013-10-02 19:25:25 +08:00
|
|
|
}
|
2013-09-19 13:20:55 +08:00
|
|
|
}
|
2013-07-29 14:39:21 +08:00
|
|
|
}
|
2013-06-14 17:22:55 +08:00
|
|
|
}
|