Closed icio closed 1 year ago
@icio IMHO this is not a bug but a feature request.
I don't see what could be causing this as we hook into the prompt functions and not really much else. I'll have a look at if it's possible to support this but no guarantees.
@icio I found what's causing this. We get the cursor position before printing the prompt and that's what's somehow swallowing this. The weird thing is that this is executed before the command is executed, not after. There's no other way to do this so we might need to make this explicit rather than implicit. Which is a pity actually.
I've tested 14.2.1 but I'm not seeing any change in behaviour. I've attached my config.
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "black",
"type": "text",
"style": "plain",
"template": "# "
},
{
"foreground": "white",
"style": "plain",
"template": "root in ",
"type": "root"
},
{
"foreground": "red",
"properties": {
"style": "folder"
},
"style": "plain",
"template": "{{ .Path }} ",
"type": "path"
},
{
"foreground": "#D19A66",
"properties": {
"fetch_status": true
},
"style": "plain",
"template": "<white>on</> {{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }} ",
"type": "git"
},
{
"foreground": "blue",
"properties": {
"fetch_version": true
},
"style": "plain",
"template": "<white>with</> \ue781 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} ",
"type": "node"
},
{
"foreground": "blue",
"properties": {
"fetch_version": true
},
"style": "plain",
"template": "<white>with</> \ue627 {{ .Full }} ",
"type": "go"
},
{
"foreground": "lightRed",
"style": "plain",
"template": "<b>x</b> ",
"type": "exit"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "black",
"style": "plain",
"template": "$ ",
"type": "text"
}
],
"type": "prompt"
}
],
"version": 2
}
If I oh-my-posh init zsh > omp.zsh
then comment-out the _set_posh_cursor_position
call, everything works as expected. So something in that function is trapping the input. The read
call looks a likely candidate, but I'm afraid I don't know enough about what's happening around stty
//dev/tty
stuff.
For the mean-time I'm just going to keep it commented out.
@icio ah yes, because you have an initial newline. That's when we do this. Removing that will solve that for you. For now that's by design until bash/zsh can provide direct access to the cursor position.
Are you sure it's needed just because there's a newline? I've not noticed anything breaking while I've disabled this function call.
@icio the only feature this enables is that it does not add a newline when the user clears the terminal. That's the most bulletproof way to identify if we're at the top of the terminal. For fish and nu we check the last command, but that's brittle.
Ah, gotcha! Yes, you're right. When I clear the terminal now I do get an empty newline at the top. A small price to pay to avoid accidentally running "it status" all the time :sweat_smile:
@icio I can also fallback here to the history, but then it won't ever be perfect as shortcuts and aliae can break this. I'll give this a thought.
Could we hook into zle clear-screen
here to track a flag of when to omit the newline? For example:
clear-screen() { echoti clear; POSH_NO_NEWLINE=0; zle redisplay; }
zle -N clear-screen
Then in precmd we can omit the newline of POST_NO_NEWLINE!=1 then sets it to 1.
@icio that could work, I was looking for this earlier today but didn't come across this one. I'll have a look!
Just ran into this problem again on a fresh install (but this time on bash), and was surprised to find my own issue from last time!
IMHO this is not a bug but a feature request.
This bit made me laugh.
This time around I've removed "newline": true
from the config and just put a "\n"
at the start of the first template.
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. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.
Code of Conduct
What happened?
Typically you can type while a command in your shell is executing and, upon that command's completion, the things you typed will prefill the next prompt. Not so with oh-my-posh. For example, with oh-my-posh I can run
sleep
, hit enter, then type anecho
command before the "done" output and the stuff I typed in never reappears:whereas without oh-my-posh:
--no-rcs
ignores everything in .zshrc, but I've double-checked that commenting-out onlyoh-my-posh init
resolves the problem.Theme
n/a
What OS are you seeing the problem on?
Linux
Which shell are you using?
zsh
Log output