diff --git a/pkg/eval/builtin_special.go b/pkg/eval/builtin_special.go index 8b8bdb21..02d595d7 100644 --- a/pkg/eval/builtin_special.go +++ b/pkg/eval/builtin_special.go @@ -307,7 +307,7 @@ func evalModule(fm *Frame, key string, src *Source) (Ns, error) { fm.Evaler, src, diag.Ranging{From: 0, To: len(src.Code)}, modGlobal, make(Ns), - fm.ports, + fm.intCh, fm.ports, fm.addTraceback(), false, } diff --git a/pkg/eval/eval.go b/pkg/eval/eval.go index 6ec30a50..e5809634 100644 --- a/pkg/eval/eval.go +++ b/pkg/eval/eval.go @@ -47,9 +47,6 @@ type Evaler struct { beforeChdir []func(string) afterChdir []func(string) - // Used to receive SIGINT. - intCh chan struct{} - // State of the module system. libDir string bundled map[string]string @@ -142,7 +139,6 @@ func NewEvaler() *Evaler { }, bundled: bundled.Get(), Editor: nil, - intCh: nil, } beforeChdirElvish, afterChdirElvish := vector.Empty, vector.Empty @@ -282,10 +278,8 @@ func (ev *Evaler) EvalInTTY(op Op) error { defer stdPorts.close() intCh, cleanupInt := listenInterrupts() - ev.intCh = intCh defer func() { cleanupInt() - ev.intCh = nil // Put myself in foreground, in case some command has put me in background. err := putSelfInFg() if err != nil { @@ -293,7 +287,9 @@ func (ev *Evaler) EvalInTTY(op Op) error { } }() - return ev.Eval(op, stdPorts.ports[:]) + ec := NewTopFrame(ev, op.Src, stdPorts.ports[:]) + ec.intCh = intCh + return ec.eval(op.Inner) } // Compile compiles Elvish code in the global scope. If the error is not nil, it diff --git a/pkg/eval/frame.go b/pkg/eval/frame.go index a225d0ed..e9bd2505 100644 --- a/pkg/eval/frame.go +++ b/pkg/eval/frame.go @@ -16,11 +16,14 @@ import ( // shortly after creation; new Frame's are "forked" when needed. type Frame struct { *Evaler + srcMeta *Source srcRange diag.Ranging local, up Ns - ports []*Port + + intCh chan struct{} + ports []*Port traceback *stackTrace @@ -35,7 +38,7 @@ func NewTopFrame(ev *Evaler, src *Source, ports []*Port) *Frame { ev, src, diag.Ranging{From: 0, To: len(src.Code)}, ev.Global, make(Ns), - ports, + nil, ports, nil, false, } } @@ -128,7 +131,7 @@ func (fm *Frame) fork(name string) *Frame { return &Frame{ fm.Evaler, fm.srcMeta, fm.srcRange, fm.local, fm.up, - newPorts, + fm.intCh, newPorts, fm.traceback, fm.background, } }