-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Add the ability to configure per-module color styles #285
Conversation
@starship/astronauts Looks like I have a working draft of this puppy (screenshot at end). The last thing I'd like to do before integrating it with our existing modules is to make sure the syntax is good. The current rules for the stylestring are as follows: Valid tokens
Valid colorsA color can take on one of the three following forms:
Foreground/Background
Bold and Italic
We can add additional styling codes that are supported by ANSI terminals (e.g. italic, dimmed, strikethrough), but given that a lot of terminal emulators don't support some of these codes, we might want to be judicious about what we support. Does anyone have improvements to suggest for how this little DSL works before I bake it into the codebase? Do we want to add support for any additional styling? |
Looks like a good start @chipbuster, I like the different options you've provided for specifying colors. Regarding the syntax, I do find it a little odd that For example, if you consider the current parser implementation, these strings are valid.
Some possible solutions:
|
I like the colon solution. I originally had something similar in mind, but I guess I just derped because I didn't consider having separators (and things like Do you have any opinions on behavior if the same color is set twice? We can ignore subsequent settings, set to the last occurrence, or cause the parse to fail (presumably while logging a message). |
How are bright vs normal colors handled? Would it be
This comes back to us not having an elegant solution for handling errors. Ideally, the error would only be logged once after a configuration change is made so that the prompt containing the error doesn't get in the way of the user trying to fix the issue. For the time being, we can simply respect the last occurrence, and eventually transition to error handling, like we have noted elsewhere in the codebase.
Does anyone think that the DSL might be too complicated for advanced style configuration? I think it certainly would be simple for the most common use cases: Another option to allow for clearer control for advanced styling would be to use a nested table for style. [[character]]
symbol = "👋"
[character.style]
foreground = "bold red"
background = "blue" Thoughts? |
Haven't thought that far ahead yet. There's actually not an explicit enum in
Sounds good to me.
Do you mean too complicated in terms of for the user to understand, or for us to implement? I think with the change suggested by @nickwb the syntax becomes pretty simple to explain (whether it stays that way or not is another story) |
Alright, the current language is the following:
We still take the last instance of any color if multiple colors are found in the format string. Examples:
|
I accidentally introduced a bug which I think is useful as a feature: if the color config string is completely invalid, it acts the same way as a blank config (turns off all styling). I think this could be helpful if the user types in an invalid config string: they now know that starship has seen their update to the config, but that something is going wrong (as opposed to going to the default color, where you're not sure if its because starship didn't see the config change or not). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just had a question.
src/config.rs
Outdated
let tokens = style_string.split_whitespace(); | ||
let mut style = ansi_term::Style::new(); | ||
|
||
// Should we color the foreground? If not, assume we color the background. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the sentence here correct? Seems like we default to foreground if no fg:
/bg:
token was found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think this is poorly worded.
The intent was to say that "if col_fg
is false
, then we're coloring the background", as opposed to "if col_fg
is false, don't color anything".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other option I had would have been to introduce an Enum for it, but that felt a little overkill for an either-or decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. It reads much better now.
Could we have an example where the style of a module is explicitly set to nothing? [character]
style = "none" |
@matchai Currently the way to do no styling is to set the style string to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks great! Really looking forward to having this as part of the prompt! 😄
- `"bg:blue fg:bright-green"` sets bright green text on a blue background | ||
- `"bold fg:27"` sets bold text with [ANSI color](https://i.stack.imgur.com/KTSQa.png) 27 | ||
- `"underline bg:#bf5700"` sets underlined text on a burnt orange background | ||
- `""` explicitly disables all styling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on using null
or "none"
here?
- `""` explicitly disables all styling | |
- `null` explicitly disables all styling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put in a new token none
(as well as a new token dimmed
).
- `""` explicitly disables all styling | ||
|
||
Note that what styling looks like will be controlled by your terminal emulator. For example, some terminal emulators will brighten the colors instead of bolding text, and some color themes use the same values for the normal and bright colors. | ||
|
||
## Prompt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be addressed in a separate PR, but we should probably have style configuration under prompt.style
for the prompt elements that aren't part of modules (e.g. prefix, suffix).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do a separate PR. I'll open an issue once this gets merged.
Description
Allows the user to specify styles on a per-module (and potentially even per-section) basis.
This has two main parts: the first is a new config function which can read a string specifier, e.g.
underlined bold green bg:75
and return the appropriateansi_term::Style
object to match that specifier.The second will be integrating this config function in with existing modules.
Motivation and Context
Closes #128 and #208
Types of changes
Screenshots (if appropriate):
How Has This Been Tested?
Checklist: