Update following librseq API update
[libside.git] / m4 / ae_pprint.m4
CommitLineData
82abd52d
MJ
1# SPDX-License-Identifier: GPL-2.0-or-later WITH Autoconf-exception-2.0
2#
3# SPDX-FileCopyrightText: 2016 Philippe Proulx <pproulx@efficios.com>
4#
5
6#serial 2
7
8# AE_PPRINT_INIT(): initializes the pretty printing system.
9#
10# Use this macro before using any other AE_PPRINT_* macro.
11AC_DEFUN([AE_PPRINT_INIT], [
12 m4_define([AE_PPRINT_CONFIG_TS], [50])
13 m4_define([AE_PPRINT_CONFIG_INDENT], [2])
14 AE_PPRINT_YES_MSG=yes
15 AE_PPRINT_NO_MSG=no
16
17 # find tput, which tells us if colors are supported and gives us color codes
18 AC_PATH_PROG([ae_pprint_tput], [tput])
19
20 AS_IF([test -n "$ae_pprint_tput"], [
21 AS_IF([test -n "$PS1" && test `"$ae_pprint_tput" colors` -eq 256 && test -t 1], [
22 # interactive shell and colors supported and standard output
23 # file descriptor is opened on a terminal
24 AE_PPRINT_COLOR_TXTBLK="`"$ae_pprint_tput" setaf 0`"
25 AE_PPRINT_COLOR_TXTBLU="`"$ae_pprint_tput" setaf 4`"
26 AE_PPRINT_COLOR_TXTGRN="`"$ae_pprint_tput" setaf 2`"
27 AE_PPRINT_COLOR_TXTCYN="`"$ae_pprint_tput" setaf 6`"
28 AE_PPRINT_COLOR_TXTRED="`"$ae_pprint_tput" setaf 1`"
29 AE_PPRINT_COLOR_TXTPUR="`"$ae_pprint_tput" setaf 5`"
30 AE_PPRINT_COLOR_TXTYLW="`"$ae_pprint_tput" setaf 3`"
31 AE_PPRINT_COLOR_TXTWHT="`"$ae_pprint_tput" setaf 7`"
32 AE_PPRINT_COLOR_BLD=`"$ae_pprint_tput" bold`
33 AE_PPRINT_COLOR_BLDBLK="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTBLK"
34 AE_PPRINT_COLOR_BLDBLU="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTBLU"
35 AE_PPRINT_COLOR_BLDGRN="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTGRN"
36 AE_PPRINT_COLOR_BLDCYN="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTCYN"
37 AE_PPRINT_COLOR_BLDRED="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTRED"
38 AE_PPRINT_COLOR_BLDPUR="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTPUR"
39 AE_PPRINT_COLOR_BLDYLW="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTYLW"
40 AE_PPRINT_COLOR_BLDWHT="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTWHT"
41 AE_PPRINT_COLOR_RST="`"$ae_pprint_tput" sgr0`"
42
43 # colored yes and no
44 AE_PPRINT_YES_MSG="$AE_PPRINT_COLOR_BLDGRN$AE_PPRINT_YES_MSG$AE_PPRINT_COLOR_RST"
45 AE_PPRINT_NO_MSG="$AE_PPRINT_COLOR_BLDRED$AE_PPRINT_NO_MSG$AE_PPRINT_COLOR_RST"
46
47 # subtitle color
48 AE_PPRINT_COLOR_SUBTITLE="$AE_PPRINT_COLOR_BLDCYN"
49 ])
50 ])
51])
52
53# AE_PPRINT_SET_INDENT(indent): sets the current indentation.
54#
55# Use AE_PPRINT_INIT() before using this macro.
56AC_DEFUN([AE_PPRINT_SET_INDENT], [
57 m4_define([AE_PPRINT_CONFIG_INDENT], [$1])
58])
59
60# AE_PPRINT_SET_TS(ts): sets the current tab stop.
61#
62# Use AE_PPRINT_INIT() before using this macro.
63AC_DEFUN([AE_PPRINT_SET_TS], [
64 m4_define([AE_PPRINT_CONFIG_TS], [$1])
65])
66
67# AE_PPRINT_SUBTITLE(subtitle): pretty prints a subtitle.
68#
69# The subtitle is put as is in a double-quoted shell string so the user
70# needs to escape ".
71#
72# Use AE_PPRINT_INIT() before using this macro.
73AC_DEFUN([AE_PPRINT_SUBTITLE], [
74 AS_ECHO(["${AE_PPRINT_COLOR_SUBTITLE}$1$AE_PPRINT_COLOR_RST"])
75])
76
77AC_DEFUN([_AE_PPRINT_INDENT], [
78 m4_if(AE_PPRINT_CONFIG_INDENT, 0, [
79 ], [
80 m4_for([ae_pprint_i], [0], m4_eval(AE_PPRINT_CONFIG_INDENT * 2 - 1), [1], [
81 AS_ECHO_N([" "])
82 ])
83 ])
84])
85
86# AE_PPRINT_PROP_STRING(title, value, title_color?): pretty prints a
87# string property.
88#
89# The title is put as is in a double-quoted shell string so the user
90# needs to escape ".
91#
92# The $AE_PPRINT_CONFIG_INDENT variable must be set to the desired indentation
93# level.
94#
95# Use AE_PPRINT_INIT() before using this macro.
96AC_DEFUN([AE_PPRINT_PROP_STRING], [
97 m4_pushdef([ae_pprint_title], [$1])
98 m4_pushdef([ae_pprint_value], [$2])
99 m4_pushdef([ae_pprint_title_color], m4_default([$3], []))
100 m4_pushdef([ae_pprint_title_len], m4_len(ae_pprint_title))
101 m4_pushdef([ae_pprint_spaces_cnt], m4_eval(AE_PPRINT_CONFIG_TS - ae_pprint_title_len - (AE_PPRINT_CONFIG_INDENT * 2) - 1))
102
103 m4_if(m4_eval(ae_pprint_spaces_cnt <= 0), [1], [
104 m4_define([ae_pprint_spaces_cnt], [1])
105 ])
106
107 m4_pushdef([ae_pprint_spaces], [])
108
109 m4_for([ae_pprint_i], 0, m4_eval(ae_pprint_spaces_cnt - 1), [1], [
110 m4_append([ae_pprint_spaces], [ ])
111 ])
112
113 _AE_PPRINT_INDENT
114
115 AS_ECHO_N(["ae_pprint_title_color""ae_pprint_title$AE_PPRINT_COLOR_RST:ae_pprint_spaces"])
116 AS_ECHO(["${AE_PPRINT_COLOR_BLD}ae_pprint_value$AE_PPRINT_COLOR_RST"])
117
118 m4_popdef([ae_pprint_spaces])
119 m4_popdef([ae_pprint_spaces_cnt])
120 m4_popdef([ae_pprint_title_len])
121 m4_popdef([ae_pprint_title_color])
122 m4_popdef([ae_pprint_value])
123 m4_popdef([ae_pprint_title])
124])
125
126# AE_PPRINT_PROP_BOOL(title, value, title_color?): pretty prints a boolean
127# property.
128#
129# The title is put as is in a double-quoted shell string so the user
130# needs to escape ".
131#
132# The value is evaluated at shell runtime. Its evaluation must be
133# 0 (false) or 1 (true).
134#
135# Uses the AE_PPRINT_PROP_STRING() with the "yes" or "no" string.
136#
137# Use AE_PPRINT_INIT() before using this macro.
138AC_DEFUN([AE_PPRINT_PROP_BOOL], [
139 m4_pushdef([ae_pprint_title], [$1])
140 m4_pushdef([ae_pprint_value], [$2])
141
142 test ae_pprint_value -eq 0 && ae_pprint_msg="$AE_PPRINT_NO_MSG" || ae_pprint_msg="$AE_PPRINT_YES_MSG"
143
144 m4_if([$#], [3], [
145 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg], $3)
146 ], [
147 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg])
148 ])
149
150 m4_popdef([ae_pprint_value])
151 m4_popdef([ae_pprint_title])
152])
153
154# AE_PPRINT_PROP_BOOL_CUSTOM(title, value, no_msg, title_color?): pretty prints a boolean
155# property.
156#
157# The title is put as is in a double-quoted shell string so the user
158# needs to escape ".
159#
160# The value is evaluated at shell runtime. Its evaluation must be
161# 0 (false) or 1 (true).
162#
163# Uses the AE_PPRINT_PROP_STRING() with the "yes" or "no" string.
164#
165# Use AE_PPRINT_INIT() before using this macro.
166AC_DEFUN([AE_PPRINT_PROP_BOOL_CUSTOM], [
167 m4_pushdef([ae_pprint_title], [$1])
168 m4_pushdef([ae_pprint_value], [$2])
169 m4_pushdef([ae_pprint_value_no_msg], [$3])
170
171 test ae_pprint_value -eq 0 && ae_pprint_msg="$AE_PPRINT_NO_MSG (ae_pprint_value_no_msg)" || ae_pprint_msg="$AE_PPRINT_YES_MSG"
172
173 m4_if([$#], [4], [
174 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg], $4)
175 ], [
176 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg])
177 ])
178
179 m4_popdef([ae_pprint_value_no_msg])
180 m4_popdef([ae_pprint_value])
181 m4_popdef([ae_pprint_title])
182])
183
184# AE_PPRINT_WARN(msg): pretty prints a warning message.
185#
186# The message is put as is in a double-quoted shell string so the user
187# needs to escape ".
188#
189# Use AE_PPRINT_INIT() before using this macro.
190AC_DEFUN([AE_PPRINT_WARN], [
191 m4_pushdef([ae_pprint_msg], [$1])
192
193 _AE_PPRINT_INDENT
194 AS_ECHO(["${AE_PPRINT_COLOR_TXTYLW}WARNING:$AE_PPRINT_COLOR_RST ${AE_PPRINT_COLOR_BLDYLW}ae_pprint_msg$AE_PPRINT_COLOR_RST"])
195
196 m4_popdef([ae_pprint_msg])
197])
198
199# AE_PPRINT_ERROR(msg): pretty prints an error message and exits.
200#
201# The message is put as is in a double-quoted shell string so the user
202# needs to escape ".
203#
204# Use AE_PPRINT_INIT() before using this macro.
205AC_DEFUN([AE_PPRINT_ERROR], [
206 m4_pushdef([ae_pprint_msg], [$1])
207
208 AC_MSG_ERROR([${AE_PPRINT_COLOR_BLDRED}ae_pprint_msg$AE_PPRINT_COLOR_RST])
209
210 m4_popdef([ae_pprint_msg])
211])
This page took 0.02832 seconds and 4 git commands to generate.