diff options
author | Simon Gomizelj <simongmzlj@gmail.com> | 2012-08-14 19:03:29 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-08-14 19:36:27 -0400 |
commit | 9c1f6d96e2d64b4763ff02c23aa942849b28176b (patch) | |
tree | 7165b8ec9b17eb18935e0415a3cf57b4991935e7 | |
parent | 8052cbee80429e24e41c765b1547e1ca30e5f13f (diff) | |
download | mirror-ponymix-9c1f6d96e2d64b4763ff02c23aa942849b28176b.tar.gz mirror-ponymix-9c1f6d96e2d64b4763ff02c23aa942849b28176b.tar.bz2 mirror-ponymix-9c1f6d96e2d64b4763ff02c23aa942849b28176b.zip |
colorize pretty printed output
.,,.
,;;*;;;;,
.-'``;-');;.
/' .-. /*;;
.' \d \;; .;;;,
/ o ` \; ,__. ,;*;;;*;,
\__, _.__,' \_.-') __)--.;;;;;*;;;;,
`""`;;;\ /-')_) __) `\' ';;;;;;
;*;;; -') `)_) |\ | ;;;;*;
;;;;| `---` O | | ;;*;;;
*;*;\| O / ;;;;;*
;;;;;/| .-------\ / ;*;;;;;
;;;*;/ \ | '. (`. ;;;*;;;
;;;;;'. ; | ) \ | ;;;;;;
,;*;;;;\/ |. / /` | ';;;*;
;;;;;;/ |/ / /__/ ';;;
'*jgs/ | / | ;*;
`""""` `""""` ;'
-rw-r--r-- | ponymix.c | 55 |
1 files changed, 50 insertions, 5 deletions
@@ -33,6 +33,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <pulse/pulseaudio.h> @@ -46,6 +47,12 @@ ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ }) +#define COLOR_RESET "\033[0m" +#define COLOR_BOLD "\033[1m" +#define COLOR_RED "\033[31m" +#define COLOR_GREEN "\033[32m" +#define COLOR_YELLOW "\033[33m" + enum mode { MODE_DEVICE = 0, MODE_APP, @@ -126,6 +133,15 @@ struct pulseaudio_t { struct io_t *head; }; +struct colstr_t { + const char *name; + const char *high; + const char *mid; + const char *low; + const char *mute; + const char *nc; +}; + static int xstrtol(const char *str, long *out) { char *end = NULL; @@ -421,19 +437,48 @@ static int move_client(struct pulseaudio_t *pulse, struct io_t *dev) return !pulse->success; } -static void print(struct io_t *dev) +static void print(struct colstr_t *colstr, struct io_t *dev) { - printf("%s %2d: %s\n %s\n Avg. Volume: %d%% %s\n", dev->pp_name, - dev->idx, dev->name, dev->desc, dev->volume_percent, - dev->mute ? "[Muted]" : ""); + const char *level; + const char *mute = dev->mute ? "[Muted]" : ""; + + if (dev->volume_percent < 50) + level = colstr->low; + else if (dev->volume_percent < 75) + level = colstr->mid; + else + level = colstr->high; + + printf("%s%s %d:%s %s\n", colstr->name, dev->pp_name, dev->idx, + colstr->nc, dev->name); + printf(" %s\n", dev->desc); + printf(" Avg. Volume: %s%d%%%s %s%s%s\n", level, dev->volume_percent, + colstr->nc, colstr->mute, mute, colstr->nc); } static void print_all(struct pulseaudio_t *pulse) { struct io_t *dev = pulse->head; + struct colstr_t colstr; + + if (isatty(fileno(stdout))) { + colstr.name = COLOR_BOLD; + colstr.high = COLOR_RED; + colstr.mid = COLOR_YELLOW; + colstr.low = COLOR_GREEN; + colstr.mute = COLOR_BOLD COLOR_RED; + colstr.nc = COLOR_RESET; + } else { + colstr.name = ""; + colstr.high = ""; + colstr.mid = ""; + colstr.low = ""; + colstr.mute = ""; + colstr.nc = ""; + } while (dev) { - print(dev); + print(&colstr, dev); dev = dev->next; } } |