##// END OF EJS Templates
chg: use color in debug/error messages conditionally...
Jun Wu -
r28787:ea86cdcd default
parent child Browse files
Show More
@@ -522,6 +522,9 int main(int argc, const char *argv[], c
522 522 if (getenv("CHGDEBUG"))
523 523 enabledebugmsg();
524 524
525 if (!getenv("HGPLAIN") && isatty(fileno(stderr)))
526 enablecolor();
527
525 528 if (getenv("CHGINTERNALMARK"))
526 529 abortmsg("chg started by chg detected.\n"
527 530 "Please make sure ${HG:-hg} is not a symlink or "
@@ -18,13 +18,24
18 18
19 19 #include "util.h"
20 20
21 static int colorenabled = 0;
22
23 static inline void fsetcolor(FILE *fp, const char *code)
24 {
25 if (!colorenabled)
26 return;
27 fprintf(fp, "\033[%sm", code);
28 }
29
21 30 void abortmsg(const char *fmt, ...)
22 31 {
23 32 va_list args;
24 33 va_start(args, fmt);
25 fputs("\033[1;31mchg: abort: ", stderr);
34 fsetcolor(stderr, "1;31");
35 fputs("chg: abort: ", stderr);
26 36 vfprintf(stderr, fmt, args);
27 fputs("\033[m\n", stderr);
37 fsetcolor(stderr, "");
38 fputc('\n', stderr);
28 39 va_end(args);
29 40
30 41 exit(255);
@@ -32,6 +43,11 void abortmsg(const char *fmt, ...)
32 43
33 44 static int debugmsgenabled = 0;
34 45
46 void enablecolor(void)
47 {
48 colorenabled = 1;
49 }
50
35 51 void enabledebugmsg(void)
36 52 {
37 53 debugmsgenabled = 1;
@@ -44,9 +60,11 void debugmsg(const char *fmt, ...)
44 60
45 61 va_list args;
46 62 va_start(args, fmt);
47 fputs("\033[1;30mchg: debug: ", stderr);
63 fsetcolor(stderr, "1;30");
64 fputs("chg: debug: ", stderr);
48 65 vfprintf(stderr, fmt, args);
49 fputs("\033[m\n", stderr);
66 fsetcolor(stderr, "");
67 fputc('\n', stderr);
50 68 va_end(args);
51 69 }
52 70
@@ -18,6 +18,7
18 18
19 19 void abortmsg(const char *fmt, ...) PRINTF_FORMAT_;
20 20
21 void enablecolor(void);
21 22 void enabledebugmsg(void);
22 23 void debugmsg(const char *fmt, ...) PRINTF_FORMAT_;
23 24
General Comments 0
You need to be logged in to leave comments. Login now