From 6cc0ddb5b0c44e855c6638d3b6838e0aa0f3e9e8 Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 28 Apr 2016 00:37:46 -0400 Subject: utility: fancy --version. --- src/slibtool.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/slibtool.c b/src/slibtool.c index e3bf2bb..6548099 100644 --- a/src/slibtool.c +++ b/src/slibtool.c @@ -15,19 +15,35 @@ | SLBT_DRIVER_VERBOSITY_USAGE #endif -static const char vermsg[] = "%s (git://midipix.org/slibtool): " - "version %d.%d.%d.\n" - "[commit reference: %s]\n"; +static const char vermsg[] = "%s%s%s (git://midipix.org/slibtool): " + "version %s%d.%d.%d%s.\n" + "[commit reference: %s%s%s]\n"; + +static const char * const slbt_ver_color[6] = { + "\e[1m\e[35m","\e[0m", + "\e[1m\e[32m","\e[0m", + "\e[1m\e[34m","\e[0m" +}; + +static const char * const slbt_ver_plain[6] = { + "","", + "","", + "","" +}; static ssize_t slibtool_version(struct slbt_driver_ctx * dctx) { const struct slbt_source_version * verinfo; + const char * const * verclr; verinfo = slbt_source_version(); + verclr = isatty(STDOUT_FILENO) ? slbt_ver_color : slbt_ver_plain; - return fprintf(stdout,vermsg,dctx->program, - verinfo->major,verinfo->minor,verinfo->revision, - verinfo->commit); + return fprintf(stdout,vermsg, + verclr[0],dctx->program,verclr[1], + verclr[2],verinfo->major,verinfo->minor, + verinfo->revision,verclr[3], + verclr[4],verinfo->commit,verclr[5]); } static void slibtool_perform_driver_actions(struct slbt_driver_ctx * dctx) -- cgit v1.2.3