-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Module configuration with format strings #624
Comments
I think this is much better than the current method |
@matchai I think that this is a splendid idea, and that it simplifies the configuration file significantly (and possibly the code as well 🤞). As you said, this removes the hassle of configurable prefixes/suffixes of modules, which are inconsistent for each module at the moment. IMO, I think that this will be a good thing to implement before we go stable, and I'm more than willing to help implement this feature. Also, this is related in part to #346. |
@matchai What about the styles? One option that I initially came about is to use something similar to the escaping sequence, e.g. But I think adding parameters like |
@heyrict I really like the second one |
What about using an array? It will be easier to parse (and we can pass arguments other than string to modules). Also, using this syntax allows us to add the same module multiple times with different config, which is useful if we want to display multiple environment variables. [[modules]]
name = "character"
config = {
symbol = "❯",
error_symbol = "✖",
}
segments = [
{ name = "prompt_symbol", style = "bold red" },
{ name = "text", value = " " },
] I think json format may look better if we have highly nested tables. {
"modules": [
{
"name": "character",
"config": {
"symbol": "❯",
"error_symbol": "✖"
},
"segments": [
// Add a `>` symbol if $HOSTNAME == home, related to #607
{
"name": "match",
"matches": [
{
"env": "HOSTNAME",
"eq": "home",
"display": {
"name": "text",
"value": ">",
"style": "bold green"
}
}
]
},
// Add segment `prompt_symbol`
{ "name": "prompt_symbol", "style": "bold red" },
{
"name": "text",
"value": " "
}
]
}
]
} |
@heyrict Although I think that that is an ingenious solution, it doesn't seem to make the configuration file any simpler, which was one of the goals of this discussion. |
I've skimmed through crates.io and didn't find a crate that meets the need of #624 (comment). So I made a runtime string formatter at https://github.com/heyrict/spongy as a PoC. Feel free to ping me if you found some existing crates that can do the trick. |
Quick update: I've rewritten Note: I'll be busy before Jan 10. Feel free to continue working on this branch if you would like to. |
@heyrict Sorry I didn't get around to answering #624 (comment), which I think is a discussion we need to have before #682 can go through. I personally find the Giving it a little more thought, I think something along these lines might be a little easier to make sense of: # Previous:
"via ${styled?value=⬢ &style=green bold}${version?style=green bold} "
# Alternative:
"via [⬢ $version](green bold) " The above is inspired by Markdown syntax. I'm not attached to Anything prefixed with an unescaped What are your thoughts? |
@matchai I'm not opposed to We may want:
if we are in a condition that
This cannot be done with merely As for me, anything that can be parsed as a See Also: Limitation section in #682 |
Hi, I was thinking about a possible solution that mixes together both the solution of @heyrict and @matchai. The idea is to divide the formatting configuration of the prompt from the logical configuration. Thus, create a
As shown in the example, each module can have a
Sorry for the very long comment, I hope that I was clear and that the proposal was pertinent. |
@heyrict I have PowerLine working well enough for my needs, see #528 (comment) and this commit https://github.com/lzybkr/starship/commit/3e02f172adcf5cf84022fd14b10c52285a4bde6e I've avoided a PR because in my mind, the proposed changes here would simplify PowerLine styling even more. |
Unfortunately I don't think it's worth this much complexity for the Powerline use-case. We could get around to adding advanced configuration for this in particular, but >90% of users will only be working with basic configuration. There is certainly room is extend the syntax to support advanced configuration, but I think that's a discussion for another time. |
What I mean by powerline syntax is that, users may want a full control over the command prompt. I agree that most user will be working with the basic configuration, but requests do exist for more customization. Other issues that I personally would like to solve by a Map is to have multiple modules (esp. env_var) with different parameters, see #664
Well, I would rather get it discussed before we've gone too far. There are feature request of all kind. I would like to know what we want to cover and what not, as any refactor is costly and it would be painful to have two if we can get things done with one. |
I'm hesitant to support maps when something similar can perhaps be achieved with TOML configuration. [env_var]
format = "[$session](red) [$shell](blue)"
[env_var.session]
variable = "SESSION"
[env_var.shell]
variable = "SHELL" I think there would be a more elegant way to use maps in TOML than to have another map added within configuration. At the end of the day, I'd rather have simple configuration than more extensibility. |
@chipbuster I figured you might have some thoughts to share, if you haven't had the chance to see this issue yet. 😊 |
@matchai Funnily enough, I had just been reading over this and another issue/PR when you tagged me (then I had to travel and clean up a bunch of stuff, so I'm a little delayed in responding). @heyrict I looked over your benchmark on #682. Was that 30% increase just for two modules with custom format strings? If so, the cost of the current format may be intolerably high. On a slow computer, the default prompt can take 50-100ms to render without too many external calls--and if the cost of custom format strings increases per-string, then using too many format strings might push prompt render time well above 200ms, which is too slow. |
@chipbuster Thanks for your review. I haven't figured out which part of the code is responsible for the increment to the render time, but it seems that no matter how many modules there are, the render time is always increased by ~30% on my laptop. |
@heyrict Thanks, that solve some concerns, but makes this more mysterious. I'll see if I have some time this weekend to rip out the old I'd want to be careful about going too complex on the scripting language here: I think one of our biggest advantages over other shell prompts is ease of understanding the configuration, and it would be problematic if we lost both that and our relative speed (compared to say, the default omzsh prompts) in order to gain a configurability advantage. I don't think we'll ever be able to match actual shell-based prompts for configurability, simply because we're an external binary interfacing with the shell at very fixed points while shell-based prompts write in the actual language of the shell. Of course, if we can get the ability to do powerline without sacrificing too much in terms of simplicity/speed, we should go for it. I guess we'll see what the profiler turns up. |
@heyrict It took me a while to poke around here, because the code structure is drastically different between the format-string branch and its common ancestor with the main branch (which One thing that jumped out at me was that a huge amount of time (71%) in the base version of the code is spent in a child of My best guess here is that you accidentally stripped out the parallelism in If I replace the call to Could you try either disabling parallelism on the base commit or re-enabling it on your branch and re-running your benchmarks? |
I'd like this feature a bunch because it'd give me more freedom. I've spent more time than I'd like to admit playing with prefix & suffix and how not every module has the first, the second, or sometimes misses both. On my old home made version of spaceship my path prompt looked like so: Not really related but in the same vein of freedom: I'd also like the ability to provide arbitrary functions or something to run. With my other prompt my path was similar to the fish style one provided by starship now but it's length was variable depending on the uniqueness of the path rather than a strict length. |
I think the styles would be much better if specified with an xml-like syntax (e.g. |
I'm going to ping @chipbuster and @matchai here if you have any thoughts after two months :) I'm pretty fine with #624 (comment) if you think there is no need to adds more functions to format strings. |
I think that would be best for the time being. 👍 I'd be open to eventually adding an additional "advanced" configuration style once we finish with the "simple" configuration implementation. That's certainly worth opening a separate issue to track and discuss. |
This PR implements the parser of format strings described in #624.
In reply to @matchai comment on advanced configuration:
You're right in regards to the majority of users not having much interest in configuration of tools by themself, but – IMHO – they would use a theme to get a specific visual representation they prefer, if said theme(s) are available. In regards to enabling a Powerline style of the Starship prompt, I believe there is more to todo than just an advanced configuration. In order to have prompts like this (I included the default and current theming options for reference): Therefore either the modules have to be self-aware which module was active before them or you need to check the active modules and insert the separator in between. If I was just stating the obvious, please excuse my intrusion. I personally would really like the possibility to use a Powerline theme for Starship, as I consider it the best prompt by far (information and configuration wise, just not visually, ATM 😉)! |
I have just attempted to implement a 2nd variable for the dotnet module to support showing the TFM the current project is building against. The problem I ran into was with format strings there isn't an easy way to define a prefix for the 2nd variable that has its visibility linked to that variable. I thought that was how the TextGroup would would work but realized that it was just for text formatting. Is there a preferred way to handle this? Does it need a separate variable for that prefix? |
@andymac4182 IMO, you can either use an extra format string like this and then make it renders conditionally programmatically. [some_module]
format = "via $version$branch"
branch_format = "@$branch" Or allow users to define their own variables. [some_module]
format = "via $version$custom"
[some_module.variables]
custom = "@$branch" , and then display the custom variables only when all variables are not We may need some best practices to follow. |
Since the format parser landed in 0.40 I wanted to port the kubernetes module to use format strings. But I did run into the following issue: Hence my questions:
I am looking forwards to reading your opinions / answers. |
@stku1985, that sounds like the same issue I raised in #1116 (comment). |
Since we are getting close to the v0.45.0 release, I'm going to close this issue so we can see what is actually left to do in the milestone and what still needs a little bit of work. |
This PR implements the parser of format strings described in starship#624.
@mickimnet |
@vladimir-lu, thank you, I saw your PR, and I am looking forward to it. |
With more and more configuration being introduced into Starship, we're starting to see a fair bit of configuration bloat that simply modifies the formatting of the output, rather than changing the way the prompt retrieves information or processes context. (e.g. #603, #623)
What I would like to propose is the following configuration:
This would allow us to remove all the following configuration options in modules where they are static:
symbol
prefix
suffix
In modules where the values are dynamic, they would remain. For example, the
character
module:We could also remove the following configuration options from
git_status
, where enabling them would be implicit by them being in the format string:conflicted_count
untracked_count
modified_count
This would, of course, require some changes in the way we educate users, but I think it would make for a less dense and complicated configuration system in the long run.
The text was updated successfully, but these errors were encountered: