elvish/main/main.go

73 lines
1.0 KiB
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-09-22 18:49:37 +08:00
"../async"
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
tr, err := async.NewTimedReader(os.Stdin)
if err != nil {
panic(err)
}
2013-09-22 18:49:37 +08:00
for {
cmd_no++
name := fmt.Sprintf("<tty %d>", cmd_no)
ed, err := edit.Init(os.Stdin, tr)
if err != nil {
panic(err)
}
2013-09-18 22:58:50 +08:00
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)
}
2013-09-18 22:58:50 +08:00
tree, pe := parse.Parse(name, lr.Line, false)
if pe != nil {
fmt.Print(pe.Pprint())
continue
}
updates, err := eval.ExecPipeline(tree.Root.(*parse.ListNode))
if err != nil {
fmt.Println(err)
continue
2013-08-17 20:06:06 +08:00
}
for i, update := range updates {
// TODO Should check update.Msg
for up := range update {
switch up.Msg {
case "0", "":
default:
fmt.Printf("Command #%d update: %s\n", i, up.Msg)
}
}
}
}
2013-06-14 17:22:55 +08:00
}