Add stub to Evaler; don't flood the terminal when I/O error occurs.

This commit is contained in:
Qi Xiao 2016-02-21 16:23:36 +01:00
parent 1f1e739ef2
commit ff76359063
2 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/elves/elvish/parse"
"github.com/elves/elvish/store"
"github.com/elves/elvish/stub"
"github.com/elves/elvish/util"
)
@ -30,6 +31,7 @@ type Evaler struct {
global Namespace
modules map[string]Namespace
store *store.Store
Stub *stub.Stub
}
// EvalCtx maintains an Evaler along with its runtime context. After creation
@ -50,7 +52,7 @@ func (ec *EvalCtx) evaling(n parse.Node) {
// NewEvaler creates a new Evaler.
func NewEvaler(st *store.Store) *Evaler {
ev := &Evaler{nil, map[string]Namespace{}, st}
ev := &Evaler{nil, map[string]Namespace{}, st, nil}
// Construct initial global namespace
pid := String(strconv.Itoa(syscall.Getpid()))

View File

@ -15,6 +15,7 @@ import (
"github.com/elves/elvish/eval"
"github.com/elves/elvish/parse"
"github.com/elves/elvish/store"
"github.com/elves/elvish/stub"
"github.com/elves/elvish/sys"
"github.com/elves/elvish/util"
)
@ -69,6 +70,13 @@ func Main() {
}
}()
stub, err := stub.NewStub(os.Stderr)
if err != nil {
fmt.Println("failed to spawn stub:", err)
} else {
ev.Stub = stub
}
if len(args) == 1 {
script(ev, args[0])
} else {
@ -158,6 +166,9 @@ func interact(ev *eval.Evaler, st *store.Store) {
fmt.Println("Falling back to basic line editor")
readLine = basicReadLine
usingBasic = true
} else {
fmt.Println("Don't know what to do, pid is", os.Getpid())
select {}
}
continue
}