repl.go 895 B

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