Skip to content

Blocking echo messages on startup result in blank screen #1573

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

Open
1 of 7 tasks
ilyagr opened this issue Apr 1, 2025 · 6 comments
Open
1 of 7 tasks

Blocking echo messages on startup result in blank screen #1573

ilyagr opened this issue Apr 1, 2025 · 6 comments

Comments

@ilyagr
Copy link
Contributor

ilyagr commented Apr 1, 2025

Steps to reproduce

With the latest prerelease, I run the following command (from a draft default diff tool config similar to jj-vcs/jj#6205, sorry for extraneous quotes):

Update: I changed this line to remove irrelevant backticks. They mess up the result in bash or zsh; I didn't notice because I use fish.

"gvim" "-f" "-d" "-u" "/dev/null" mkdocs-offline.yml mkdocs.yml "-c" "echohl WarningMsg" "-c" "echomsg \"Warning: using plain vimdiff as a diff editor is not recommended. See https://github.com/jj-vcs/jj/wiki/Vim for alternatives.\"" "-c" "echohl None"

(It doesn't matter which two files you'd be comparing, or if they even exist)

This results in a confusing blank screen instead of the expected message:

Image

After pressing Enter, everything works.

Image

Expected behaviour

In plain vim, I get:

"mkdocs-offline.yml" 19 lines, 724 bytes
"mkdocs.yml" 154 lines, 4992 bytes
Warning: using plain `vimdiff` as a diff editor is not recommended. See https://github.com/jj-vcs/jj/wiki/Vim for alternatives.
Press ENTER or type command to continue

Then, vim loads after I press ENTER.

Version of Vim and architecture

1-1251

Environment

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Mar 28 2025 09:26:05)
macOS version - arm64
Included patches: 1-1251
Compiled by GitHub Actions

How MacVim was installed

Downloaded from GitHub

Logs and stack traces

Vim configuration where issue is reproducable

No response

Issue has been tested with given configuration

  • by running MacVim.app from GUI macOS interface
  • by running vim/gvim/etc installed by MacVim
  • by running other versions of vim (e.g. /usr/bin/vim)

Issue has been tested with no configuration

  • by running mvim --clean (or gvim, supplied by MacVim distribution)
  • by running vim --clean (in terminal, supplied by MacVim distribution)
  • by running vim --clean (in terminal, other suppliers, e.g. /usr/bin/vim)

Other conditions

  • The both Homebrew packages "vim" and "macvim" are installed
@ychin
Copy link
Member

ychin commented Apr 2, 2025

Let me take a look, but I think this is a bad interaction with the "Press Enter" mode in Vim and some recent resize changes in MacVim. Basically Vim's "Press Enter" mode is quite fragile in that if you resize the window, it will clear all the rendering instead of redrawing itself. This issue occurs when Vim is used in a terminal as well but MacVim may have triggered a resize event which caused this to happen.

Have you noticed this issue before (e.g. in r181) the current pre-release build (r181.1)? It would be nice to know when you have noticed that.

But as you noticed it's mostly a rendering / redraw issue in Vim and pressing enter will indeed fix the issue.

@ilyagr
Copy link
Contributor Author

ilyagr commented Apr 2, 2025

As of now, I haven't tried any other versions.

@ilyagr
Copy link
Contributor Author

ilyagr commented Apr 2, 2025

I tried using :echowin instead of :echomsg in that command line, but that didn't work with MacVim at all. I was going to ask if I should use it instead (e.g. if it has been around for long enough), but I guess not.

It might be the same issue with resizing, since after MacVim launches, manually using :echowin in it works, but the message gets cut off a bit.

@ychin
Copy link
Member

ychin commented Apr 2, 2025

echowin works. As you said it works if you type it manually. Either way it's not really the expected way to show an error message at launch so it's not going to be a good option regardless. (Edit: Actually I tried it and it seemed to work fine. What is the actual issue?)

Also, running your command seems to trigger some serious warning. Did you look at the terminal output and look at what it's saying? You are wrapping "vimdiff" as `vimdiff` and that's going to run vimdiff due to how most shells work and make everything unhappy. It's not like most terminal emulators understands markdown. Also, is there a reason why you are using -u /dev/null instead of -u NONE?

@ychin
Copy link
Member

ychin commented Apr 2, 2025

I think the issue here is multi-fold. You are using -u /dev/null which is equivalent to -u NONE which forces a press-enter prompt when using vimdiff (even without your messages) (see point (1) below), and it also enables scroll bars which causes a resize. The resize clips the press-enter prompt.

There are multiple things you could do here:

  1. Don't use -u NONE. At least use -u DEFAULTS which has better behavior on start when using diff mode (just try both without your message commands and you will see what I mean). I think this is due to different shortmess settings. Alternatively, just respect user defaults and don't force it to something else.
  2. You could use echowin after doing (1) above.
  3. You could use :echomsg like before but set a timer of 0 seconds using timer_start so that the new message doesn't literally get called immediately and interfere with Vim's own output of the file being edited and resize.
  4. Play around with messageopt to avoid hit-enter. That said this may have the issue of stomping user defaults.
  5. You can also disable scroll bars to prevent the resize trigger which like above does have the issue of stomping user defaults.

I do want to fix Vim's Press Enter prompt to be more safe to terminal resizing but I think there are other things you could do in the meantime.

Btw, seems like the issue here is that jj defaults to vimdiff, but then you want it to warn when vimdiff is used as-is because it does not do folder diff? That seems like a mediocre default behavior to me, as defaults should work instead of throwing up an annoying error message. If vimdiff doesn't work at all, it should just not be allowed to launch with jj explaining why. If it works, then having this error message every time a user wants to use it is going to get old real fast. This "kind of works but I'll annoy the hell out of you" seems like half measures to me. Even if there are warning messages I think it's better to show them before Vim is launched to have a consistent way to do this. Once Vim is launched you should just let it do its thing and the user may have all sorts of weird configurations that you are not aware of that may interfere with your message injection. I don't use it though so it's up to you.

@ilyagr
Copy link
Contributor Author

ilyagr commented Apr 2, 2025

You are using -u /dev/null which is equivalent to -u NONE which forces a press-enter prompt when using vimdiff (even without your messages)

This was just to make sure my config doesn't affect the reproduction. I also tried --clean when I saw it recommended in the issue template.

The actual config doesn't have that option, and I get all the same problems.

If you want to play around with jj, here's what I was trying. edit-args is the important option.

[merge-tools.gvimdiff]
program = "gvim"
# `-d` enables diff mode. `-f` makes vim run in foreground even if it starts a GUI.
# The other options make sure that only the output file can be modified.
merge-args = ["-f", "-d", "$output", "-M", "$left", "$base", "$right",
              "-c", "wincmd J", "-c", "set modifiable", "-c", "set write",
              "-c", "/<<<<<</+2"]
merge-tool-edits-conflict-markers = true
# Directory diffing is barely usable in vimdiff without additional plugins
edit-args = [
    "-f", "-d", "$left", "$right", "-c", "echohl WarningMsg", "-c",
    # Or echomsg
    'echowin "Warning: using plain `vimdiff` as a diff editor is not recommended. See https://github.com/jj-vcs/jj/wiki/Vim for alternatives."',
    "-c", "echohl None",
]
diff-invocation-mode="file-by-file"
diff-args = ["-f", "-d", "$left", "$right"]

I haven't yet read your other thoughts (thank you!), but wanted to clarify this point quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants