diff options
author | Christophe Varoqui <christophe.varoqui@free.fr> | 2008-11-20 23:16:01 +0100 |
---|---|---|
committer | Christophe Varoqui <christophe.varoqui@free.fr> | 2008-11-20 23:16:01 +0100 |
commit | 14df6388e07bb09302e1e79b1744414b8a94974c (patch) | |
tree | be39fd4ecfce9593ec2f7c051e8d2f7bdaa6f3f0 /multipathd | |
parent | 8f0cb7332f468ac7a5f4456ee6076e9a872384ed (diff) | |
download | multipath-tools-14df6388e07bb09302e1e79b1744414b8a94974c.tar.gz multipath-tools-14df6388e07bb09302e1e79b1744414b8a94974c.tar.bz2 multipath-tools-14df6388e07bb09302e1e79b1744414b8a94974c.zip |
strip ANSI color markers in non-interactive mode
Tested with piped and redirected stdout, using either "multipath -l"
or "multipathd show topo". Seems there are no more blatant regression.
Let me know if there are, because I'm tempted to go a little further
with those ANSI codes by highlighting degrated/failure situation.
Diffstat (limited to 'multipathd')
-rw-r--r-- | multipathd/uxclnt.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/multipathd/uxclnt.c b/multipathd/uxclnt.c index bc89294..6de496b 100644 --- a/multipathd/uxclnt.c +++ b/multipathd/uxclnt.c @@ -24,6 +24,19 @@ #include <vector.h> #include "cli.h" +static void print_reply(char *s) +{ + if (isatty(1)) { + printf("%s", s); + return; + } + /* strip ANSI color markers */ + while (*s != '\0') { + if ((*s == 0x1b) && (*(s+1) == '[')) + while ((*s++ != 'm') && (*s != '\0')) {}; + putchar(*s++); + } +} /* * process the client */ @@ -51,7 +64,7 @@ static void process(int fd) if (send_packet(fd, line, llen + 1) != 0) break; if (recv_packet(fd, &reply, &len) != 0) break; - printf("%s", reply); + print_reply(reply); if (line && *line) add_history(line); @@ -69,7 +82,7 @@ static void process_req(int fd, char * inbuf) send_packet(fd, inbuf, strlen(inbuf) + 1); recv_packet(fd, &reply, &len); - printf("%s", reply); + print_reply(reply); FREE(reply); } |