-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dynamic prompt support via ExternalPrinter #772
base: master
Are you sure you want to change the base?
Conversation
rustyline doesn't currently support changing the prompt while in the core readline loop. There are a number of open PRs and issues for this functionality, but all of them appear to be stalled for more than a year. Looking at kkawakam#696 and 4ec26e8, the traditional appoach to this is to provide a reference to a trait object (`Prompt` or `ToString`), but with that appoach there's no way to cause the prompt to be redrawn for a change without user input. This means for these appoaches the prompt could change without being displayed to the user. There's an existing mechanism to allow another async task/thread to push input into the core readline loop, the `ExternalPrinter`. In this commit, I expand `ExternalPrinter` to add `set_prompt()`. With various plumbing, this function results in `wait_for_input` to return `Cmd::SetPrompt(String)`. One of key change here is `State.prompt` changes from `&str` to `String`. There is a performance hit here from the copy, but rustyline would need to prompt and receive input hundreds of times per second for the copy to have a noticable performance inpact. Added examples/dynamic_prompt.rs to demonstrate the functionality. Closes kkawakam#417 Related kkawakam#208, kkawakam#372, kkawakam#369, kkawakam#417, kkawakam#598, kkawakam#696
Note, this is only the unix implementation. I do not have access to a windows development environment to add the implementation for that side. It's not a complicated change, but for now it's marked as |
See #126 (comment)
And another issue related to the prompt: #348
So, for me, when only the prompt ( I apologize for the stalled situation induced by some bad design choices. |
from PR comments: @gwenn> So, for me, when only the prompt (Cmd::SetPrompt) is changed, we should not have to redraw the whole line (s.refresh_line()) or at least we should not have to invoke Hinter::hint() / Highlighter::highlight_char / Highlighter::highlight (only Highlighter::highlight_prompt). Implemented this as `Refresher::refresh_prompt()` that is a cut-down version of `Refresher::refresh_line()`.
TL;DR: Pushing a change to reduce processing when prompt changes. Linenoise approach is out-of-scope for this PR, but I am looking at how to do something similar. Reduce computation for
|
Hey, would love to see progress here! |
rustyline doesn't currently support changing the prompt while in the core readline loop. There are a number of open PRs and issues for this functionality, but all of them appear to be stalled for more than a year.
Looking at #696 and 4ec26e8, the traditional appoach to this is to provide a reference to a trait object (
Prompt
orToString
), but with that appoach there's no way to cause the prompt to be redrawn for a change without user input. This means for these appoaches the prompt could change without being displayed to the user.There's an existing mechanism to allow another async task/thread to push input into the core readline loop, the
ExternalPrinter
.In this commit, I expand
ExternalPrinter
to addset_prompt()
. With various plumbing, this function results inwait_for_input
to returnCmd::SetPrompt(String)
.One of key change here is
State.prompt
changes from&str
toString
. There is a performance hit here from the copy, but rustyline would need to prompt and receive input hundreds of times per second for the copy to have a noticable performance inpact.Added examples/dynamic_prompt.rs to demonstrate the functionality.
Closes #417
Related #208, #372, #369, #417, #598, #696