altsem / gitu

A TUI Git client inspired by Magit
MIT License
1.78k stars 92 forks source link

Vim hangs when opening from gitu on Windows #186

Open McPhale opened 4 months ago

McPhale commented 4 months ago

When opening vim from gitu (when committing, for instance) on windows, the editor does not respond to keystrokes. The graphical version of vim seems to work just fine. Not sure if this is a gitu issue or not, but vim works fine in other scenarios. I've tried setting the editor variable in both git config and the system environment variables to see if that makes a difference, and have tried removing my vimrc to see if there was a problem there, but it didn't change the behavior. The issue also appears in both cmd and windows terminal running powershell core. The editor variable is set to "C:/Tools/Vim/vim91/vim.exe".

Any thoughts?

Thanks for the very cool utility!

altsem commented 4 months ago

Hi! Was just a matter of time before this would happen I feel, the implementation is not ideal.

It seems that Gitu is unable to realize we're actually opening Vim due to the .exe at the end. Defaulting to the file/line format: vim file.txt:120 instead of vim +120 file.txt.

If you try opening a file like vim file.txt:120, does it also hang?

Got the idea of checking the output of vim --version (or whichever editor is configured) instead of the path, which might be more reliable. But I wonder if there's an even better way.

The existing code is found here: https://github.com/altsem/gitu/blob/9d9ea52ee85fdf66e6e49eef2010f07da4ef25b2/src/ops/show.rs#L67-L103

Happy you like it! :)

altsem commented 4 months ago

@McPhale I potentially fixed this in #189. Just needs some testing.

McPhale commented 4 months ago

Cool! If I have some extra free time this week I can test it out, thanks for taking a look

McPhale commented 3 months ago

Ok, I managed to get a debugger set up and stepped through the code in the new branch. It doesn't look like the changes you made in show.rs are ever getting hit; with the editor set to vim, it gets as far as the function "run_cmd_interactive" in state.rs, where it hangs as as soon as vim spawns. I tried setting it to nano, and while it works fine from the shell it spits out an error code when gitu tries to open it. Sorry I don't know the first thing about rust, I'm not sure how helpful this is! (I took a screen capture of this but it's too large to upload. If you think that would be helpful I can zip it up or something).

altsem commented 3 months ago

Interesting! I'm not sure what's going on.

Else I'd double-check the environment variables: GIT_EDITOR, VISUAL, EDITOR. These (in this order) dictate which editor to launch.

Screenshot would be helpful, or (if it's just text), I guess you could copy-paste it?

And some notes for myself/others that happen to read this: It does open the process (vim/nano) and then pipes all input/output from Gitu to it. Perhaps there's a better way for Gitu spawn and handle the process?

McPhale commented 3 months ago

Hello; had an issue with my machine and had to get a new one and set it all up, so I'm just now looking at this again. Here is my environment variable:

image

altsem commented 3 months ago

I tried setting it to nano, and while it works fine from the shell it spits out an error code when gitu tries to open it. Sorry I don't know the first thing about rust, I'm not sure how helpful this is! (I took a screen capture of this but it's too large to upload.

I mean the error :) Do you have the error code that you saw?

McPhale commented 2 months ago

Oh, right, sorry! It just comes back with "! exited with code: 1". Potentially related to this newer issue? https://github.com/altsem/gitu/issues/215

Edit: Vim actually briefly complains when it hangs with a similar message that I just noticed: "Warning: Input is not from a terminal".