#include <stdarg.h>
#include <sys/stat.h>
#include <dirent.h>
+#include <unistd.h>
#include "checkers.h"
#include "vector.h"
if (verbosity == 1)
return snprint_multipath(buff, len, "%n", mpp);
- c += sprintf(c, "%c[%dm", 0x1B, 1); /* bold on */
+ if(isatty(1))
+ c += sprintf(c, "%c[%dm", 0x1B, 1); /* bold on */
if (verbosity > 1 &&
mpp->action != ACT_NOTHING &&
c += sprintf(c, " (%%w)");
c += sprintf(c, " %%d %%s");
- c += sprintf(c, "%c[%dm", 0x1B, 0); /* bold off */
+ if(isatty(1))
+ c += sprintf(c, "%c[%dm", 0x1B, 0); /* bold off */
fwd += snprint_multipath(buff + fwd, len - fwd, style, mpp);
if (fwd > len)
#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
*/
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);
send_packet(fd, inbuf, strlen(inbuf) + 1);
recv_packet(fd, &reply, &len);
- printf("%s", reply);
+ print_reply(reply);
FREE(reply);
}