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
Conditional Newline #607
Comments
You can set prefix and postfix to empty if you don't want a space before and after(by default). |
That did the trick ... I didn't realize the default was a space. Thanks! |
I should note, I attempted to add a |
@sdsalyer in theory, you could add the |
I believe technically this worked, but it rendered the start of the colores powerline block on the first line? I will check again at my work laptop tomorrow. |
Yes, you are right. We can fix that with a diamond segment though by adding the |
You're right and it could work but more generally, there is no possibility to show/hide a segment/block conditionally based on the visibility of another segment/block. This would need a not so small refactoring of the engine. And I don't know if many people asked for a feature like this? |
@lnu this is the first time that has been asked. But I understand the feature. @sdsalyer works with the following config: {
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "root",
"style": "plain",
"background": "#ac0101",
"foreground": "#fce93c",
"properties": {
"root_icon": "[ADMIN]"
}
},
{
"type": "time",
"style": "plain",
"properties": {
"prefix": "",
"time_format": "15:04:05"
}
},
{
"type": "path",
"style": "powerline",
"background": "#91ddff",
"foreground": "#100e23",
"powerline_symbol": "",
"properties": {
"folder_icon": "",
"folder_separator_icon": " ",
"style": "agnoster_short"
}
}
]
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "git",
"style": "diamond",
"leading_diamond": "\n<transparent,#95ffa4>\uE0B0</>",
"trailing_diamond": "\uE0B0",
"foreground": "#193549",
"background": "#95ffa4"
}
]
},
{
"type": "newline"
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"foreground": "#007ACC",
"properties": {
"prefix": "",
"text": "PS❯"
},
"style": "plain",
"type": "text"
}
]
}
],
"final_space": false
} |
@JanDeDobbeleer Works like a charm -- thanks so much! Feel free to close this issue unless you think it is a relevant feature add to make blocks conditional. Thanks again for your help. |
Hey I found this issue because I wanted to do the same but the solution only works for left alignment because \n will always move the cursor to the left obviously. I think a real conditional statement for the newline would be good. Or is there another way to achieve the same but with right alignment? |
@Linard11 hmm, not without in depth knowledge of ANSI. Let's do it. |
To not have over-complicated statements that link a newline blocks to specific segments in other blocks. Maybe the easiest approach would be to have a single bool option (e.g. hide_if_empty) on the newline type that looks ahead into the next block and if none of the segments would be rendered the newline isn't either. |
@Linard11 I would opt to remove the previous newline (if present) if the current block is empty. Not sure of the side-effects here so I need to test that a bit. |
@Linard11 I gave this a bit of thought and what we can do is the following:
If I'm not mistaken, that can render the newline block obsolete and we have everything we need. |
Sounds like a good solution 👍 |
this deprecates the "newline" block and favours using the newline property on the Block component. For backwards compatibility we'll keep recognizing the newline block for the time being. resolves #607
this deprecates the "newline" block and favours using the newline property on the Block component. For backwards compatibility we'll keep recognizing the newline block for the time being. resolves #607
this deprecates the "newline" block and favours using the newline property on the Block component. For backwards compatibility we'll keep recognizing the newline block for the time being. resolves #607
this deprecates the "newline" block and favours using the newline property on the Block component. For backwards compatibility we'll keep recognizing the newline block for the time being. resolves #607
this deprecates the "newline" block and favours using the newline property on the Block component. For backwards compatibility we'll keep recognizing the newline block for the time being. resolves #607
This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. |
Prerequisites
CONTRIBUTING
guideDescription
Is it possible to set a conditional newline? For example, if I'm in a directory under Git version control, display the git / poshgit info on the next line. Otherwise, don't display the extra (blank) line.
Environment
Steps to Reproduce
n/a
Expected behavior: [What you expected to happen]
Actual behavior: [What actually happened]
Theme file:
The text was updated successfully, but these errors were encountered: