1 # git-gui console support
2 # Copyright (C) 2006, 2007 Shawn Pearce
11 constructor new {short_title long_title} {
12 set t_short $short_title
13 set t_long $long_title
20 make_toplevel top w -autodelete 0
21 wm title $top "[appname] ([reponame]): $t_short"
26 -textvariable @t_long \
31 -background white -borderwidth 1 \
33 -width 80 -height 10 \
36 -yscrollcommand [list $w.m.sby set]
37 label $w.m.s -text {Working... please wait...} \
41 scrollbar $w.m.sby -command [list $w.m.t yview]
42 pack $w.m.l1 -side top -fill x
43 pack $w.m.s -side bottom -fill x
44 pack $w.m.sby -side right -fill y
45 pack $w.m.t -side left -fill both -expand 1
46 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
48 menu $w.ctxm -tearoff 0
49 $w.ctxm add command -label "Copy" \
50 -command "tk_textCopy $w.m.t"
51 $w.ctxm add command -label "Select All" \
52 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
53 $w.ctxm add command -label "Copy All" \
55 $w.m.t tag add sel 0.0 end
57 $w.m.t tag remove sel 0.0 end
60 button $w.ok -text {Close} \
63 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
65 bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
66 bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
67 bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
68 bind $w <Visibility> "focus $w"
71 method exec {cmd {after {}}} {
72 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
73 # But most users need that so we have to relogin. :-(
76 set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
79 # -- Tcl won't let us redirect both stdout and stderr to
80 # the same pipe. So pass it through cat...
82 set cmd [concat | $cmd |& cat]
84 set fd_f [open $cmd r]
85 fconfigure $fd_f -blocking 0 -translation binary
86 fileevent $fd_f readable [cb _read $fd_f $after]
89 method _read {fd after} {
92 if {![winfo exists $w.m.t]} {_init $this}
93 $w.m.t conf -state normal
95 set n [string length $buf]
97 set cr [string first "\r" $buf $c]
98 set lf [string first "\n" $buf $c]
99 if {$cr < 0} {set cr [expr {$n + 1}]}
100 if {$lf < 0} {set lf [expr {$n + 1}]}
103 $w.m.t insert end [string range $buf $c $lf]
104 set console_cr [$w.m.t index {end -1c}]
108 $w.m.t delete $console_cr end
109 $w.m.t insert end "\n"
110 $w.m.t insert end [string range $buf $c $cr]
115 $w.m.t conf -state disabled
119 fconfigure $fd -blocking 1
121 if {[catch {close $fd}]} {
127 uplevel #0 $after $ok
133 fconfigure $fd -blocking 0
136 method chain {cmdlist {ok 1}} {
138 if {[llength $cmdlist] == 0} {
143 set cmd [lindex $cmdlist 0]
144 set cmdlist [lrange $cmdlist 1 end]
146 if {[lindex $cmd 0] eq {exec}} {
148 [lrange $cmd 1 end] \
151 uplevel #0 $cmd [cb chain $cmdlist]
160 if {[winfo exists $w.m.s]} {
161 $w.m.s conf -background green -text {Success}
162 $w.ok conf -state normal
166 if {![winfo exists $w.m.s]} {
169 $w.m.s conf -background red -text {Error: Command Failed}
170 $w.ok conf -state normal