Skip to content

Commit f8a2c0d

Browse files
committed
gitk: Allow the user to set some colors
This makes the colors for the diff old/new lines and hunk headers configurable, as well as the background and foreground (text color) of the various panes. There is now a GUI in the edit->preferences window to set them. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 2e1ded4 commit f8a2c0d

File tree

1 file changed

+101
-23
lines changed

1 file changed

+101
-23
lines changed

gitk

Lines changed: 101 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ proc makewindow {} {
386386
global rowctxmenu mergemax wrapcomment
387387
global highlight_files gdttype
388388
global searchstring sstring
389+
global bgcolor fgcolor bglist fglist diffcolors
389390

390391
menu .bar
391392
.bar add cascade -label "File" -menu .bar.file
@@ -446,18 +447,19 @@ proc makewindow {} {
446447
.ctop add .ctop.top
447448
set canv .ctop.top.clist.canv
448449
canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
449-
-bg white -bd 0 \
450+
-background $bgcolor -bd 0 \
450451
-yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
451452
.ctop.top.clist add $canv
452453
set canv2 .ctop.top.clist.canv2
453454
canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
454-
-bg white -bd 0 -yscrollincr $linespc
455+
-background $bgcolor -bd 0 -yscrollincr $linespc
455456
.ctop.top.clist add $canv2
456457
set canv3 .ctop.top.clist.canv3
457458
canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
458-
-bg white -bd 0 -yscrollincr $linespc
459+
-background $bgcolor -bd 0 -yscrollincr $linespc
459460
.ctop.top.clist add $canv3
460461
bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
462+
lappend bglist $canv $canv2 $canv3
461463

462464
set sha1entry .ctop.top.bar.sha1
463465
set entries $sha1entry
@@ -563,19 +565,22 @@ proc makewindow {} {
563565
trace add variable searchstring write incrsearch
564566
pack $sstring -side left -expand 1 -fill x
565567
set ctext .ctop.cdet.left.ctext
566-
text $ctext -bg white -state disabled -font $textfont \
568+
text $ctext -background $bgcolor -foreground $fgcolor \
569+
-state disabled -font $textfont \
567570
-width $geometry(ctextw) -height $geometry(ctexth) \
568571
-yscrollcommand scrolltext -wrap none
569572
scrollbar .ctop.cdet.left.sb -command "$ctext yview"
570573
pack .ctop.cdet.left.sb -side right -fill y
571574
pack $ctext -side left -fill both -expand 1
572575
.ctop.cdet add .ctop.cdet.left
576+
lappend bglist $ctext
577+
lappend fglist $ctext
573578

574579
$ctext tag conf comment -wrap $wrapcomment
575580
$ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
576-
$ctext tag conf hunksep -fore blue
577-
$ctext tag conf d0 -fore red
578-
$ctext tag conf d1 -fore "#00a000"
581+
$ctext tag conf hunksep -fore [lindex $diffcolors 2]
582+
$ctext tag conf d0 -fore [lindex $diffcolors 0]
583+
$ctext tag conf d1 -fore [lindex $diffcolors 1]
579584
$ctext tag conf m0 -fore red
580585
$ctext tag conf m1 -fore blue
581586
$ctext tag conf m2 -fore green
@@ -608,11 +613,15 @@ proc makewindow {} {
608613
pack .ctop.cdet.right.mode -side top -fill x
609614
set cflist .ctop.cdet.right.cfiles
610615
set indent [font measure $mainfont "nn"]
611-
text $cflist -width $geometry(cflistw) -background white -font $mainfont \
616+
text $cflist -width $geometry(cflistw) \
617+
-background $bgcolor -foreground $fgcolor \
618+
-font $mainfont \
612619
-tabs [list $indent [expr {2 * $indent}]] \
613620
-yscrollcommand ".ctop.cdet.right.sb set" \
614621
-cursor [. cget -cursor] \
615622
-spacing1 1 -spacing3 1
623+
lappend bglist $cflist
624+
lappend fglist $cflist
616625
scrollbar .ctop.cdet.right.sb -command "$cflist yview"
617626
pack .ctop.cdet.right.sb -side right -fill y
618627
pack $cflist -side left -fill both -expand 1
@@ -747,6 +756,7 @@ proc savestuff {w} {
747756
global maxwidth showneartags
748757
global viewname viewfiles viewargs viewperm nextviewnum
749758
global cmitmode wrapcomment
759+
global colors bgcolor fgcolor diffcolors
750760

751761
if {$stuffsaved} return
752762
if {![winfo viewable .]} return
@@ -761,6 +771,10 @@ proc savestuff {w} {
761771
puts $f [list set cmitmode $cmitmode]
762772
puts $f [list set wrapcomment $wrapcomment]
763773
puts $f [list set showneartags $showneartags]
774+
puts $f [list set bgcolor $bgcolor]
775+
puts $f [list set fgcolor $fgcolor]
776+
puts $f [list set colors $colors]
777+
puts $f [list set diffcolors $diffcolors]
764778
puts $f "set geometry(width) [winfo width .ctop]"
765779
puts $f "set geometry(height) [winfo height .ctop]"
766780
puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
@@ -2870,19 +2884,19 @@ proc drawlines {id} {
28702884
}
28712885

28722886
proc drawcmittext {id row col rmx} {
2873-
global linespc canv canv2 canv3 canvy0
2887+
global linespc canv canv2 canv3 canvy0 fgcolor
28742888
global commitlisted commitinfo rowidlist
28752889
global rowtextx idpos idtags idheads idotherrefs
28762890
global linehtag linentag linedtag
2877-
global mainfont canvxmax boldrows boldnamerows
2891+
global mainfont canvxmax boldrows boldnamerows fgcolor
28782892

28792893
set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
28802894
set x [xc $row $col]
28812895
set y [yc $row]
28822896
set orad [expr {$linespc / 3}]
28832897
set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
28842898
[expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
2885-
-fill $ofill -outline black -width 1]
2899+
-fill $ofill -outline $fgcolor -width 1 -tags circle]
28862900
$canv raise $t
28872901
$canv bind $t <1> {selcanvline {} %x %y}
28882902
set xt [xc $row [llength [lindex $rowidlist $row]]]
@@ -2910,13 +2924,13 @@ proc drawcmittext {id row col rmx} {
29102924
lappend nfont bold
29112925
}
29122926
}
2913-
set linehtag($row) [$canv create text $xt $y -anchor w \
2914-
-text $headline -font $font]
2927+
set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \
2928+
-text $headline -font $font -tags text]
29152929
$canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
2916-
set linentag($row) [$canv2 create text 3 $y -anchor w \
2917-
-text $name -font $nfont]
2918-
set linedtag($row) [$canv3 create text 3 $y -anchor w \
2919-
-text $date -font $mainfont]
2930+
set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
2931+
-text $name -font $nfont -tags text]
2932+
set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
2933+
-text $date -font $mainfont -tags text]
29202934
set xr [expr {$xt + [font measure $mainfont $headline]}]
29212935
if {$xr > $canvxmax} {
29222936
set canvxmax $xr
@@ -3138,7 +3152,7 @@ proc bindline {t id} {
31383152
proc drawtags {id x xt y1} {
31393153
global idtags idheads idotherrefs
31403154
global linespc lthickness
3141-
global canv mainfont commitrow rowtextx curview
3155+
global canv mainfont commitrow rowtextx curview fgcolor
31423156

31433157
set marks {}
31443158
set ntags 0
@@ -3201,8 +3215,8 @@ proc drawtags {id x xt y1} {
32013215
-width 0 -fill "#ffddaa" -tags tag.$id
32023216
}
32033217
}
3204-
set t [$canv create text $xl $y1 -anchor w -text $tag \
3205-
-font $mainfont -tags tag.$id]
3218+
set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
3219+
-font $mainfont -tags [list tag.$id text]]
32063220
if {$ntags >= 0} {
32073221
$canv bind $t <1> [list showtag $tag 1]
32083222
}
@@ -3223,10 +3237,11 @@ proc xcoord {i level ln} {
32233237
}
32243238

32253239
proc show_status {msg} {
3226-
global canv mainfont
3240+
global canv mainfont fgcolor
32273241

32283242
clear_display
3229-
$canv create text 3 3 -anchor nw -text $msg -font $mainfont -tags textitems
3243+
$canv create text 3 3 -anchor nw -text $msg -font $mainfont \
3244+
-tags text -fill $fgcolor
32303245
}
32313246

32323247
proc finishcommits {} {
@@ -4574,7 +4589,8 @@ proc linehover {} {
45744589
set t [$canv create rectangle $x0 $y0 $x1 $y1 \
45754590
-fill \#ffff80 -outline black -width 1 -tags hover]
45764591
$canv raise $t
4577-
set t [$canv create text $x $y -anchor nw -text $text -tags hover -font $mainfont]
4592+
set t [$canv create text $x $y -anchor nw -text $text -tags hover \
4593+
-font $mainfont]
45784594
$canv raise $t
45794595
}
45804596

@@ -5242,6 +5258,7 @@ proc doquit {} {
52425258
proc doprefs {} {
52435259
global maxwidth maxgraphpct diffopts
52445260
global oldprefs prefstop showneartags
5261+
global bgcolor fgcolor ctext diffcolors
52455262

52465263
set top .gitkprefs
52475264
set prefstop $top
@@ -5265,6 +5282,7 @@ proc doprefs {} {
52655282
-font optionfont
52665283
spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
52675284
grid x $top.maxpctl $top.maxpct -sticky w
5285+
52685286
label $top.ddisp -text "Diff display options"
52695287
grid $top.ddisp - -sticky w -pady 10
52705288
label $top.diffoptl -text "Options for diff program" \
@@ -5276,6 +5294,34 @@ proc doprefs {} {
52765294
checkbutton $top.ntag.b -variable showneartags
52775295
pack $top.ntag.b $top.ntag.l -side left
52785296
grid x $top.ntag -sticky w
5297+
5298+
label $top.cdisp -text "Colors: press to choose"
5299+
grid $top.cdisp - -sticky w -pady 10
5300+
label $top.bg -padx 40 -relief sunk -background $bgcolor
5301+
button $top.bgbut -text "Background" -font optionfont \
5302+
-command [list choosecolor bgcolor 0 $top.bg background setbg]
5303+
grid x $top.bgbut $top.bg -sticky w
5304+
label $top.fg -padx 40 -relief sunk -background $fgcolor
5305+
button $top.fgbut -text "Foreground" -font optionfont \
5306+
-command [list choosecolor fgcolor 0 $top.fg foreground setfg]
5307+
grid x $top.fgbut $top.fg -sticky w
5308+
label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
5309+
button $top.diffoldbut -text "Diff: old lines" -font optionfont \
5310+
-command [list choosecolor diffcolors 0 $top.diffold "diff old lines" \
5311+
[list $ctext tag conf d0 -foreground]]
5312+
grid x $top.diffoldbut $top.diffold -sticky w
5313+
label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
5314+
button $top.diffnewbut -text "Diff: new lines" -font optionfont \
5315+
-command [list choosecolor diffcolors 1 $top.diffnew "diff new lines" \
5316+
[list $ctext tag conf d1 -foreground]]
5317+
grid x $top.diffnewbut $top.diffnew -sticky w
5318+
label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
5319+
button $top.hunksepbut -text "Diff: hunk header" -font optionfont \
5320+
-command [list choosecolor diffcolors 2 $top.hunksep \
5321+
"diff hunk header" \
5322+
[list $ctext tag conf hunksep -foreground]]
5323+
grid x $top.hunksepbut $top.hunksep -sticky w
5324+
52795325
frame $top.buts
52805326
button $top.buts.ok -text "OK" -command prefsok
52815327
button $top.buts.can -text "Cancel" -command prefscan
@@ -5285,6 +5331,35 @@ proc doprefs {} {
52855331
grid $top.buts - - -pady 10 -sticky ew
52865332
}
52875333

5334+
proc choosecolor {v vi w x cmd} {
5335+
global $v
5336+
5337+
set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
5338+
-title "Gitk: choose color for $x"]
5339+
if {$c eq {}} return
5340+
$w conf -background $c
5341+
lset $v $vi $c
5342+
eval $cmd $c
5343+
}
5344+
5345+
proc setbg {c} {
5346+
global bglist
5347+
5348+
foreach w $bglist {
5349+
$w conf -background $c
5350+
}
5351+
}
5352+
5353+
proc setfg {c} {
5354+
global fglist canv
5355+
5356+
foreach w $fglist {
5357+
$w conf -foreground $c
5358+
}
5359+
allcanvs itemconf text -fill $c
5360+
$canv itemconf circle -outline $c
5361+
}
5362+
52885363
proc prefscan {} {
52895364
global maxwidth maxgraphpct diffopts
52905365
global oldprefs prefstop showneartags
@@ -5620,6 +5695,9 @@ set wrapcomment "none"
56205695
set showneartags 1
56215696

56225697
set colors {green red blue magenta darkgrey brown orange}
5698+
set bgcolor white
5699+
set fgcolor black
5700+
set diffcolors {red "#00a000" blue}
56235701

56245702
catch {source ~/.gitk}
56255703

0 commit comments

Comments
 (0)