0

I'm working on a project that will use whatever package manager is available to provision a freshly installed OS. Some examples of package managers could be apt for Ubuntu, brew and brew cask for OSX, or pacman for Arch.

I'd like to display colored messages to stdout or stderr depending on what happens. I'm looking for some guidelines about what type of color and content I should use and where I should pipe the output.

Thinking a little bit about it I came up with:

  • status messages can be in blue or no color and only printed to stdout if the -v or --verbose flag is given.

    Ex:

    -* installing commandline-tools
    
  • Success messages in green and printed by default to stdout (or maybe if the verbose flag is given I'm not sure)

    Ex:

    -* installed commandline-tools
    
  • Failure messages in red and printed by default to stderr

    Ex:

    -* failed to install commandline-tools
    

Thoughts and opinions are welcome, but I would also appreciate some definitive sources/guidelines

  • When you say "provision a freshly installed OS" what do you mean by that? With this tool be run in an initrd? Will it try to overwrite the current local disk? Will it create a chroot environment? Also, how do you intend to dynamically use a package manager? Package managers require packages in particular formats, so are you including a copy of many types of packages? Or dynamically building the packages in your tool? – Centimane Sep 7 '16 at 20:09
  • Check out what ansible output looks like? +1 for finishing with a count of errors. The green messages for "ok" tend to have the same text, (like ok [localhost], on a line of it's own), maybe it makes them easier to skim. The name of the task is in normal color. The defaults seem to be that you do want output for successes, to provide progress indicators, because these tasks take sooo longgg. Not entirely sure that separating stdout / stderr is useful here. It's most useful as a separate channel from tools used in pipelines, but you kind of want to keep the whole log output together – sourcejedi Sep 7 '16 at 21:07
1

Try this snippet, you will be able to color what you want :

for i in {0..7};
do
    tput setaf $i // color next echo command
    echo "tput setaf $i"
    tput sgr0     // reset normal colors
done

I recommend to not use raw ANSI escape code.

| improve this answer | |
  • The original project I've been looking at uses raw ANSI escape codes, can you elaborate on why you recommend not going that route? – mbigras Sep 9 '16 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.