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 <paulus@samba.org>
Paul Mackerras committed
Jul 5, 2006 at 22:56 UTC
f8a2c0d14f5326e157b12ec549b864ddb492621d
1 file changed
+101
-23
gitk
+101
-23
@@ -386,6 +386,7 @@ proc makewindow {} {
386
global rowctxmenu mergemax wrapcomment
387
global highlight_files gdttype
388
global searchstring sstring
389
+ global bgcolor fgcolor bglist fglist diffcolors
390
391
menu .bar
392
.bar add cascade -label "File" -menu .bar.file
@@ -446,18 +447,19 @@ proc makewindow {} {
447
.ctop add .ctop.top
448
set canv .ctop.top.clist.canv
449
canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
449
- -bg white -bd 0 \
450
+ -background $bgcolor -bd 0 \
451
-yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
452
.ctop.top.clist add $canv
453
set canv2 .ctop.top.clist.canv2
454
canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
454
- -bg white -bd 0 -yscrollincr $linespc
455
+ -background $bgcolor -bd 0 -yscrollincr $linespc
456
.ctop.top.clist add $canv2
457
set canv3 .ctop.top.clist.canv3
458
canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
458
- -bg white -bd 0 -yscrollincr $linespc
459
+ -background $bgcolor -bd 0 -yscrollincr $linespc
460
.ctop.top.clist add $canv3
461
bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
462
+ lappend bglist $canv $canv2 $canv3
463
464
set sha1entry .ctop.top.bar.sha1
465
set entries $sha1entry
@@ -563,19 +565,22 @@ proc makewindow {} {
565
trace add variable searchstring write incrsearch
566
pack $sstring -side left -expand 1 -fill x
567
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 \
570
-width $geometry(ctextw) -height $geometry(ctexth) \
571
-yscrollcommand scrolltext -wrap none
572
scrollbar .ctop.cdet.left.sb -command "$ctext yview"
573
pack .ctop.cdet.left.sb -side right -fill y
574
pack $ctext -side left -fill both -expand 1
575
.ctop.cdet add .ctop.cdet.left
576
+ lappend bglist $ctext
577
+ lappend fglist $ctext
578
579
$ctext tag conf comment -wrap $wrapcomment
580
$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]
584
$ctext tag conf m0 -fore red
585
$ctext tag conf m1 -fore blue
586
$ctext tag conf m2 -fore green
@@ -608,11 +613,15 @@ proc makewindow {} {
613
pack .ctop.cdet.right.mode -side top -fill x
614
set cflist .ctop.cdet.right.cfiles
615
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 \
619
-tabs [list $indent [expr {2 * $indent}]] \
620
-yscrollcommand ".ctop.cdet.right.sb set" \
621
-cursor [. cget -cursor] \
622
-spacing1 1 -spacing3 1
623
+ lappend bglist $cflist
624
+ lappend fglist $cflist
625
scrollbar .ctop.cdet.right.sb -command "$cflist yview"
626
pack .ctop.cdet.right.sb -side right -fill y
627
pack $cflist -side left -fill both -expand 1
@@ -747,6 +756,7 @@ proc savestuff {w} {
756
global maxwidth showneartags
757
global viewname viewfiles viewargs viewperm nextviewnum
758
global cmitmode wrapcomment
759
+ global colors bgcolor fgcolor diffcolors
760
761
if {$stuffsaved} return
762
if {![winfo viewable .]} return
@@ -761,6 +771,10 @@ proc savestuff {w} {
771
puts $f [list set cmitmode $cmitmode]
772
puts $f [list set wrapcomment $wrapcomment]
773
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]
778
puts $f "set geometry(width) [winfo width .ctop]"
779
puts $f "set geometry(height) [winfo height .ctop]"
780
puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
@@ -2870,11 +2884,11 @@ proc drawlines {id} {
2884
}
2885
2886
proc drawcmittext {id row col rmx} {
2873
- global linespc canv canv2 canv3 canvy0
2887
+ global linespc canv canv2 canv3 canvy0 fgcolor
2888
global commitlisted commitinfo rowidlist
2889
global rowtextx idpos idtags idheads idotherrefs
2890
global linehtag linentag linedtag
2877
- global mainfont canvxmax boldrows boldnamerows
2891
+ global mainfont canvxmax boldrows boldnamerows fgcolor
2892
2893
set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
2894
set x [xc $row $col]
@@ -2882,7 +2896,7 @@ proc drawcmittext {id row col rmx} {
2896
set orad [expr {$linespc / 3}]
2897
set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
2898
[expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
2885
- -fill $ofill -outline black -width 1]
2899
+ -fill $ofill -outline $fgcolor -width 1 -tags circle]
2900
$canv raise $t
2901
$canv bind $t <1> {selcanvline {} %x %y}
2902
set xt [xc $row [llength [lindex $rowidlist $row]]]
@@ -2910,13 +2924,13 @@ proc drawcmittext {id row col rmx} {
2924
lappend nfont bold
2925
}
2926
}
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]
2929
$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]
2934
set xr [expr {$xt + [font measure $mainfont $headline]}]
2935
if {$xr > $canvxmax} {
2936
set canvxmax $xr
@@ -3138,7 +3152,7 @@ proc bindline {t id} {
3152
proc drawtags {id x xt y1} {
3153
global idtags idheads idotherrefs
3154
global linespc lthickness
3141
- global canv mainfont commitrow rowtextx curview
3155
+ global canv mainfont commitrow rowtextx curview fgcolor
3156
3157
set marks {}
3158
set ntags 0
@@ -3201,8 +3215,8 @@ proc drawtags {id x xt y1} {
3215
-width 0 -fill "#ffddaa" -tags tag.$id
3216
}
3217
}
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]]
3220
if {$ntags >= 0} {
3221
$canv bind $t <1> [list showtag $tag 1]
3222
}
@@ -3223,10 +3237,11 @@ proc xcoord {i level ln} {
3237
}
3238
3239
proc show_status {msg} {
3226
- global canv mainfont
3240
+ global canv mainfont fgcolor
3241
3242
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
3245
}
3246
3247
proc finishcommits {} {
@@ -4574,7 +4589,8 @@ proc linehover {} {
4589
set t [$canv create rectangle $x0 $y0 $x1 $y1 \
4590
-fill \#ffff80 -outline black -width 1 -tags hover]
4591
$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]
4594
$canv raise $t
4595
}
4596
@@ -5242,6 +5258,7 @@ proc doquit {} {
5258
proc doprefs {} {
5259
global maxwidth maxgraphpct diffopts
5260
global oldprefs prefstop showneartags
5261
+ global bgcolor fgcolor ctext diffcolors
5262
5263
set top .gitkprefs
5264
set prefstop $top
@@ -5265,6 +5282,7 @@ proc doprefs {} {
5282
-font optionfont
5283
spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
5284
grid x $top.maxpctl $top.maxpct -sticky w
5285
+
5286
label $top.ddisp -text "Diff display options"
5287
grid $top.ddisp - -sticky w -pady 10
5288
label $top.diffoptl -text "Options for diff program" \
@@ -5276,6 +5294,34 @@ proc doprefs {} {
5294
checkbutton $top.ntag.b -variable showneartags
5295
pack $top.ntag.b $top.ntag.l -side left
5296
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
+
5325
frame $top.buts
5326
button $top.buts.ok -text "OK" -command prefsok
5327
button $top.buts.can -text "Cancel" -command prefscan
@@ -5285,6 +5331,35 @@ proc doprefs {} {
5331
grid $top.buts - - -pady 10 -sticky ew
5332
}
5333
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
+
5363
proc prefscan {} {
5364
global maxwidth maxgraphpct diffopts
5365
global oldprefs prefstop showneartags
@@ -5620,6 +5695,9 @@ set wrapcomment "none"
5695
set showneartags 1
5696
5697
set colors {green red blue magenta darkgrey brown orange}
5698
+set bgcolor white
5699
+set fgcolor black
5700
+set diffcolors {red "#00a000" blue}
5701
5702
catch {source ~/.gitk}
5703