summaryrefslogtreecommitdiff
path: root/multipathd
diff options
context:
space:
mode:
authorChristophe Varoqui <christophe.varoqui@free.fr>2008-11-20 23:16:01 +0100
committerChristophe Varoqui <christophe.varoqui@free.fr>2008-11-20 23:16:01 +0100
commit14df6388e07bb09302e1e79b1744414b8a94974c (patch)
treebe39fd4ecfce9593ec2f7c051e8d2f7bdaa6f3f0 /multipathd
parent8f0cb7332f468ac7a5f4456ee6076e9a872384ed (diff)
downloadmultipath-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.c17
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);
}