reedline icon indicating copy to clipboard operation
reedline copied to clipboard

Multiple prompt colors

Open nickeb96 opened this issue 2 years ago • 8 comments

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.

nickeb96 avatar Jun 26 '23 13:06 nickeb96

I'm not sure I'm following. You're free to change the prompt. This is what mine looks like in nushell. image

fdncred avatar Jun 26 '23 15:06 fdncred

I'm not talking about nushell. I'm referring to this library crate, reedline.

nickeb96 avatar Jun 26 '23 15:06 nickeb96

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?

fdncred avatar Jun 26 '23 15:06 fdncred

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?

nickeb96 avatar Jun 26 '23 15:06 nickeb96

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

fdncred avatar Jun 26 '23 16:06 fdncred

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?

nickeb96 avatar Jun 26 '23 16:06 nickeb96

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.

fdncred avatar Jun 26 '23 16:06 fdncred

I'll try to put together an api proposal later this week

nickeb96 avatar Jun 27 '23 02:06 nickeb96