glow icon indicating copy to clipboard operation
glow copied to clipboard

Feature/poll active file for change

Open deicon opened this issue 3 years ago • 13 comments

Allow automatic refresh from currently rendered and displayed local file.

New Flags

--watch, -f Enable File Watching (Defaults false) --interval, -i Interval in seconds to poll for file updates

This would fix #426 and is related to #416

deicon avatar Dec 07 '22 12:12 deicon

Works like a charm 😍 what's the status on merging this into master?

gibbz00 avatar Mar 15 '23 10:03 gibbz00

I tried to fix a few bugs and added some enhancements to various charm projects. Unfortunately the response time once a PR is opened is not the best. So as there is no reaction on this PR since Dec 22, I would argue, it will not be merged any time soon

deicon avatar Apr 10 '23 11:04 deicon

👀

marcelarie avatar Aug 03 '23 16:08 marcelarie

This is a feature that would be useful to me.

In the meantime, I have achieved a similar (though less effective) solution using the inotify-tools package

MYFILE=log_file.txt
while inotifywait -e modify $MYFILE; do
    clear
    cat $MYFILE | glow
done

Wheest avatar Aug 31 '23 17:08 Wheest

Sure. Or using entr. I keep on using my patched version of glow though :)

ls *.md | entr glow yourfile.md

deicon avatar Aug 31 '23 17:08 deicon

^ bumping this PR

The fact that this feature has been ready since December last year and still hasn't been added is a shame as it's a wonderful concept!

VanuPhantom avatar Dec 14 '23 00:12 VanuPhantom

^ bumping this PR

The fact that this feature has been ready since December last year and still hasn't been added is a shame as it's a wonderful concept!

I almost forgot about this open PR. I went from being motivated to work on issues here, to Beeing realistic and did not expect it to be merged soon. Turns out i was right 😀 I believe I also asked the maintainers if there is anything missing for this to be considered. It might not be on their agenda. But even then I would expect the PR to be handled somehow. Rejecting at least.

deicon avatar Dec 14 '23 08:12 deicon

This works nicely for me.

I uninstalled the upstream glow and will be using your version for the time being. It's vital to have live rendering while writing a markdown document.

I noticed that the file watcher only works in TUI mode, i.e. when invoked with glow and then navigating to the file via the TUI.

I tried to do this at first glow --watch --interval 1 --pager. When it did not reload on changes, I noticed that glow --help mentioned it only works in TUI mode.

timskovjacobsen avatar Dec 22 '23 10:12 timskovjacobsen

This may be a bug indeed. Not sure if am willing to spend more time on this to make it not only work in tui mode.

deicon avatar Dec 22 '23 15:12 deicon

Sure. Or using entr. I keep on using my patched version of glow though :)

ls *.md | entr glow yourfile.md

Adding skim and some extra entr functionality for fuzzy-finding and a pretty experience:

sk | entr -c glow  /_

znd4 avatar Feb 19 '24 16:02 znd4

@meowgorithm Is there still need for this, or should I close it ?

deicon avatar Feb 28 '24 19:02 deicon

Thanks for flagging this, @deicon. We'll take a look at this and let you know of week.

meowgorithm avatar Feb 28 '24 19:02 meowgorithm

I think a polling solution should only be a fallback for monitoring files. Ideally we use one of the platform's native ways to monitor filesystem events: kqueue, inotify, and so on. There's an fsnotify package that abstracts this functionality for each platform, but it doesn't have a polling fallback yet. Maybe this would be a good contribution there?

There are also additional problems that we uncovered while experimenting with filesystem monitoring:

  1. Partial writes: we will need to figure out a way to detect when a file has been fully updated, not when writing to it starts. Otherwise you render incomplete content.
  2. Some editors & tools will not actually overwrite the contents of a file, but write to a temporary file first, then move it in place. In such situations the original file typically briefly disappears, along with all the monitoring you set up.

muesli avatar Mar 01 '24 17:03 muesli