Giter Site home page Giter Site logo

Comments (6)

mag37 avatar mag37 commented on May 27, 2024

I'll look into how I could achieve this without making a mess.
My first thought (without reading up on it) would be to try to set the colors as variables - and if the monochrome-flag is set it'll just set the variables blank.

To avoid having a if-else for every print statement - that'd be messy.

What breaks with email and how can I easily test things when trying alternatives?

from dockcheck.

mag37 avatar mag37 commented on May 27, 2024

I'm still intrigued how you're using this and what's causing errors.

Looked into swapping all printf's to variables, that'd mean it would look like this:

# currently:
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
# with variables:
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"

Or something similar, where the variables would just be set to "" if monochrome option was toggled. Would that make a difference in your use case?

from dockcheck.

dst78 avatar dst78 commented on May 27, 2024

@mag37 First: Your solution would work. I'm guessing you assign the escape sequences to $c_yellow etc and if the script is started with a -m monochrome argument you reassign $c_yellow="" or something to that effect?

That would take care of my issue just fine.

To explain how my issue comes to be:
I'm using a bash wrapper script to call dockcheck.sh as cronjob. The wrapper script will direct the output of dockcheck.sh into a temporary file, measure the runtime, parse the output for actual updates and when there are any, send the content of that file via mail. After that the content of the temporary file is appended to a permanent logfile and itself deleted.

This means that the shell color escape sequences are sent via mail and my mail client doesn't know what to do with them so they're displayed as raw bytes:

checking for docker image updates: Mon Dec 11 00:30:01 CET 2023

. . . . . . . . . . . . . . . .
ESC[0;32mContainers on latest version:ESC[0m
bookstack

from dockcheck.

mag37 avatar mag37 commented on May 27, 2024

Just added a new branch, will test it some more before pushing to main. If you can and want to try it, please do and report if it suits your case :)

Edit: Sorry, didnt manage to push a monochrome flag/option yet. I'll get to it tomorrow.

Edit: Some bedside commits and its there. Option added.

from dockcheck.

dst78 avatar dst78 commented on May 27, 2024

Good morning :)
I tested the printf_rework branch and it does what it should, the escape characters are gone. Note that I wasn't able to test all variants of output but the principle surely works.
thanks!

from dockcheck.

mag37 avatar mag37 commented on May 27, 2024

Thank you for testing and giving feedback! And thank you for bringing up the suggestion in the first place.

I'll merge it with main in a minute, just gonna do some minor cleaning while I'm on it.

from dockcheck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.