@matheusbsbs / matheus-bagliano / commits / ee3dc9354d
Fork 0

git-gui: Correctly handle CR vs. LF within the console of fetch.

Because the remote end is likely to send us progress meters by resetting each line with a CR (and no LF) we should display those meters by replacing the last line of text with the next line, just like a normal xterm would do. This makes the output of fetch look about the same as if we ran it from within an xterm. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 7, 2006 at 02:18 UTC ee3dc9354d23b1262fb9c71c648435e0ccf01d7e
1 file changed +30 -6
git-gui
+30 -6
@@ -1002,9 +1002,11 @@ proc hook_failed_popup {hook msg} {
1002 set next_console_id 0
1003
1004 proc new_console {short_title long_title} {
1005 - global next_console_id gitdir appname mainfont difffont
1005 + global next_console_id console_cr
1006 + global gitdir appname mainfont difffont
1007
1008 set w .console[incr next_console_id]
1009 + set console_cr($w) 1.0
1010 toplevel $w
1011 frame $w.m
1012 label $w.m.l1 -text "$long_title:" \
@@ -1024,7 +1026,7 @@ proc new_console {short_title long_title} {
1026 pack $w.m.t -side left -fill both -expand 1
1027 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
1028
1027 - button $w.ok -text {OK} \
1029 + button $w.ok -text {Running...} \
1030 -width 15 \
1031 -font $mainfont \
1032 -state disabled \
@@ -1053,22 +1055,44 @@ proc console_exec {w cmd} {
1055 set cmd [concat | $cmd |& cat]
1056
1057 set fd_f [open $cmd r]
1056 - fconfigure $fd_f -blocking 0 -translation auto
1058 + fconfigure $fd_f -blocking 0 -translation binary
1059 fileevent $fd_f readable [list console_read $w $fd_f]
1060 }
1061
1062 proc console_read {w fd} {
1063 + global console_cr
1064 +
1065 $w.m.t conf -state normal
1062 - while {[gets $fd line] >= 0} {
1063 - $w.m.t insert end $line
1064 - $w.m.t insert end "\n"
1066 + set buf [read $fd]
1067 + set c 0
1068 + set n [string length $buf]
1069 + while {$c < $n} {
1070 + set cr [string first "\r" $buf $c]
1071 + set lf [string first "\n" $buf $c]
1072 + if {$cr < 0} {set cr [expr $n + 1]}
1073 + if {$lf < 0} {set lf [expr $n + 1]}
1074 +
1075 + if {$lf < $cr} {
1076 + $w.m.t insert end [string range $buf $c $lf]
1077 + set console_cr($w) [$w.m.t index {end -1c}]
1078 + set c $lf
1079 + incr c
1080 + } else {
1081 + $w.m.t delete $console_cr($w) end
1082 + $w.m.t insert end "\n"
1083 + $w.m.t insert end [string range $buf $c $cr]
1084 + set c $cr
1085 + incr c
1086 + }
1087 }
1088 $w.m.t conf -state disabled
1089 $w.m.t see end
1090
1091 if {[eof $fd]} {
1092 close $fd
1093 + $w.ok conf -text Close
1094 $w.ok conf -state normal
1095 + array unset console_cr $w
1096 }
1097 }
1098