git-gui: Automatically reopen any console closed by the user.
If the user closes a console and we get more ouptut for it then we will get a Tcl error in the readable event handle for the file channel. Since this loses the actual output and is quite unfriendly to the end user instead reopen any console which the user closed prior to the additional output arriving. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 7, 2006 at 04:19 UTC
37af79d10d980418eaeca953c4ba1c08a85d37e9
1 file changed
+43
-31
git-gui
+43
-31
@@ -1005,14 +1005,20 @@ proc hook_failed_popup {hook msg} {
1005
set next_console_id 0
1006
1007
proc new_console {short_title long_title} {
1008
- global next_console_id console_cr
1008
+ global next_console_id console_data
1009
+ set w .console[incr next_console_id]
1010
+ set console_data($w) [list $short_title $long_title]
1011
+ return [console_init $w]
1012
+}
1013
+
1014
+proc console_init {w} {
1015
+ global console_cr console_data
1016
global gitdir appname mainfont difffont
1017
1011
- set w .console[incr next_console_id]
1018
set console_cr($w) 1.0
1019
toplevel $w
1020
frame $w.m
1015
- label $w.m.l1 -text "$long_title:" \
1021
+ label $w.m.l1 -text "[lindex $console_data($w) 1]:" \
1022
-anchor w \
1023
-justify left \
1024
-font [concat $mainfont bold]
@@ -1041,8 +1047,7 @@ proc new_console {short_title long_title} {
1047
pack $w.ok -side bottom
1048
1049
bind $w <Visibility> "focus $w"
1044
- bind $w <Destroy> break
1045
- wm title $w "$appname ([file dirname [file normalize [file dirname $gitdir]]]): $short_title"
1050
+ wm title $w "$appname ([file dirname [file normalize [file dirname $gitdir]]]): [lindex $console_data($w) 0]"
1051
return $w
1052
}
1053
@@ -1067,44 +1072,51 @@ proc console_exec {w cmd} {
1072
}
1073
1074
proc console_read {w fd} {
1070
- global console_cr
1075
+ global console_cr console_data
1076
1072
- $w.m.t conf -state normal
1077
set buf [read $fd]
1074
- set c 0
1075
- set n [string length $buf]
1076
- while {$c < $n} {
1077
- set cr [string first "\r" $buf $c]
1078
- set lf [string first "\n" $buf $c]
1079
- if {$cr < 0} {set cr [expr $n + 1]}
1080
- if {$lf < 0} {set lf [expr $n + 1]}
1081
-
1082
- if {$lf < $cr} {
1083
- $w.m.t insert end [string range $buf $c $lf]
1084
- set console_cr($w) [$w.m.t index {end -1c}]
1085
- set c $lf
1086
- incr c
1087
- } else {
1088
- $w.m.t delete $console_cr($w) end
1089
- $w.m.t insert end "\n"
1090
- $w.m.t insert end [string range $buf $c $cr]
1091
- set c $cr
1092
- incr c
1078
+ if {$buf != {}} {
1079
+ if {![winfo exists $w]} {console_init $w}
1080
+ $w.m.t conf -state normal
1081
+ set c 0
1082
+ set n [string length $buf]
1083
+ while {$c < $n} {
1084
+ set cr [string first "\r" $buf $c]
1085
+ set lf [string first "\n" $buf $c]
1086
+ if {$cr < 0} {set cr [expr $n + 1]}
1087
+ if {$lf < 0} {set lf [expr $n + 1]}
1088
+
1089
+ if {$lf < $cr} {
1090
+ $w.m.t insert end [string range $buf $c $lf]
1091
+ set console_cr($w) [$w.m.t index {end -1c}]
1092
+ set c $lf
1093
+ incr c
1094
+ } else {
1095
+ $w.m.t delete $console_cr($w) end
1096
+ $w.m.t insert end "\n"
1097
+ $w.m.t insert end [string range $buf $c $cr]
1098
+ set c $cr
1099
+ incr c
1100
+ }
1101
}
1102
+ $w.m.t conf -state disabled
1103
+ $w.m.t see end
1104
}
1095
- $w.m.t conf -state disabled
1096
- $w.m.t see end
1105
1106
fconfigure $fd -blocking 1
1107
if {[eof $fd]} {
1108
if {[catch {close $fd}]} {
1109
+ if {![winfo exists $w]} {console_init $w}
1110
$w.m.s conf -background red -text {Error: Command Failed}
1102
- } else {
1111
+ $w.ok conf -text Close
1112
+ $w.ok conf -state normal
1113
+ } elseif {[winfo exists $w]} {
1114
$w.m.s conf -background green -text {Success}
1115
+ $w.ok conf -text Close
1116
+ $w.ok conf -state normal
1117
}
1105
- $w.ok conf -text Close
1106
- $w.ok conf -state normal
1118
array unset console_cr $w
1119
+ array unset console_data $w
1120
return
1121
}
1122
fconfigure $fd -blocking 0