IlanCosman / tide

🌊 The ultimate Fish prompt.
MIT License
2.74k stars 103 forks source link

Add newline before prompt only when previous output exists #327

Open mtardy opened 1 year ago

mtardy commented 1 year ago

First of all thanks for creating tide, I just tried fish and it's amazing to have a p10k equivalent for fish. This bug is just a minor annoyance but I don't know how to resolve it by myself :(!

Describe the bug

I stole the description here because this is the exact same problem.

However, the newline is also printed when there is no previous output, e.g. after clearing the terminal with printf "\033c" (or when the terminal is first opened):

                           <--- bad newline: no previous output
➜ /some/dir            
❯ command1            
output...             
                           <--- good newline
➜ /some/dir          
❯ command2         

Steps to reproduce

Use tide configure and use prompt spacing (2) Sparse to see the issue.

Screenshots

This is what happens with tide and fish:

image

This is what happens with powerlevel10k and zsh:

image

Even the configuration wizard of tide advertises the behavior intended and not the reality:

image

Environment

fish version: 3.5.1
tide version: 5.4.0
term: xterm-256color
os: macOS Monterey 12.5
terminal emulator: iTerm
fish startup: 11.29 millis
fisher plugins: jorgebucaran/fisher ilancosman/tide@v5

Additional context

I guess what we see is happening here for double line prompt and here for simple line prompt but I don't know how we can detect reliably we just started the interactive shell session or not.

IlanCosman commented 1 year ago

Yah it'd be nice, I'll try.

mtardy commented 1 year ago

Thanks a lot! Yes considering the title change (that was reverted so I think you already understand), just to be super clear, it is not only when a new session is created, but also when clearing the terminal with clear or CTRL+L (\033c).

I tried to look at how p10k did it but the syntax was too hardcore for a shell newbie like me.

heyarne commented 4 months ago

i'd love to see that as well! it took me a bit until i realized that the empty first line in the prompt was caused by the "sparse" setting. any idea what exactly would need to be changed in #419 to make this work?

EDIT: Managed to hack it together by chosing the "compact" prompt and adding these lines to my ~/.config/fish/config.fish. The example is given in the stackoverflow answer, and this also works with Ctrl + L.

status --is-interactive; and begin
    # this fixes the "sparse" layout of the tide prompt
    function postexec_newline --on-event fish_postexec
        echo
    end
end

EDIT 2: This is a slightly improved version, I think, because the previous version would sometimes print the empty line too early for me. To be clear, I configured tide to use the compact layout and added this bit of code and all is working well so far:

status --is-interactive; and begin
  # this fixes the "sparse" layout of the tide prompt
  set first_line true
  function sparse_prompt --on-event fish_prompt
    if test "$first_line" = true
      set first_line false
      return
    end

    # print newline for sparse layout
    echo
  end
end