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