︙ | | | ︙ | |
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
}
/* A Tcl/Tk script used to render diff output.
*/
static const char zDiffScript[] =
@ set prog {
@ package require Tk
@
@ array set CFG {
@ TITLE {Fossil Diff}
@ LN_COL_BG #dddddd
@ LN_COL_FG #444444
@ TXT_COL_BG #ffffff
@ TXT_COL_FG #000000
@ MKR_COL_BG #444444
|
|
|
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
}
/* A Tcl/Tk script used to render diff output.
*/
static const char zDiffScript[] =
@ set prog {
@ package require Tk
@
@ array set CFG {
@ TITLE {Fossil Diff}
@ LN_COL_BG #dddddd
@ LN_COL_FG #444444
@ TXT_COL_BG #ffffff
@ TXT_COL_FG #000000
@ MKR_COL_BG #444444
|
︙ | | | ︙ | |
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
@ FN_FG #ffffff
@ FN_PAD 5
@ PADX 5
@ WIDTH 80
@ HEIGHT 45
@ LB_HEIGHT 25
@ }
@
@ if {![namespace exists ttk]} {
@ interp alias {} ::ttk::scrollbar {} ::scrollbar
@ interp alias {} ::ttk::menubutton {} ::menubutton
@ }
@
@ proc dehtml {x} {
@ set x [regsub -all {<[^>]*>} $x {}]
@ return [string map {& & < < > > ' ' " \"} $x]
@ }
@
@ proc cols {} {
@ return [list .lnA .txtA .mkr .lnB .txtB]
@ }
@
@ proc colType {c} {
@ regexp {[a-z]+} $c type
@ return $type
@ }
@
@ proc getLine {difftxt N iivar} {
@ upvar $iivar ii
@ if {$ii>=$N} {return -1}
@ set x [lindex $difftxt $ii]
@ incr ii
@ return $x
@ }
@
@ proc readDiffs {fossilcmd} {
@ global difftxt
@ if {![info exists difftxt]} {
@ set in [open $fossilcmd r]
@ fconfigure $in -encoding utf-8
@ set difftxt [split [read $in] \n]
@ close $in
|
|
|
|
|
|
|
|
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
@ FN_FG #ffffff
@ FN_PAD 5
@ PADX 5
@ WIDTH 80
@ HEIGHT 45
@ LB_HEIGHT 25
@ }
@
@ if {![namespace exists ttk]} {
@ interp alias {} ::ttk::scrollbar {} ::scrollbar
@ interp alias {} ::ttk::menubutton {} ::menubutton
@ }
@
@ proc dehtml {x} {
@ set x [regsub -all {<[^>]*>} $x {}]
@ return [string map {& & < < > > ' ' " \"} $x]
@ }
@
@ proc cols {} {
@ return [list .lnA .txtA .mkr .lnB .txtB]
@ }
@
@ proc colType {c} {
@ regexp {[a-z]+} $c type
@ return $type
@ }
@
@ proc getLine {difftxt N iivar} {
@ upvar $iivar ii
@ if {$ii>=$N} {return -1}
@ set x [lindex $difftxt $ii]
@ incr ii
@ return $x
@ }
@
@ proc readDiffs {fossilcmd} {
@ global difftxt
@ if {![info exists difftxt]} {
@ set in [open $fossilcmd r]
@ fconfigure $in -encoding utf-8
@ set difftxt [split [read $in] \n]
@ close $in
|
︙ | | | ︙ | |
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
|
@ }
@ if {[string compare -length 6 [getLine $difftxt $N ii] "<table"]} {
@ continue
@ }
@ incr nDiffs
@ set idx [expr {$nDiffs > 1 ? [.txtA index end] : "1.0"}]
@ .wfiles.lb insert end $fn
@
@ foreach c [cols] {
@ while {[getLine $difftxt $N ii] ne "<pre>"} continue
@
@ if {$nDiffs > 1} {
@ $c insert end \n -
@ }
@ if {[colType $c] eq "txt"} {
@ $c insert end $fn\n fn
@ if {$fn2!=""} {set fn $fn2}
@ } else {
@ $c insert end \n fn
@ }
@ $c insert end \n -
@
@ set type [colType $c]
@ set str {}
@ while {[set line [getLine $difftxt $N ii]] ne "</pre>"} {
@ set len [string length [dehtml $line]]
@ if {$len > $widths($type)} {
@ set widths($type) $len
@ }
@ append str $line\n
@ }
@
@ set re {<span class="diff([a-z]+)">([^<]*)</span>}
@ # Use \r as separator since it can't appear in the diff output (it gets
@ # converted to a space).
@ set str [regsub -all $re $str "\r\\1\r\\2\r"]
@ foreach {pre class mid} [split $str \r] {
@ if {$class ne ""} {
@ $c insert end [dehtml $pre] - [dehtml $mid] [list $class -]
@ } else {
@ $c insert end [dehtml $pre] -
@ }
@ }
@ }
@ }
@
@ foreach c [cols] {
@ set type [colType $c]
@ if {$type ne "txt"} {
@ $c config -width $widths($type)
@ }
@ $c config -state disabled
@ }
@ if {$nDiffs <= [.wfiles.lb cget -height]} {
@ .wfiles.lb config -height $nDiffs
@ grid remove .wfiles.sb
@ }
@
@ return $nDiffs
@ }
@
@ proc viewDiff {idx} {
@ .txtA yview $idx
@ .txtA xview moveto 0
@ }
@
@ proc cycleDiffs {{reverse 0}} {
@ if {$reverse} {
@ set range [.txtA tag prevrange fn @0,0 1.0]
@ if {$range eq ""} {
@ viewDiff {fn.last -1c}
@ } else {
@ viewDiff [lindex $range 0]
@ }
@ } else {
@ set range [.txtA tag nextrange fn {@0,0 +1c} end]
@ if {$range eq "" || [lindex [.txtA yview] 1] == 1} {
@ viewDiff fn.first
@ } else {
@ viewDiff [lindex $range 0]
@ }
@ }
@ }
@
@ proc xvis {col} {
@ set view [$col xview]
@ return [expr {[lindex $view 1]-[lindex $view 0]}]
@ }
@
@ proc scroll-x {args} {
@ set c .txt[expr {[xvis .txtA] < [xvis .txtB] ? "A" : "B"}]
@ eval $c xview $args
@ }
@
@ interp alias {} scroll-y {} .txtA yview
@
@ proc noop {args} {}
@
@ proc enableSync {axis} {
@ update idletasks
@ interp alias {} sync-$axis {}
@ rename _sync-$axis sync-$axis
@ }
@
@ proc disableSync {axis} {
@ rename sync-$axis _sync-$axis
@ interp alias {} sync-$axis {} noop
@ }
@
@ proc sync-x {col first last} {
@ disableSync x
@ $col xview moveto [expr {$first*[xvis $col]/($last-$first)}]
@ foreach side {A B} {
@ set sb .sbx$side
@ set xview [.txt$side xview]
@ if {[lindex $xview 0] > 0 || [lindex $xview 1] < 1} {
@ grid $sb
@ eval $sb set $xview
@ } else {
@ grid remove $sb
@ }
@ }
@ enableSync x
@ }
@
@ proc sync-y {first last} {
@ disableSync y
@ foreach c [cols] {
@ $c yview moveto $first
@ }
@ if {$first > 0 || $last < 1} {
@ grid .sby
@ .sby set $first $last
@ } else {
@ grid remove .sby
@ }
@ enableSync y
@ }
@
@ wm withdraw .
@ wm title . $CFG(TITLE)
@ wm iconname . $CFG(TITLE)
@ bind . <q> exit
@ bind . <Destroy> {after 0 exit}
@ bind . <Tab> {cycleDiffs; break}
@ bind . <<PrevWindow>> {cycleDiffs 1; break}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
|
@ }
@ if {[string compare -length 6 [getLine $difftxt $N ii] "<table"]} {
@ continue
@ }
@ incr nDiffs
@ set idx [expr {$nDiffs > 1 ? [.txtA index end] : "1.0"}]
@ .wfiles.lb insert end $fn
@
@ foreach c [cols] {
@ while {[getLine $difftxt $N ii] ne "<pre>"} continue
@
@ if {$nDiffs > 1} {
@ $c insert end \n -
@ }
@ if {[colType $c] eq "txt"} {
@ $c insert end $fn\n fn
@ if {$fn2!=""} {set fn $fn2}
@ } else {
@ $c insert end \n fn
@ }
@ $c insert end \n -
@
@ set type [colType $c]
@ set str {}
@ while {[set line [getLine $difftxt $N ii]] ne "</pre>"} {
@ set len [string length [dehtml $line]]
@ if {$len > $widths($type)} {
@ set widths($type) $len
@ }
@ append str $line\n
@ }
@
@ set re {<span class="diff([a-z]+)">([^<]*)</span>}
@ # Use \r as separator since it can't appear in the diff output (it gets
@ # converted to a space).
@ set str [regsub -all $re $str "\r\\1\r\\2\r"]
@ foreach {pre class mid} [split $str \r] {
@ if {$class ne ""} {
@ $c insert end [dehtml $pre] - [dehtml $mid] [list $class -]
@ } else {
@ $c insert end [dehtml $pre] -
@ }
@ }
@ }
@ }
@
@ foreach c [cols] {
@ set type [colType $c]
@ if {$type ne "txt"} {
@ $c config -width $widths($type)
@ }
@ $c config -state disabled
@ }
@ if {$nDiffs <= [.wfiles.lb cget -height]} {
@ .wfiles.lb config -height $nDiffs
@ grid remove .wfiles.sb
@ }
@
@ return $nDiffs
@ }
@
@ proc viewDiff {idx} {
@ .txtA yview $idx
@ .txtA xview moveto 0
@ }
@
@ proc cycleDiffs {{reverse 0}} {
@ if {$reverse} {
@ set range [.txtA tag prevrange fn @0,0 1.0]
@ if {$range eq ""} {
@ viewDiff {fn.last -1c}
@ } else {
@ viewDiff [lindex $range 0]
@ }
@ } else {
@ set range [.txtA tag nextrange fn {@0,0 +1c} end]
@ if {$range eq "" || [lindex [.txtA yview] 1] == 1} {
@ viewDiff fn.first
@ } else {
@ viewDiff [lindex $range 0]
@ }
@ }
@ }
@
@ proc xvis {col} {
@ set view [$col xview]
@ return [expr {[lindex $view 1]-[lindex $view 0]}]
@ }
@
@ proc scroll-x {args} {
@ set c .txt[expr {[xvis .txtA] < [xvis .txtB] ? "A" : "B"}]
@ eval $c xview $args
@ }
@
@ interp alias {} scroll-y {} .txtA yview
@
@ proc noop {args} {}
@
@ proc enableSync {axis} {
@ update idletasks
@ interp alias {} sync-$axis {}
@ rename _sync-$axis sync-$axis
@ }
@
@ proc disableSync {axis} {
@ rename sync-$axis _sync-$axis
@ interp alias {} sync-$axis {} noop
@ }
@
@ proc sync-x {col first last} {
@ disableSync x
@ $col xview moveto [expr {$first*[xvis $col]/($last-$first)}]
@ foreach side {A B} {
@ set sb .sbx$side
@ set xview [.txt$side xview]
@ if {[lindex $xview 0] > 0 || [lindex $xview 1] < 1} {
@ grid $sb
@ eval $sb set $xview
@ } else {
@ grid remove $sb
@ }
@ }
@ enableSync x
@ }
@
@ proc sync-y {first last} {
@ disableSync y
@ foreach c [cols] {
@ $c yview moveto $first
@ }
@ if {$first > 0 || $last < 1} {
@ grid .sby
@ .sby set $first $last
@ } else {
@ grid remove .sby
@ }
@ enableSync y
@ }
@
@ wm withdraw .
@ wm title . $CFG(TITLE)
@ wm iconname . $CFG(TITLE)
@ bind . <q> exit
@ bind . <Destroy> {after 0 exit}
@ bind . <Tab> {cycleDiffs; break}
@ bind . <<PrevWindow>> {cycleDiffs 1; break}
|
︙ | | | ︙ | |
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
|
@ Next y {scroll 1 page}
@ Home y {moveto 0}
@ End y {moveto 1}
@ } {
@ bind . <$key> "scroll-$axis $args; break"
@ bind . <Shift-$key> continue
@ }
@
@ frame .bb
@ ::ttk::menubutton .bb.files -text "Files"
@ toplevel .wfiles
@ wm withdraw .wfiles
@ update idletasks
@ wm transient .wfiles .
@ wm overrideredirect .wfiles 1
|
|
|
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
|
@ Next y {scroll 1 page}
@ Home y {moveto 0}
@ End y {moveto 1}
@ } {
@ bind . <$key> "scroll-$axis $args; break"
@ bind . <Shift-$key> continue
@ }
@
@ frame .bb
@ ::ttk::menubutton .bb.files -text "Files"
@ toplevel .wfiles
@ wm withdraw .wfiles
@ update idletasks
@ wm transient .wfiles .
@ wm overrideredirect .wfiles 1
|
︙ | | | ︙ | |
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
|
@ break
@ }
@ }
@ bind .wfiles.lb <Motion> {
@ %W selection clear 0 end
@ %W selection set @%x,%y
@ }
@
@ foreach {side syncCol} {A .txtB B .txtA} {
@ set ln .ln$side
@ text $ln
@ $ln tag config - -justify right
@
@ set txt .txt$side
@ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \
@ -xscroll "sync-x $syncCol"
@ catch {$txt config -tabstyle wordprocessor} ;# Required for Tk>=8.5
@ foreach tag {add rm chng} {
@ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
@ $txt tag lower $tag
@ }
@ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
@ -justify center
@ }
@ text .mkr
@
@ foreach c [cols] {
@ set keyPrefix [string toupper [colType $c]]_COL_
@ if {[tk windowingsystem] eq "win32"} {$c config -font {courier 9}}
@ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
@ -padx $CFG(PADX) -yscroll sync-y
@ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
@ -foreground $CFG(HR_FG)
@ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
@ bindtags $c ". $c Text all"
@ bind $c <1> {focus %W}
@ }
@
@ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
@ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
@ ::ttk::scrollbar .sbxB -command {.txtB xview} -orient horizontal
@ frame .spacer
@
@ if {[readDiffs $fossilcmd] == 0} {
@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
@ exit
@ }
@ update idletasks
@
@ proc saveDiff {} {
@ set fn [tk_getSaveFile]
@ set out [open $fn wb]
@ puts $out "#!/usr/bin/tclsh\n#\n# Run this script using 'tclsh' or 'wish'"
@ puts $out "# to see the graphical diff.\n#"
@ puts $out "set fossilcmd {}"
@ puts $out "set prog [list $::prog]"
|
|
|
|
|
|
|
|
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
|
@ break
@ }
@ }
@ bind .wfiles.lb <Motion> {
@ %W selection clear 0 end
@ %W selection set @%x,%y
@ }
@
@ foreach {side syncCol} {A .txtB B .txtA} {
@ set ln .ln$side
@ text $ln
@ $ln tag config - -justify right
@
@ set txt .txt$side
@ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \
@ -xscroll "sync-x $syncCol"
@ catch {$txt config -tabstyle wordprocessor} ;# Required for Tk>=8.5
@ foreach tag {add rm chng} {
@ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
@ $txt tag lower $tag
@ }
@ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
@ -justify center
@ }
@ text .mkr
@
@ foreach c [cols] {
@ set keyPrefix [string toupper [colType $c]]_COL_
@ if {[tk windowingsystem] eq "win32"} {$c config -font {courier 9}}
@ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
@ -padx $CFG(PADX) -yscroll sync-y
@ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
@ -foreground $CFG(HR_FG)
@ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
@ bindtags $c ". $c Text all"
@ bind $c <1> {focus %W}
@ }
@
@ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
@ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
@ ::ttk::scrollbar .sbxB -command {.txtB xview} -orient horizontal
@ frame .spacer
@
@ if {[readDiffs $fossilcmd] == 0} {
@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
@ exit
@ }
@ update idletasks
@
@ proc saveDiff {} {
@ set fn [tk_getSaveFile]
@ set out [open $fn wb]
@ puts $out "#!/usr/bin/tclsh\n#\n# Run this script using 'tclsh' or 'wish'"
@ puts $out "# to see the graphical diff.\n#"
@ puts $out "set fossilcmd {}"
@ puts $out "set prog [list $::prog]"
|
︙ | | | ︙ | |
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
@ grid columnconfigure . 4 -weight 1
@ grid .bb -row 0 -columnspan 6
@ eval grid [cols] -row 1 -sticky nsew
@ grid .sby -row 1 -column 5 -sticky ns
@ grid .sbxA -row 2 -columnspan 2 -sticky ew
@ grid .spacer -row 2 -column 2
@ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
@
@ .spacer config -height [winfo height .sbxA]
@ wm deiconify .
@ }
@ eval $prog
;
/*
|
|
|
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
@ grid columnconfigure . 4 -weight 1
@ grid .bb -row 0 -columnspan 6
@ eval grid [cols] -row 1 -sticky nsew
@ grid .sby -row 1 -column 5 -sticky ns
@ grid .sbxA -row 2 -columnspan 2 -sticky ew
@ grid .spacer -row 2 -column 2
@ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
@
@ .spacer config -height [winfo height .sbxA]
@ wm deiconify .
@ }
@ eval $prog
;
/*
|
︙ | | | ︙ | |