mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Add stub to Evaler; don't flood the terminal when I/O error occurs.
This commit is contained in:
parent
1f1e739ef2
commit
ff76359063
|
@ -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()))
|
||||
|
|
11
run/run.go
11
run/run.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user