rebase -i: teach --onto A...B syntax
[git.git] / git-gui / lib / status_bar.tcl
blob51d4177551b911c35cfd8004a36fca4259367d24
1 # git-gui status bar mega-widget
2 # Copyright (C) 2007 Shawn Pearce
4 class status_bar {
6 field w ; # our own window path
7 field w_l ; # text widget we draw messages into
8 field w_c ; # canvas we draw a progress bar into
9 field c_pack ; # script to pack the canvas with
10 field status {}; # single line of text we show
11 field prefix {}; # text we format into status
12 field units {}; # unit of progress
13 field meter {}; # current core git progress meter (if active)
15 constructor new {path} {
16 set w $path
17 set w_l $w.l
18 set w_c $w.c
20 frame $w \
21 -borderwidth 1 \
22 -relief sunken
23 label $w_l \
24 -textvariable @status \
25 -anchor w \
26 -justify left
27 pack $w_l -side left
28 set c_pack [cb _oneline_pack]
30 bind $w <Destroy> [cb _delete %W]
31 return $this
34 method _oneline_pack {} {
35 $w_c conf -width 100
36 pack $w_c -side right
39 constructor two_line {path} {
40 set w $path
41 set w_l $w.l
42 set w_c $w.c
44 frame $w
45 label $w_l \
46 -textvariable @status \
47 -anchor w \
48 -justify left
49 pack $w_l -anchor w -fill x
50 set c_pack [list pack $w_c -fill x]
52 bind $w <Destroy> [cb _delete %W]
53 return $this
56 method start {msg uds} {
57 if {[winfo exists $w_c]} {
58 $w_c coords bar 0 0 0 20
59 } else {
60 canvas $w_c \
61 -height [expr {int([winfo reqheight $w_l] * 0.6)}] \
62 -borderwidth 1 \
63 -relief groove \
64 -highlightt 0
65 $w_c create rectangle 0 0 0 20 -tags bar -fill navy
66 eval $c_pack
69 set status $msg
70 set prefix $msg
71 set units $uds
72 set meter {}
75 method update {have total} {
76 set pdone 0
77 if {$total > 0} {
78 set pdone [expr {100 * $have / $total}]
79 set cdone [expr {[winfo width $w_c] * $have / $total}]
82 set prec [string length [format %i $total]]
83 set status [mc "%s ... %*i of %*i %s (%3i%%)" \
84 $prefix \
85 $prec $have \
86 $prec $total \
87 $units $pdone]
88 $w_c coords bar 0 0 $cdone 20
91 method update_meter {buf} {
92 append meter $buf
93 set r [string last "\r" $meter]
94 if {$r == -1} {
95 return
98 set prior [string range $meter 0 $r]
99 set meter [string range $meter [expr {$r + 1}] end]
100 set p "\\((\\d+)/(\\d+)\\)"
101 if {[regexp ":\\s*\\d+% $p\(?:, done.\\s*\n|\\s*\r)\$" $prior _j a b]} {
102 update $this $a $b
103 } elseif {[regexp "$p\\s+done\r\$" $prior _j a b]} {
104 update $this $a $b
108 method stop {{msg {}}} {
109 destroy $w_c
110 if {$msg ne {}} {
111 set status $msg
115 method show {msg {test {}}} {
116 if {$test eq {} || $status eq $test} {
117 set status $msg
121 method _delete {current} {
122 if {$current eq $w} {
123 delete_this