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