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 \
37 -xscrollcommand [list $w.m.sbx
set] \
38 -yscrollcommand [list $w.m.sby
set]
39 label $w.m.s
-text {Working... please wait...
} \
43 scrollbar $w.m.sbx
-command [list $w.m.t xview
] -orient h
44 scrollbar $w.m.sby
-command [list $w.m.t yview
]
45 pack $w.m.l1
-side top
-fill x
46 pack $w.m.s
-side bottom
-fill x
47 pack $w.m.sbx
-side bottom
-fill x
48 pack $w.m.sby
-side right
-fill y
49 pack $w.m.t
-side left
-fill both
-expand 1
50 pack $w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
52 menu $w.ctxm
-tearoff 0
53 $w.ctxm add command
-label "Copy" \
54 -command "tk_textCopy $w.m.t"
55 $w.ctxm add command
-label "Select All" \
56 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
57 $w.ctxm add command
-label "Copy All" \
59 $w.m.t tag add sel 0.0 end
61 $w.m.t tag remove sel 0.0 end
64 button $w.ok
-text {Close
} \
67 pack $w.ok
-side bottom
-anchor e
-pady 10 -padx 10
69 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
70 bind $w.m.t
<$M1B-Key
-a
> "$w.m.t tag add sel 0.0 end;break"
71 bind $w.m.t
<$M1B-Key
-A
> "$w.m.t tag add sel 0.0 end;break"
72 bind $w <Visibility
> "focus $w"
75 method
exec {cmd
{after {}}} {
76 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
77 # But most users need that so we have to relogin. :-(
80 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
83 # -- Tcl won't let us redirect both stdout and stderr to
84 # the same pipe. So pass it through cat...
86 set cmd
[concat |
$cmd |
& cat
]
88 set fd_f
[open $cmd r
]
89 fconfigure $fd_f -blocking 0 -translation binary
90 fileevent $fd_f readable
[cb _read
$fd_f $after]
93 method _read
{fd
after} {
96 if {![winfo exists
$w.m.t
]} {_init
$this}
97 $w.m.t conf
-state normal
99 set n
[string length
$buf]
101 set cr
[string first
"\r" $buf $c]
102 set lf
[string first
"\n" $buf $c]
103 if {$cr < 0} {set cr
[expr {$n + 1}]}
104 if {$lf < 0} {set lf
[expr {$n + 1}]}
107 $w.m.t insert end
[string range
$buf $c $lf]
108 set console_cr
[$w.m.t index
{end
-1c}]
112 $w.m.t delete
$console_cr end
113 $w.m.t insert end
"\n"
114 $w.m.t insert end
[string range
$buf $c $cr]
119 $w.m.t conf
-state disabled
123 fconfigure $fd -blocking 1
125 if {[catch {close $fd}]} {
131 uplevel #0 $after $ok
137 fconfigure $fd -blocking 0
140 method chain
{cmdlist
{ok
1}} {
142 if {[llength $cmdlist] == 0} {
147 set cmd
[lindex $cmdlist 0]
148 set cmdlist
[lrange $cmdlist 1 end
]
150 if {[lindex $cmd 0] eq
{exec}} {
152 [lrange $cmd 1 end
] \
155 uplevel #0 $cmd [cb chain $cmdlist]
164 if {[winfo exists
$w.m.s
]} {
165 $w.m.s conf
-background green
-text {Success
}
166 $w.ok conf
-state normal
170 if {![winfo exists
$w.m.s
]} {
173 $w.m.s conf
-background red
-text {Error
: Command Failed
}
174 $w.ok conf
-state normal