From 9cb97d5705658f31ba3c4fb197d8800e3f77aec0 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 26 Sep 2011 22:54:04 +0200 Subject: [PATCH] Colorize make output (v1) --- job.c | 2 +- main.c | 2 ++ misc.c | 16 +++++++++------- remake.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/job.c b/job.c index aacfb84..37017e0 100644 --- a/job.c +++ b/job.c @@ -1144,7 +1144,7 @@ start_job_command (struct child *child) appear. */ message (0, (just_print_flag || (!(flags & COMMANDS_SILENT) && !silent_flag)) - ? "%s" : (char *) 0, p); + ? "\033[1;35m%s\033[0m" : (char *) 0, p); /* Tell update_goal_chain that a command has been started on behalf of this target. It is important that this happens here and not in diff --git a/main.c b/main.c index c6989e3..5c6528d 100644 --- a/main.c +++ b/main.c @@ -3231,6 +3231,7 @@ log_working_directory (int entering) /* Use entire sentences to give the translators a fighting chance. */ + printf ("\033[0;36m"); if (makelevel == 0) if (starting_directory == 0) if (entering) @@ -3259,6 +3260,7 @@ log_working_directory (int entering) else printf (_("%s[%u]: Leaving directory `%s'\n"), program, makelevel, starting_directory); + printf ("\033[0m"); /* Flush stdout to be sure this comes before any stderr output. */ fflush (stdout); diff --git a/misc.c b/misc.c index 7a6f773..ad31b83 100644 --- a/misc.c +++ b/misc.c @@ -236,16 +236,18 @@ message (prefix, fmt, va_alist) if (fmt != 0) { if (prefix) - { - if (makelevel == 0) - printf ("%s: ", program); - else - printf ("%s[%u]: ", program, makelevel); - } + { + if (makelevel == 0) + printf ("\033[36m%s: ", program); + else + printf ("\033[36m%s[%u]: ", program, makelevel); + } + else + printf ("\033[36m"); VA_START (args, fmt); VA_PRINTF (stdout, fmt, args); VA_END (args); - putchar ('\n'); + printf ("\n\033[0m"); } fflush (stdout); diff --git a/remake.c b/remake.c index 27d2550..3babb7a 100644 --- a/remake.c +++ b/remake.c @@ -69,6 +69,38 @@ static void remake_file (struct file *file); static FILE_TIMESTAMP name_mtime (const char *name); static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr); +/* + * Take string and wrap it by and + * The result is malloc'd and has to be free'd. + */ +static char * colorize(const char * begin, const char * text, const char * end) { + const char * const jobs[] = {begin, text, end}; + const size_t job_count = sizeof(jobs) / sizeof(char *); + size_t job_lens[job_count]; + size_t out_len = 1; + int i = 0; + + /* Count */ + for (; i < job_count; i++) { + job_lens[i] = strlen(jobs[i]); + out_len += job_lens[i]; + } + + /* Allocate */ + char * const out = malloc(out_len); + assert(out); + + /* Concat */ + char * walker = out; + for (i = 0; i < job_count; i++) { + strcpy(walker, jobs[i]); + walker += job_lens[i]; + } + walker[0] = '\0'; + + return out; +} + /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing was done, 0 if all goals were updated successfully, or 1 if a goal failed. @@ -230,11 +262,14 @@ update_goal_chain (struct dep *goals) && file->update_status == 0 && !g->changed /* Never give a message under -s or -q. */ && !silent_flag && !question_flag) - message (1, ((file->phony || file->cmds == 0) - ? _("Nothing to be done for `%s'.") - : _("`%s' is up to date.")), - file->name); - + { + const char * const text = ((file->phony || file->cmds == 0) + ? _("Nothing to be done for `%s'.") + : _("`%s' is up to date.")); + char * const colorized = colorize("\033[36m", text, "\033[0m"); + message (1, colorized, file->name); + free (colorized); + } /* This goal is finished. Remove it from the chain. */ if (lastgoal == 0) goals = g->next; -- 1.7.6.1