bhauman / rebel-readline

Terminal readline library for Clojure dialects
Eclipse Public License 1.0
684 stars 37 forks source link

explore nesting repls so that they have a proper readline functionality #103

Closed bhauman closed 6 years ago

bhauman commented 6 years ago

Currently when you nest a repl you drop out of the line reader. The repl will work as expected but the line reader will not be engauged. This is for simplicity.

Because the line-reader handlers the prompt things get tricky when you launch a subrepl with the parent readline engaged.

The obvious use case here is launching a debugging context-locals repl and still have readline engauged. This is actually not a problem and this will mostly work with with-readline-input-stream if you disable the prompt of the sub-clojure.main/repl

But the most important case to explore is the case of a nested cljs-repl where the service is different.

The obvious solution is to have proxys for clojure.main/repl and cljs.repl/repl that handle the top level case and the nested cases gracefully.

One thought here that troubled me was wether we should instead be using multimethods for service implementation. That way we could just change the :type field of the service atom and get new service behavior. Also mutimethods would mean that the service is just an atom. with dispatch on its type. This would allow easier partial implementations. If you needed to call the service at a per char granularity multimethod dispatch could be slow???

Another thing to think about here is the case where you just replace the input with the line reader. In this case, we will want to just change the type of the line reader and possibly call init and destroy around it.

bhauman commented 6 years ago

It would certainly also be possible to nest an nREPL inside a clojure.main/repl. Need to keep this in mind.

bhauman commented 6 years ago

First discoveries: it's mostly possible to nest repls with the current code design by using nested rebinding of *service* and *line-reader* as is but you will be stuck with the highlighting settings of the previous service bc highlight can be called on another thread. This can be mostly fixed so that highlight uses the bound service before reverting to the stored service.

But when you pop out of the nested repl you will pop any changed repl settings back to the previous repl settings. This is not so bad.

The service init function is really needed.