From 1ff783d1ccb17fbf702f352812ae7eb834fed3ee Mon Sep 17 00:00:00 2001 From: merakor Date: Wed, 8 Sep 2021 17:34:12 +0000 Subject: log(): change print function depending on number of arguments FossilOrigin-Name: 9628d8c0a2b3f6cb9b78898701aace71a1f4d1aec8b98b55f75acb34c21b4ddd --- src/cpt-lib.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 58c9a0f..1d3a0de 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -28,8 +28,12 @@ log() { # # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. # '${2:+colorb}': If the 2nd argument exists, set text style of '$1'. - printf '%b%s %b%b%s%b %s\n' \ - "$colory" "${3:-->}" "$colre" "${2:+$colorb}" "$1" "$colre" "$2" >&2 + case $# in + 1) printf '%b->%b %s\n' "$colory" "$colre" "$1" ;; + 2) printf '%b->%b %b%s%b %s\n' "$colory" "$colre" "$colorb" "$1" "$colre" "$2" ;; + 3) printf '%b%s%b %b%s%b %s\n' "$colory" "${3:-->}" "$colre" "$colorb" "$1" "$colre" "$2" ;; + *) return 1 + esac >&2 } warn() { -- cgit v1.2.3