threads / patch / 33204

patchgitk: Add user-configurable branch bg color

Subject: [PATCH] gitk: Add user-configurable branch bg color

## tl;dr

2 messages between Mar 16, 2013 and Mar 17, 2013. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Manuel Bua· Mar 16, 2013, 20:05 UTC · lore

In some cases, the default branch background color (green) isn't an optimal choice, thus it can be difficult to read.

This provides a way for the user to customize the color used to fill the rectangle around the branch name, by choosing another one from the "Preferences" dialog.

The default behavior of using "green" as the default color is maintained.

Signed-off-by: Manuel Bua <manuel.bua@gmail.com>
---
 gitk | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
Show changes to gitk +16 −4
diff --git a/gitk b/gitk
index b3706fc..310c9a9 100755
--- a/gitk
+++ b/gitk
@@ -2720,7 +2720,7 @@ proc savestuff {w} {
     global maxwidth showneartags showlocalchanges
     global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
     global cmitmode wrapcomment datetimeformat limitdiffs
-    global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
+    global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor branchcolor
     global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
     global hideremotes want_ttk maxrefs
 
@@ -2760,6 +2760,7 @@ proc savestuff {w} {
 	puts $f [list set selectbgcolor $selectbgcolor]
 	puts $f [list set extdifftool $extdifftool]
 	puts $f [list set perfile_attrs $perfile_attrs]
+	puts $f [list set branchcolor $branchcolor]
 
 	puts $f "set geometry(main) [wm geometry .]"
 	puts $f "set geometry(state) [wm state .]"
@@ -6344,7 +6345,7 @@ proc bindline {t id} {
 proc drawtags {id x xt y1} {
     global idtags idheads idotherrefs mainhead
     global linespc lthickness
-    global canv rowtextx curview fgcolor bgcolor ctxbut
+    global canv rowtextx curview fgcolor bgcolor ctxbut branchcolor
 
     set marks {}
     set ntags 0
@@ -6399,7 +6400,7 @@ proc drawtags {id x xt y1} {
 	} else {
 	    # draw a head or other ref
 	    if {[incr nheads -1] >= 0} {
-		set col green
+		set col $branchcolor
 		if {$tag eq $mainhead} {
 		    set font mainfontbold
 		}
@@ -11033,7 +11034,7 @@ proc prefspage_general {notebook} {
 }
 
 proc prefspage_colors {notebook} {
-    global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
+    global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor branchcolor
 
     set page [create_prefs_page $notebook.colors]
 
@@ -11077,6 +11078,12 @@ proc prefspage_colors {notebook} {
     ${NS}::button $page.selbgbut -text [mc "Select bg"] \
 	-command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
     grid x $page.selbgbut $page.selbgsep -sticky w
+    label $page.selbranchcolsep -padx 40 -relief sunk -background $branchcolor
+    ${NS}::button $page.selbranchcolbut -text [mc "Select branch bg"] \
+	-command [list choosecolor branchcolor {} $page.selbranchcolsep \
+			[mc "branch background"] \
+			setbranchcolor]
+    grid x $page.selbranchcolbut $page.selbranchcolsep -sticky w
     return $page
 }
 
@@ -11221,6 +11228,10 @@ proc setfg {c} {
     $canv itemconf markid -outline $c
 }
 
+proc setbranchcolor {c} {
+	reloadcommits
+}
+
 proc prefscan {} {
     global oldprefs prefstop
 
@@ -11742,6 +11753,7 @@ set diffcontext 3
 set ignorespace 0
 set worddiff ""
 set markbgcolor "#e0e0ff"
+set branchcolor green
 
 set circlecolors {white blue gray blue blue}
 
-- 
1.8.2
Manuel Bua· Mar 17, 2013, 12:46 UTC · lore

Re: [PATCH] gitk: Add user-configurable branch bg color

On 03/17/2013 03:57 AM, David Aguilar wrote:
Show 12 quoted lines
>
> > In some cases, the default branch background color (green) isn't
> > an optimal choice, thus it can be difficult to read.
>
> I'm just curious -- is it "difficult to read" because gitk does not 
> specify a foreground color, thus causing it to pickup a system default 
> (which can vary), or is it for a different reason?
>
> If this is the reason then I wonder whether gitk should explicitly set 
> a foreground color. Apologies if it already works that way -- I just 
> wanted to better understand the motivation behind this patch.
>

Yes, having gitk to specify a foreground color instead would probably solve it too: i can remember the branch rectangles were a lot more readable in the past, but this could probably be due to me using a dark system theme at the time.

For example, in my case it would look a lot more readable if the text was "white on green" instead of "black on green", that could be even hardcoded as it was with the "green" color, but the reason behind the choice to let the user customize it is that i think it is better to honour the user system colors giving the means to adjust it to match his actual system configuration, rather than overriding it.

Regards, Manuel

← back to recent threads