click-contrib / click-repl

Subcommand REPL for click apps
MIT License
215 stars 41 forks source link

Added ReplContext class #118

Closed GhostOps77 closed 3 weeks ago

GhostOps77 commented 2 months ago

This class is very much similar to click.Context class, which keeps track of every layer of nested group and chained command invocations are to be done, based on the input from the prompt, while having link with their parent context

But this class is used to do the same but keeps track of each layer of REPL session in a nested layer of REPL sessions.

In this PR:

The construction of PromptSession object is moved into ReplContext's __init__ method and stored as one of the context object's attributes. So that it'll be invoked only if the REPL is invoked in a proper terminal window, rather than via piping in shell. This class also allows users to change prompt text of the REPL at runtime, and also keep track of the command's history.

These are some of the features that I have manually implemented, rather than changing them via the PromptSession object directly. That's why I've made that object to be in an attribute of ReplContext, so that a user can access it from anywhere using click_repl.globals_.get_current_repl_ctx function.

Why did I make this?

Well, instead of giving no or certain options to customize the prompt, it's better to use hand over the object thats responsible for showing the REPL, to the user is far better, in my opinion. So that they can do whatever they want. It's up to them.

I see that in my last PR I haven't described it well. I hope this explanation is ok just dont ghost me, im all ears about any feedback to this PR.

GhostOps77 commented 2 months ago

@auvipy can u review this one? i hope i got it right this time

auvipy commented 3 weeks ago

can you please review this? https://github.com/click-contrib/click-repl/pull/115