thp / urlwatch

Watch (parts of) webpages and get notified when something changes via e-mail, on your phone or via other means. Highly configurable.
https://thp.io/2008/urlwatch/
Other
2.81k stars 352 forks source link

color output lost with custom diff_tool setting #706

Closed mentalstring closed 2 years ago

mentalstring commented 2 years ago

I have looked into the documentation but couldn't find any obvious way to do this: how to ignore changes if they are only whitespace changes?

Sometimes pages change layout slightly, or the output of PDFs is styled a bit different, but despite no actual content changes, it still triggers a notification. Any way to better handle this?

thp commented 2 years ago

You should be able to use:

diff_tool: "diff --ignore-all-space"
mentalstring commented 2 years ago

That works great — will add it to the config defaults. Thank you!

mentalstring commented 2 years ago

Seems to have lost the colouring of the output so I'm guessing I'm overriding some default parameters. Tried to look through the code but couldn't figure it out what they are.

thp commented 2 years ago

Which color output do you mean? stdout? e-mail/HTML?

Coloring of the diff happens here: https://github.com/thp/urlwatch/blob/master/lib/urlwatch/reporters.py

        self._has_color = sys.stdout.isatty() and self.config.get('color', False)

For example, if you pipe the tool output into a different process, it won't color it -- or if the config for the stdout reporter doesn't have color set to a true-y value:

report:
  stdout:
    color: true
mentalstring commented 2 years ago

Sorry for not being specific — I meant the email/HTML report. Used to be colorized and the only config change was the diff_tool.

mentalstring commented 2 years ago

I was able to get the coloring to work again by using

diff_tool: "diff --ignore-all-space -u"

to get the unified out of diff. Not sure whether this is intended behavior and/or if it's worth documenting?

thp commented 2 years ago

Oh yeah, of course -- the coloring happens for unified diff. Yeah, I think it might make sense to add a small section to the docs how to ignore whitespace with this line. Want to have a try at a PR to the docs?

thp commented 2 years ago

Closing this as "done" in #707 by documentation.