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

Avoid refreshing previews for shell pipe commands #1281

Merged
merged 1 commit into from
Jun 4, 2023
Merged

Avoid refreshing previews for shell pipe commands #1281

merged 1 commit into from
Jun 4, 2023

Conversation

joelim-work
Copy link
Collaborator

@joelim-work joelim-work commented Jun 3, 2023

Follow up of #1164

Like shell-async commands, shell-pipe commands are run in the background and can take some time to complete, so there is no point refreshing the preview immediately. When the shell-pipe command finishes, it internally sends a load command, so that should be sufficient.

For shell and shell-wait commands, the loading is handled in the runCmdSync function, see #1243 for details.


I did notice that % triggers the load command afterwards but & doesn't, I'm not sure if there's a reason for this though, but I think it can be addressed separately outside of this PR.

@ilyagr
Copy link
Collaborator

ilyagr commented Jun 3, 2023

I think this is a good idea and it seems safe. In fact, I was considering doing this in #1243. I'm not quite sure if there was some weird bug those two lines fixed, though.

I was also considering adding some form of refresh when the command stops executing, in the two go func()-s below that line. Again, I'm not sure whether that can cause some subtle bug (e.g. an infinite loop).

I'll keep thinking about it, but it's also possible that at this point you and @gokcehan might be better experts on subtleties of changing such behavior than I am.

@joelim-work
Copy link
Collaborator Author

I think this is a good idea and it seems safe. In fact, I was considering doing this in #1243. I'm not quite sure if there was some weird bug those two lines fixed, though.

Looking back at the original code, I'm quite sure app.ui.loadFile was used just for refreshing the preview after a $ or ! command finishes and for & and % commands it would be a no-op since they would still be running in the background. The problem is that app.ui.loadFile actually has the side effect of running the cleaner and previewer` script (noticiable for image previews).

I was also considering adding some form of refresh when the command stops executing, in the two go func()-s below that line. Again, I'm not sure whether that can cause some subtle bug (e.g. an infinite loop).

I did notice that % triggers the load command afterwards but & doesn't, I'm not sure if there's a reason for this though, but I think it can be addressed separately outside of this PR.

@ilyagr
Copy link
Collaborator

ilyagr commented Jun 4, 2023

I think you are likely correct. I went spelunking through the blame, and the code seems to originate in 52fbe46.

I think that, unless @gokcehan sees a reason not to, we can merge this and see if any bugs appear (which is, hopefully, unlikely).

The problem is that app.ui.loadFile actually has the side effect of running the cleaner and previewer` script (noticiable for image previews).

I'd put a sentence about this in the PR description, perhaps with a link to #414 (comment).

I did notice that % triggers the load command afterwards but & doesn't, I'm not sure if there's a reason for this though, but I think it can be addressed separately outside of this PR.

👍

I also realized we already talked about this in #1164 (comment)

@joelim-work
Copy link
Collaborator Author

I also realized we already talked about this in #1164 (comment)

BTW I did some quick testing, adding a load call at the end of a & command (similar to %) actually reintroduces the bug in #414 (comment), at least on my setup. The reason is that image previews are always volatile (they cannot be cached inside lf and the cleaner/previewer scripts need to run every time to display the image preview), and load will trigger this, causing the image to flash.

This is also why the period timer performs a non-volatile load, otherwise image previews would constantly be flashing, see #546:

lf/app.go

Lines 467 to 470 in a9d90bc

case <-app.ticker.C:
app.nav.renew()
app.ui.loadFile(app, false)
app.ui.draw(app.nav)

If you can make the load command accept some kind of nonvolatile argument and pass it to app.ui.loadFile then that should work.

@gokcehan
Copy link
Owner

gokcehan commented Jun 4, 2023

@ilyagr I don't remember anything specific about this behavior. Let's merge it and see how it goes.

@joelim-work Thanks for the patch.

@gokcehan gokcehan merged commit 027538e into gokcehan:master Jun 4, 2023
@joelim-work joelim-work deleted the avoid-refresh-async branch June 4, 2023 23:19
@gokcehan gokcehan mentioned this pull request Sep 17, 2023
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