From f5d0fe0a5f7ce3e547d5541e47102fc4d3ad355d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 12 May 2020 12:03:13 +0300 Subject: [PATCH] kiss: Added KISS_COLOR to control color output --- kiss | 14 ++++++++------ kiss.1 | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/kiss b/kiss index b9d9c0a..057b40d 100755 --- a/kiss +++ b/kiss @@ -15,12 +15,10 @@ log() { # All messages are printed to stderr to allow the user to hide build # output which is the only thing printed to stdout. # - # '\033[1;32m' Set text to color '2' and make it bold. - # '\033[m': Reset text formatting. - # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. - # '${2:+\033[1;3Xm}': If the 2nd argument exists, set text style of '$1'. - printf '\033[1;33m%s \033[m%b%s\033[m %s\n' \ - "${3:-->}" "${2:+\033[1;36m}" "$1" "$2" >&2 + # The l variables contain escape sequence which are defined + # when '$KISS_COLOR' is equal to '1'. + printf '%b%s %b%s%b %s\n' \ + "$lcol" "${3:-->}" "${lclr}${2:+$lcol2}" "$1" "$lclr" "$2" } war() { @@ -1590,6 +1588,10 @@ main() { # as the environment variable should always be defined. [ "$KISS_PATH" ] || die "\$KISS_PATH needs to be set" + # Allow the user to disable colors in output via an environment variable. + # Check this once so as to not slow down printing. + [ "$KISS_COLOR" = 0 ] || lcol='\033[1;33m' lcol2='\033[1;36m' lclr='\033[m' + # Set the location to the repository and package database. pkg_db=var/db/kiss/installed diff --git a/kiss.1 b/kiss.1 index b80d883..99eb170 100644 --- a/kiss.1 +++ b/kiss.1 @@ -93,6 +93,11 @@ export KISS_HOOK=/path/to/script # This can be used to have the package manager run in a "fake root". export KISS_ROOT=/ +# Whether or not to color package manager output messages. +# +# Set it to '0' to disable. +export KISS_COLOR=1 + # Keep build logs around for successful builds and not just failing # ones. Helpful when debugging. #