1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
# DESCRIPTION
#
# Pretty printing macros.
#
# LICENSE
#
# Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 1
# PPRINT_INIT(): initializes the pretty printing system.
#
# Use this macro before using any other PPRINT_* macro.
AC_DEFUN([PPRINT_INIT], [
m4_define([PPRINT_CONFIG_TS], [50])
m4_define([PPRINT_CONFIG_INDENT], [2])
PPRINT_YES_MSG=yes
PPRINT_NO_MSG=no
# find tput, which tells us if colors are supported and gives us color codes
AC_PATH_PROG([pprint_tput], [tput])
AS_IF([test -n "$pprint_tput"], [
AS_IF([test -n "$PS1" && test `"$pprint_tput" colors` -eq 256 && test -t 1], [
# interactive shell and colors supported and standard output
# file descriptor is opened on a terminal
PPRINT_COLOR_TXTBLK="`"$pprint_tput" setaf 0`"
PPRINT_COLOR_TXTBLU="`"$pprint_tput" setaf 4`"
PPRINT_COLOR_TXTGRN="`"$pprint_tput" setaf 2`"
PPRINT_COLOR_TXTCYN="`"$pprint_tput" setaf 6`"
PPRINT_COLOR_TXTRED="`"$pprint_tput" setaf 1`"
PPRINT_COLOR_TXTPUR="`"$pprint_tput" setaf 5`"
PPRINT_COLOR_TXTYLW="`"$pprint_tput" setaf 3`"
PPRINT_COLOR_TXTWHT="`"$pprint_tput" setaf 7`"
PPRINT_COLOR_BLD=`"$pprint_tput" bold`
PPRINT_COLOR_BLDBLK="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTBLK"
PPRINT_COLOR_BLDBLU="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTBLU"
PPRINT_COLOR_BLDGRN="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTGRN"
PPRINT_COLOR_BLDCYN="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTCYN"
PPRINT_COLOR_BLDRED="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTRED"
PPRINT_COLOR_BLDPUR="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTPUR"
PPRINT_COLOR_BLDYLW="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTYLW"
PPRINT_COLOR_BLDWHT="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTWHT"
PPRINT_COLOR_RST="`"$pprint_tput" sgr0`"
# colored yes and no
PPRINT_YES_MSG="$PPRINT_COLOR_BLDGRN$PPRINT_YES_MSG$PPRINT_COLOR_RST"
PPRINT_NO_MSG="$PPRINT_COLOR_BLDRED$PPRINT_NO_MSG$PPRINT_COLOR_RST"
# subtitle color
PPRINT_COLOR_SUBTITLE="$PPRINT_COLOR_BLDCYN"
])
])
])
# PPRINT_SET_INDENT(indent): sets the current indentation.
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_SET_INDENT], [
m4_define([PPRINT_CONFIG_INDENT], [$1])
])
# PPRINT_SET_TS(ts): sets the current tab stop.
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_SET_TS], [
m4_define([PPRINT_CONFIG_TS], [$1])
])
# PPRINT_SUBTITLE(subtitle): pretty prints a subtitle.
#
# The subtitle is put as is in a double-quoted shell string so the user
# needs to escape ".
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_SUBTITLE], [
AS_ECHO(["${PPRINT_COLOR_SUBTITLE}$1$PPRINT_COLOR_RST"])
])
AC_DEFUN([_PPRINT_INDENT], [
m4_if(PPRINT_CONFIG_INDENT, 0, [
], [
m4_for([pprint_i], [0], m4_eval(PPRINT_CONFIG_INDENT * 2 - 1), [1], [
AS_ECHO_N([" "])
])
])
])
# PPRINT_PROP_STRING(title, value, title_color?): pretty prints a
# string property.
#
# The title is put as is in a double-quoted shell string so the user
# needs to escape ".
#
# The $PPRINT_CONFIG_INDENT variable must be set to the desired indentation
# level.
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_PROP_STRING], [
m4_pushdef([pprint_title], [$1])
m4_pushdef([pprint_value], [$2])
m4_pushdef([pprint_title_color], m4_default([$3], []))
m4_pushdef([pprint_title_len], m4_len(pprint_title))
m4_pushdef([pprint_spaces_cnt], m4_eval(PPRINT_CONFIG_TS - pprint_title_len - (PPRINT_CONFIG_INDENT * 2) - 1))
m4_if(m4_eval(pprint_spaces_cnt <= 0), [1], [
m4_define([pprint_spaces_cnt], [1])
])
m4_pushdef([pprint_spaces], [])
m4_for([pprint_i], 0, m4_eval(pprint_spaces_cnt - 1), [1], [
m4_append([pprint_spaces], [ ])
])
_PPRINT_INDENT
AS_ECHO_N(["pprint_title_color""pprint_title$PPRINT_COLOR_RST:pprint_spaces"])
AS_ECHO(["${PPRINT_COLOR_BLD}pprint_value$PPRINT_COLOR_RST"])
m4_popdef([pprint_spaces])
m4_popdef([pprint_spaces_cnt])
m4_popdef([pprint_title_len])
m4_popdef([pprint_title_color])
m4_popdef([pprint_value])
m4_popdef([pprint_title])
])
# PPRINT_PROP_BOOL(title, value, title_color?): pretty prints a boolean
# property.
#
# The title is put as is in a double-quoted shell string so the user
# needs to escape ".
#
# The value is evaluated at shell runtime. Its evaluation must be
# 0 (false) or 1 (true).
#
# Uses the PPRINT_PROP_STRING() with the "yes" or "no" string.
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_PROP_BOOL], [
m4_pushdef([pprint_title], [$1])
m4_pushdef([pprint_value], [$2])
test pprint_value -eq 0 && pprint_msg="$PPRINT_NO_MSG" || pprint_msg="$PPRINT_YES_MSG"
m4_if([$#], [3], [
PPRINT_PROP_STRING(pprint_title, [$pprint_msg], $3)
], [
PPRINT_PROP_STRING(pprint_title, [$pprint_msg])
])
m4_popdef([pprint_value])
m4_popdef([pprint_title])
])
# PPRINT_PROP_BOOL_CUSTOM(title, value, no_msg, title_color?): pretty prints a boolean
# property.
#
# The title is put as is in a double-quoted shell string so the user
# needs to escape ".
#
# The value is evaluated at shell runtime. Its evaluation must be
# 0 (false) or 1 (true).
#
# Uses the PPRINT_PROP_STRING() with the "yes" or "no" string.
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_PROP_BOOL_CUSTOM], [
m4_pushdef([pprint_title], [$1])
m4_pushdef([pprint_value], [$2])
m4_pushdef([pprint_value_no_msg], [$3])
test pprint_value -eq 0 && pprint_msg="$PPRINT_NO_MSG (pprint_value_no_msg)" || pprint_msg="$PPRINT_YES_MSG"
m4_if([$#], [4], [
PPRINT_PROP_STRING(pprint_title, [$pprint_msg], $4)
], [
PPRINT_PROP_STRING(pprint_title, [$pprint_msg])
])
m4_popdef([pprint_value_no_msg])
m4_popdef([pprint_value])
m4_popdef([pprint_title])
])
# PPRINT_WARN(msg): pretty prints a warning message.
#
# The message is put as is in a double-quoted shell string so the user
# needs to escape ".
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_WARN], [
m4_pushdef([pprint_msg], [$1])
_PPRINT_INDENT
AS_ECHO(["${PPRINT_COLOR_TXTYLW}WARNING:$PPRINT_COLOR_RST ${PPRINT_COLOR_BLDYLW}pprint_msg$PPRINT_COLOR_RST"])
m4_popdef([pprint_msg])
])
# PPRINT_ERROR(msg): pretty prints an error message and exits.
#
# The message is put as is in a double-quoted shell string so the user
# needs to escape ".
#
# Use PPRINT_INIT() before using this macro.
AC_DEFUN([PPRINT_ERROR], [
m4_pushdef([pprint_msg], [$1])
AC_MSG_ERROR([${PPRINT_COLOR_BLDRED}pprint_msg$PPRINT_COLOR_RST])
m4_popdef([pprint_msg])
])
|