Skip to content
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

Multiline commit message #114

Merged
merged 1 commit into from
Jun 25, 2020

Conversation

jonstodle
Copy link
Contributor

@jonstodle jonstodle commented Jun 9, 2020

This intends to implement a way to enter multi-line commit messages. Ref #46

This adds support for opening a file in an external editor, writing the commit message and saving it to the file, and the use the entered message as the commit message. This works in much the same way git does by default.

This PR at, in it's current state is not ready for merging. There are a few issues which will need to be resolved first and I hope to get some feedback on how to solve these. They are as follows:

gitui will capture key stroke events and prevent them from being passed on to the editor

This is only an issue when the editor is opened inside the terminal (such as vim), and not as an external GUI application (such as VS Code).

The background thread spawned by gitui will continue to run and capture key strokes while the external editor is in use. I see mainly three ways of solving this:

  1. Add a way to make the background thread skip polling. This is how it's currently solved, but it's not working completely. When launching the editor, the "poller" will run another time, poll for 2 seconds and then stop polling for as long as the editor is open. If you type inside of those 2 first seconds, the key stroke is going to be captured by gitui and will not be passed on to the editor.
  2. Lower the polling duration from 2 seconds. It's not desirable, but it could work.
  3. Add a way to kill the spawned thread when launching the editor and then spawning it again once the editor exits.

gitui needs to redraw everything when returning from editor

Because both gitui and vim uses the alternative screen feature, gitui will need to redraw it's whole UI when returning from the editor as the incremental updates tui usually does means some parts of the UI never gets set to it's correct state. If a part of gitui never changes, the "regular" shell underneath will "show through".

It seems the only way to make tui redraw the whole screen is to both clear the current screen, but also reset the stored previous buffer. Resetting all the stored buffers is something tui doesn't allow consumers to do (as far as I can see), except for one instance: resize. This function will reset all the internal buffers and force a redraw of the whole screen. resize is currently used to enforce a redraw. (Might be worth considering opening an issue upstream to enable forcing a complete redraw of the UI).

A big downside with current implementation of this is that it introduces a mutable static variable, which means it also introduces unsafe (the forbid unsafe directive has been commented out). This might be worked around by using lazy_static, but I haven't investigated that in any way.

The reason for the mutable static is the introduction of a new channel, global to the app, which let's different parts of the app send command requests to the main loop. In this case it's a request for a full redraw of the UI, but this could be useful for other commands later (but with a better implementation of how to share the sender).


This PR is not based on a very recent commit because master would not build on stable for me, so I kept it at 0.5.0-ish. I will rebase it at a later point.

extrawurst pushed a commit that referenced this pull request Jun 22, 2020
@extrawurst extrawurst added this to the v0.8 milestone Jun 23, 2020
Adds support for editing commit messages in an external editor. It read the GIT_EDITOR, VISUAL, EDITOR environment variables in turn (in the same order git does natively) and tries to launch the specified editor. If no editor is found, it falls back to "vi" (same as git). If vi is not available, it will fail with a message.
@jonstodle
Copy link
Contributor Author

The summary of this PR pretty much boils down to the commit message of the commit:

Adds support for editing commit messages in an external editor. It read the GIT_EDITOR, VISUAL, EDITOR environment variables in turn (in the same order git does natively) and tries to launch the specified editor. If no editor is found, it falls back to "vi" (same as git). If vi is not available, it will fail with a message.

@extrawurst extrawurst merged commit 477fdd3 into extrawurst:master Jun 25, 2020
@extrawurst
Copy link
Owner

wooohhooooooo!! Thank you @jonstodle 🙏

@extrawurst
Copy link
Owner

closes #46

jonstodle added a commit to jonstodle/gitui that referenced this pull request Jul 6, 2020
Pressing `e` while looking at a file in the _Status_ view will launch an external editor with the current file opened. The editor chosen is determined by the default logic introduced in extrawurst#114.

An improvement to this in the future could be launching at the specific line at which the _Diff_ view is focused, but that seems to require a change in `FileDiff` which is a change bigger than this PR.

Fixes extrawurst#166
jonstodle added a commit to jonstodle/gitui that referenced this pull request Jul 6, 2020
Pressing `e` while looking at a file in the _Status_ view will launch an external editor with the current file opened. The editor chosen is determined by the default logic introduced in extrawurst#114.

An improvement to this in the future could be launching at the specific line at which the _Diff_ view is focused, but that seems to require a change in `FileDiff` which is a change bigger than this PR.

Fixes extrawurst#166
extrawurst pushed a commit that referenced this pull request Jul 7, 2020
Pressing `e` while looking at a file in the _Status_ view will launch an external editor with the current file opened. The editor chosen is determined by the default logic introduced in #114.

An improvement to this in the future could be launching at the specific line at which the _Diff_ view is focused, but that seems to require a change in `FileDiff` which is a change bigger than this PR.

Fixes #166
@jonstodle jonstodle deleted the multiline-commit-message branch July 27, 2020 17:50
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

Successfully merging this pull request may close these issues.

2 participants