Multiple prompt colors
It would be very helpful if we could set different colors for different parts of a dynamic prompt string. Take the following prompt for example:
[current-message] account>
Most shells, editors, and cli tools would allow you to make current-message one color, the square brackets a different color, and account another color.
I can't do that with reedline currently without trying to disable its coloring effects entirely and manually inserting ansi escape sequences in Prompt::render_prompt_left.
I'm not sure I'm following. You're free to change the prompt. This is what mine looks like in nushell.
I'm not talking about nushell. I'm referring to this library crate, reedline.
Right, but I was just using nushell as an example since it uses reedline. Maybe I'm still misunderstanding but it sounds like you're wanting a reedline config file where you can customize the look?
Implementing reedline::Prompt for a type requires defining get_prompt_color which can only return a single color that gets applied to the entire prompt line.
I'd like to have a way to highlight different parts of the prompt with different colors.
This is for a client I'm writing that I'd like to use reedline for. Right now this is the only point of friction for me.
How does nushell have multi-colored prompts if the Prompt interface only supports a single color? Does it embed ansi escapes into the prompt string returned by Prompt::render_prompt_left?
It's been a while since we implemented that code, but I believe nushell sends strings that contain ansi escape sequences. Here's an example (using nushell scripting) of how I build up the left prompt. https://github.com/nushell/nu_scripts/blob/9d12487d11ce028a3601c07f806e1cb5e10704f2/modules/prompt/oh-my.nu#L312-L340. You can also look at the nushell code here https://github.com/fdncred/nushell/blob/6d84eec5cdba5ea927e49274c2336341707f697f/crates/nu-cli/src/prompt.rs#L29-L30
Ok thanks, I will go with the embedded ansi escape approach for now.
Is possible for the reedline::Prompt api to be extended in the future to natively support multiple colors?
i'm sure it's possible. feel free to propose an api or submit a preliminary pr for us to look at. we'd like reedline to be as useful as possible.
I'll try to put together an api proposal later this week