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

feat: update on file changes #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sbillig
Copy link
Contributor

@sbillig sbillig commented Dec 17, 2024

This adds a file watcher (using the notify crate); when any files have been modified/created/removed/etc in the work directory, we do a screen update and redraw. I found gitu today and have been using it in zed as a magit substitute, and am really liking it so far (thanks!). I thought it would be nice to not have to manually refresh gitu.

The gitignore filter probably isn't necessary; if an ignored file is modified and triggers an extra update/redraw, it doesn't really matter. Or it could be more complete (eg I don't think we're currently filtering out files in .git/ for example). 🤷

Happy to make changes or whatever as you see fit.

Screen.Recording.2024-12-16.at.11.06.15.PM.mov

@altsem
Copy link
Owner

altsem commented Dec 17, 2024

Thats cool! I read through it and think it makes sense.

I haven't tested it myself, or read the code in-depth. (I'm on vacation until February).

Could be a configurable option.

I wonder if it works on windows/mac?

I'd wish for the cursor to remain at the selected line post updates ):, though, that is a separate problem.

@sbillig
Copy link
Contributor Author

sbillig commented Dec 17, 2024

(Rebased onto #293)

@micahscopes
Copy link

Tested this on Linux and it works great! Just need to fix a little glitch that happens when event.paths is empty.

I'd wish for the cursor to remain at the selected line post updates

Looks like the cursor remains at the literal selected line number, which may have different information on it after the update. So I guess at each notify event if you were to calculate how many lines have been added/removed you could jump the cursor by that number of lines in the opposite direction maybe?

@sbillig
Copy link
Contributor Author

sbillig commented Dec 21, 2024

Tested this on Linux and it works great! Just need to fix a little glitch that happens when event.paths is empty.

Whoops, that paths[0] was a silly testing thing I forgot to change. Fixed, thanks!

I'm on a mac and it works here. Can't easily test Windows though. The notify crate works there, so it should work.

Copy link

codecov bot commented Dec 26, 2024

Codecov Report

Attention: Patch coverage is 17.07317% with 34 lines in your changes missing coverage. Please review.

Project coverage is 87.96%. Comparing base (0f02879) to head (7a5380c).

Files with missing lines Patch % Lines
src/file_watcher.rs 0.00% 23 Missing ⚠️
src/lib.rs 0.00% 9 Missing ⚠️
src/state.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #292      +/-   ##
==========================================
- Coverage   88.40%   87.96%   -0.44%     
==========================================
  Files          62       63       +1     
  Lines        5578     5608      +30     
==========================================
+ Hits         4931     4933       +2     
- Misses        647      675      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@altsem
Copy link
Owner

altsem commented Dec 26, 2024

@sbillig what do you think of making it possible to disable this via config? Enabled per default.
Just in case someone has a preference, or is experiencing issues.

There's a module "config.rs" I believe.

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.

3 participants