git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git status: display current branch name in color
@ 2010-01-15  2:23 Michael Wookey
  2010-01-17  4:31 ` Michael Wookey
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Wookey @ 2010-01-15  2:23 UTC (permalink / raw)
  To: Git Mailing List

There is an existing highlight when the user is not on any branch.
Enhance this functionality to always provide the name of the current
branch in color.

Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
---
 wt-status.c |   10 ++++++----
 wt-status.h |    3 ++-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 5d56988..bdaa98b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -17,6 +17,7 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RED,    /* WT_STATUS_UNTRACKED */
 	GIT_COLOR_RED,    /* WT_STATUS_NOBRANCH */
 	GIT_COLOR_RED,    /* WT_STATUS_UNMERGED */
+	GIT_COLOR_GREEN,  /* WT_STATUS_BRANCH */
 };

 static const char *color(int slot, struct wt_status *s)
@@ -553,7 +554,7 @@ static void wt_status_print_tracking(struct wt_status *s)

 void wt_status_print(struct wt_status *s)
 {
-	const char *branch_color = color(WT_STATUS_HEADER, s);
+	const char *branch_color = color(WT_STATUS_BRANCH, s);

 	if (s->branch) {
 		const char *on_what = "On branch ";
@@ -561,12 +562,13 @@ void wt_status_print(struct wt_status *s)
 		if (!prefixcmp(branch_name, "refs/heads/"))
 			branch_name += 11;
 		else if (!strcmp(branch_name, "HEAD")) {
-			branch_name = "";
+			branch_name = "Not currently on any branch.";
 			branch_color = color(WT_STATUS_NOBRANCH, s);
-			on_what = "Not currently on any branch.";
+			on_what = "";
 		}
 		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
-		color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
+		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", on_what);
+		color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
 		if (!s->is_initial)
 			wt_status_print_tracking(s);
 	}
diff --git a/wt-status.h b/wt-status.h
index c60f40a..b0cf235 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -12,6 +12,7 @@ enum color_wt_status {
 	WT_STATUS_UNTRACKED,
 	WT_STATUS_NOBRANCH,
 	WT_STATUS_UNMERGED,
+	WT_STATUS_BRANCH,
 };

 enum untracked_status_type {
@@ -40,7 +41,7 @@ struct wt_status {
 	int relative_paths;
 	int submodule_summary;
 	enum untracked_status_type show_untracked_files;
-	char color_palette[WT_STATUS_UNMERGED+1][COLOR_MAXLEN];
+	char color_palette[WT_STATUS_BRANCH+1][COLOR_MAXLEN];

 	/* These are computed during processing of the individual sections */
 	int commitable;
-- 
1.6.6.197.gfd7f6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] git status: display current branch name in color
  2010-01-15  2:23 [PATCH] git status: display current branch name in color Michael Wookey
@ 2010-01-17  4:31 ` Michael Wookey
  2010-01-18  2:32   ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Wookey @ 2010-01-17  4:31 UTC (permalink / raw)
  To: Git Mailing List, Junio C Hamano

> There is an existing highlight when the user is not on any branch.
> Enhance this functionality to always provide the name of the current
> branch in color.
>
> Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
> ---
>  wt-status.c |   10 ++++++----
>  wt-status.h |    3 ++-
>  2 files changed, 8 insertions(+), 5 deletions(-)

Any thoughts on this?

I have found this to be a useful feature; especially when using
msysGit in a Windows CMD shell. Specifically because a CMD shell
provides no ability for any sort of "git-completion.bash" prompt. By
highlighting the current branch name, the colouring has helped to
quickly identify what the current branch is.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] git status: display current branch name in color
  2010-01-17  4:31 ` Michael Wookey
@ 2010-01-18  2:32   ` Jeff King
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff King @ 2010-01-18  2:32 UTC (permalink / raw)
  To: Michael Wookey; +Cc: Git Mailing List, Junio C Hamano

On Sun, Jan 17, 2010 at 03:31:07PM +1100, Michael Wookey wrote:

> > There is an existing highlight when the user is not on any branch.
> > Enhance this functionality to always provide the name of the current
> > branch in color.
> >
> > Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
> > ---
> >  wt-status.c |   10 ++++++----
> >  wt-status.h |    3 ++-
> >  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> Any thoughts on this?

I don't have an objection to the concept, but for it to be acceptable
for inclusion in mainstream git, the color selection needs to be
configurable (see builtin-commit.c:parse_status_slot) and documented
(see Documentation/config.txt, color.status.<slot>).

And then we can decide what the _default_ color should be. Personally, I
find it a bit distracting to change the color for something so mundane,
and would be in favor of leaving it the same as the header color. But I
will not argue too hard either way; I have no problem with setting my
own config to make it invisible if others disagree. :)

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-18  2:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-15  2:23 [PATCH] git status: display current branch name in color Michael Wookey
2010-01-17  4:31 ` Michael Wookey
2010-01-18  2:32   ` Jeff King

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).