src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/edit/repl.go (about) 1 package edit 2 3 // This file encapsulates functionality related to a complete REPL cycle. Such as capturing 4 // information about the most recently executed interactive command. 5 6 import ( 7 "src.elv.sh/pkg/eval" 8 "src.elv.sh/pkg/eval/vals" 9 "src.elv.sh/pkg/eval/vars" 10 "src.elv.sh/pkg/parse" 11 ) 12 13 func initRepl(ed *Editor, ev *eval.Evaler, nb eval.NsBuilder) { 14 var commandDuration float64 15 // TODO: Ensure that this variable can only be written from the Elvish code 16 // in elv_init.go. 17 nb.AddVar("command-duration", vars.FromPtr(&commandDuration)) 18 19 afterCommandHook := newListVar(vals.EmptyList) 20 nb.AddVar("after-command", afterCommandHook) 21 ed.AfterCommand = append(ed.AfterCommand, 22 func(src parse.Source, duration float64, err error) { 23 m := vals.MakeMap("src", src, "duration", duration, "error", err) 24 eval.CallHook(ev, nil, "$<edit>:after-command", afterCommandHook.Get().(vals.List), m) 25 }) 26 }