ReplMaker.jl icon indicating copy to clipboard operation
ReplMaker.jl copied to clipboard

feature request: enter repl when called

Open ExpandingMan opened this issue 3 years ago • 3 comments

Sometimes I want to give a user the opportunity to intervene in some otherwise-automated process if a certain condition is satisfied.

As a toy example, consider an AbstractDict object where upon inserting a key-value, if the key exists and isinteractive(), the user is dropped into a REPL mode that lets them inspect the contents of the dictionary, the pair being added, and decide what to do.

Currently I don't think ReplMaker can be used for this case, because it can only add REPL modes which are triggered from a key-press in the default Julia REPL. What would be needed is something that returns a REPL object and runs it on call. I don't think this would require too much on top of the REPL stdlib, however the stdlib does not have a very good (or well documented) API for this sort of thing, so I think it would be worth doing here.

ExpandingMan avatar Apr 18 '22 18:04 ExpandingMan

That's actually already implemented with enter_mode!: https://github.com/MasonProtter/ReplMaker.jl/blob/master/src/ReplMaker.jl#L145-L174

I should put it in the README though

MasonProtter avatar Apr 18 '22 21:04 MasonProtter

Ah, nice. Thanks, please document!

ExpandingMan avatar Apr 18 '22 21:04 ExpandingMan

Played around with this a bit today, some things that would still be nice to have

  • A "lower level" function for creating the REPL mode that doesn't do some of the extra stuff in initrepl like set the key command for entering the mode (currently to not set a key you need to hack it by setting it to "" or something).
  • Clear semantics for exiting. Currently if you call enter_mode! from a function you'd need a couple of hacks to get it to exit the REPL and resume execution of the function. Granted, some of this might not be so easy because it looks like most of this is handled by REPL and I'm not sure how flexible it is.

ExpandingMan avatar Apr 19 '22 16:04 ExpandingMan