git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Kestenholz <mk@spinlock.ch>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Matthias Kestenholz <matthias@spinlock.ch>
Subject: [PATCH 1/4] Add infrastructure for a single color config variable
Date: Sat,  5 Jan 2008 15:11:36 +0100	[thread overview]
Message-ID: <1199542299-12082-1-git-send-email-mk@spinlock.ch> (raw)
In-Reply-To: <1199542226.6209.34.camel@futex>

From: Matthias Kestenholz <matthias@spinlock.ch>

Signed-off-by: Matthias Kestenholz <matthias@spinlock.ch>
---
 Documentation/config.txt |    6 ++++++
 color.c                  |   19 +++++++++++++++++++
 color.h                  |   17 +++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index ee08845..4bebd47 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -438,6 +438,12 @@ color.status.<slot>::
 commit.template::
 	Specify a file to use as the template for new commit messages.
 
+color.ui::
+	When set to `always`, always use colors in all git commands which
+	are capable of colored output. When false (or `never`), never. When
+	set to `true` or `auto`, use colors only when the output is to the
+	terminal. Defaults to false.
+
 diff.autorefreshindex::
 	When using `git diff` to compare with work tree
 	files, do not consider stat-only change as changed.
diff --git a/color.c b/color.c
index 7f66c29..0792571 100644
--- a/color.c
+++ b/color.c
@@ -3,6 +3,9 @@
 
 #define COLOR_RESET "\033[m"
 
+int git_use_color = -1;
+int git_use_color_default = -1;
+
 static int parse_color(const char *name, int len)
 {
 	static const char * const color_names[] = {
@@ -143,6 +146,22 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
 	return 0;
 }
 
+int git_color_default_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "color.ui")) {
+		git_use_color_default = git_config_colorbool(var, value, -1);
+		return 0;
+	}
+
+	return git_default_config(var, value);
+}
+
+void git_color_config()
+{
+	if (git_use_color == -1 && git_use_color_default != -1)
+		git_use_color = git_use_color_default;
+}
+
 static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
 		va_list args, const char *trail)
 {
diff --git a/color.h b/color.h
index ff63513..bcb845d 100644
--- a/color.h
+++ b/color.h
@@ -4,7 +4,24 @@
 /* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
 #define COLOR_MAXLEN 24
 
+/*
+ * Use this variable to store the colorbool when reading from the config file.
+ */
+extern int git_use_color;
+
 int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
+
+/*
+ * Use this instead of git_default_config if you need the value of color.ui.
+ */
+int git_color_default_config(const char *var, const char *value);
+
+/*
+ * Call this function after git_config(config_fn_t fn) to set git_use_color,
+ * respecting the value of color.ui.
+ */
+void git_color_config();
+
 void color_parse(const char *var, const char *value, char *dst);
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
 int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
-- 
1.5.4.rc2.1104.gec8ae5-dirty

  reply	other threads:[~2008-01-05 14:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-04  8:35 [PATCH] add--interactive: allow diff colors without interactive colors Jeff King
2008-01-05  0:20 ` Junio C Hamano
2008-01-05  3:37   ` Jeff King
2008-01-05  8:01     ` Junio C Hamano
2008-01-05  8:51       ` Jeff King
2008-01-05  9:28         ` Junio C Hamano
2008-01-05  9:57           ` Jeff King
2008-01-05 10:58   ` [PATCH/resend] " Matthias Kestenholz
2008-01-05 11:11     ` Junio C Hamano
2008-01-05 14:10       ` Matthias Kestenholz
2008-01-05 14:11         ` Matthias Kestenholz [this message]
2008-01-05 14:11           ` [PATCH 2/4] git branch: Use color configuration infrastructure Matthias Kestenholz
2008-01-05 14:11             ` [PATCH 3/4] status and commit: " Matthias Kestenholz
2008-01-05 14:11               ` [PATCH 4/4] diff and log: " Matthias Kestenholz
2008-01-08 11:23             ` [PATCH 2/4] git branch: " Jeff King
2008-01-08 12:52               ` Matthias Kestenholz
2008-01-05 11:37     ` [PATCH/resend] add--interactive: allow diff colors without interactive colors Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1199542299-12082-1-git-send-email-mk@spinlock.ch \
    --to=mk@spinlock.ch \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matthias@spinlock.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).