You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
4.7 KiB
224 lines
4.7 KiB
18 years ago
|
# git-gui console support
|
||
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
||
|
|
||
18 years ago
|
class console {
|
||
|
|
||
|
field t_short
|
||
|
field t_long
|
||
|
field w
|
||
18 years ago
|
field w_t
|
||
18 years ago
|
field console_cr
|
||
18 years ago
|
field is_toplevel 1; # are we our own window?
|
||
18 years ago
|
|
||
|
constructor new {short_title long_title} {
|
||
|
set t_short $short_title
|
||
|
set t_long $long_title
|
||
|
_init $this
|
||
|
return $this
|
||
18 years ago
|
}
|
||
|
|
||
18 years ago
|
constructor embed {path title} {
|
||
|
set t_short {}
|
||
|
set t_long $title
|
||
|
set w $path
|
||
|
set is_toplevel 0
|
||
|
_init $this
|
||
|
return $this
|
||
|
}
|
||
|
|
||
18 years ago
|
method _init {} {
|
||
15 years ago
|
global M1B use_ttk NS
|
||
18 years ago
|
|
||
|
if {$is_toplevel} {
|
||
15 years ago
|
make_dialog top w -autodelete 0
|
||
18 years ago
|
wm title $top "[appname] ([reponame]): $t_short"
|
||
|
} else {
|
||
15 years ago
|
${NS}::frame $w
|
||
18 years ago
|
}
|
||
|
|
||
18 years ago
|
set console_cr 1.0
|
||
18 years ago
|
set w_t $w.m.t
|
||
18 years ago
|
|
||
15 years ago
|
${NS}::frame $w.m
|
||
|
${NS}::label $w.m.l1 \
|
||
18 years ago
|
-textvariable @t_long \
|
||
18 years ago
|
-anchor w \
|
||
|
-justify left \
|
||
|
-font font_uibold
|
||
18 years ago
|
text $w_t \
|
||
17 years ago
|
-background white \
|
||
|
-foreground black \
|
||
|
-borderwidth 1 \
|
||
18 years ago
|
-relief sunken \
|
||
|
-width 80 -height 10 \
|
||
18 years ago
|
-wrap none \
|
||
18 years ago
|
-font font_diff \
|
||
|
-state disabled \
|
||
18 years ago
|
-xscrollcommand [cb _sb_set $w.m.sbx h] \
|
||
|
-yscrollcommand [cb _sb_set $w.m.sby v]
|
||
18 years ago
|
label $w.m.s -text [mc "Working... please wait..."] \
|
||
18 years ago
|
-anchor w \
|
||
|
-justify left \
|
||
|
-font font_uibold
|
||
|
pack $w.m.l1 -side top -fill x
|
||
|
pack $w.m.s -side bottom -fill x
|
||
18 years ago
|
pack $w_t -side left -fill both -expand 1
|
||
18 years ago
|
pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
|
||
|
|
||
|
menu $w.ctxm -tearoff 0
|
||
18 years ago
|
$w.ctxm add command -label [mc "Copy"] \
|
||
18 years ago
|
-command "tk_textCopy $w_t"
|
||
18 years ago
|
$w.ctxm add command -label [mc "Select All"] \
|
||
18 years ago
|
-command "focus $w_t;$w_t tag add sel 0.0 end"
|
||
18 years ago
|
$w.ctxm add command -label [mc "Copy All"] \
|
||
18 years ago
|
-command "
|
||
18 years ago
|
$w_t tag add sel 0.0 end
|
||
|
tk_textCopy $w_t
|
||
|
$w_t tag remove sel 0.0 end
|
||
18 years ago
|
"
|
||
|
|
||
18 years ago
|
if {$is_toplevel} {
|
||
15 years ago
|
${NS}::button $w.ok -text [mc "Close"] \
|
||
18 years ago
|
-state disabled \
|
||
|
-command [list destroy $w]
|
||
|
pack $w.ok -side bottom -anchor e -pady 10 -padx 10
|
||
|
bind $w <Visibility> [list focus $w]
|
||
|
}
|
||
18 years ago
|
|
||
18 years ago
|
bind_button3 $w_t "tk_popup $w.ctxm %X %Y"
|
||
|
bind $w_t <$M1B-Key-a> "$w_t tag add sel 0.0 end;break"
|
||
|
bind $w_t <$M1B-Key-A> "$w_t tag add sel 0.0 end;break"
|
||
18 years ago
|
}
|
||
|
|
||
18 years ago
|
method exec {cmd {after {}}} {
|
||
18 years ago
|
if {[lindex $cmd 0] eq {git}} {
|
||
|
set fd_f [eval git_read --stderr [lrange $cmd 1 end]]
|
||
|
} else {
|
||
|
lappend cmd 2>@1
|
||
|
set fd_f [_open_stdout_stderr $cmd]
|
||
18 years ago
|
}
|
||
|
fconfigure $fd_f -blocking 0 -translation binary
|
||
18 years ago
|
fileevent $fd_f readable [cb _read $fd_f $after]
|
||
18 years ago
|
}
|
||
|
|
||
18 years ago
|
method _read {fd after} {
|
||
18 years ago
|
set buf [read $fd]
|
||
|
if {$buf ne {}} {
|
||
18 years ago
|
if {![winfo exists $w_t]} {_init $this}
|
||
|
$w_t conf -state normal
|
||
18 years ago
|
set c 0
|
||
|
set n [string length $buf]
|
||
|
while {$c < $n} {
|
||
|
set cr [string first "\r" $buf $c]
|
||
|
set lf [string first "\n" $buf $c]
|
||
|
if {$cr < 0} {set cr [expr {$n + 1}]}
|
||
|
if {$lf < 0} {set lf [expr {$n + 1}]}
|
||
|
|
||
|
if {$lf < $cr} {
|
||
18 years ago
|
$w_t insert end [string range $buf $c $lf]
|
||
|
set console_cr [$w_t index {end -1c}]
|
||
18 years ago
|
set c $lf
|
||
|
incr c
|
||
|
} else {
|
||
18 years ago
|
$w_t delete $console_cr end
|
||
|
$w_t insert end "\n"
|
||
17 years ago
|
$w_t insert end [string range $buf $c [expr {$cr - 1}]]
|
||
18 years ago
|
set c $cr
|
||
|
incr c
|
||
|
}
|
||
|
}
|
||
18 years ago
|
$w_t conf -state disabled
|
||
|
$w_t see end
|
||
18 years ago
|
}
|
||
|
|
||
|
fconfigure $fd -blocking 1
|
||
|
if {[eof $fd]} {
|
||
|
if {[catch {close $fd}]} {
|
||
|
set ok 0
|
||
|
} else {
|
||
|
set ok 1
|
||
|
}
|
||
18 years ago
|
if {$after ne {}} {
|
||
18 years ago
|
uplevel #0 $after $ok
|
||
18 years ago
|
} else {
|
||
18 years ago
|
done $this $ok
|
||
18 years ago
|
}
|
||
18 years ago
|
return
|
||
|
}
|
||
|
fconfigure $fd -blocking 0
|
||
|
}
|
||
|
|
||
18 years ago
|
method chain {cmdlist {ok 1}} {
|
||
18 years ago
|
if {$ok} {
|
||
|
if {[llength $cmdlist] == 0} {
|
||
18 years ago
|
done $this $ok
|
||
18 years ago
|
return
|
||
|
}
|
||
|
|
||
|
set cmd [lindex $cmdlist 0]
|
||
|
set cmdlist [lrange $cmdlist 1 end]
|
||
|
|
||
18 years ago
|
if {[lindex $cmd 0] eq {exec}} {
|
||
18 years ago
|
exec $this \
|
||
|
[lrange $cmd 1 end] \
|
||
|
[cb chain $cmdlist]
|
||
18 years ago
|
} else {
|
||
18 years ago
|
uplevel #0 $cmd [cb chain $cmdlist]
|
||
18 years ago
|
}
|
||
|
} else {
|
||
18 years ago
|
done $this $ok
|
||
18 years ago
|
}
|
||
|
}
|
||
|
|
||
18 years ago
|
method insert {txt} {
|
||
18 years ago
|
if {![winfo exists $w_t]} {_init $this}
|
||
|
$w_t conf -state normal
|
||
|
$w_t insert end "$txt\n"
|
||
|
set console_cr [$w_t index {end -1c}]
|
||
|
$w_t conf -state disabled
|
||
18 years ago
|
}
|
||
|
|
||
18 years ago
|
method done {ok} {
|
||
18 years ago
|
if {$ok} {
|
||
18 years ago
|
if {[winfo exists $w.m.s]} {
|
||
18 years ago
|
bind $w.m.s <Destroy> [list delete_this $this]
|
||
17 years ago
|
$w.m.s conf -background green -foreground black \
|
||
|
-text [mc "Success"]
|
||
18 years ago
|
if {$is_toplevel} {
|
||
|
$w.ok conf -state normal
|
||
|
focus $w.ok
|
||
|
}
|
||
18 years ago
|
} else {
|
||
|
delete_this
|
||
18 years ago
|
}
|
||
|
} else {
|
||
18 years ago
|
if {![winfo exists $w.m.s]} {
|
||
|
_init $this
|
||
18 years ago
|
}
|
||
18 years ago
|
bind $w.m.s <Destroy> [list delete_this $this]
|
||
17 years ago
|
$w.m.s conf -background red -foreground black \
|
||
|
-text [mc "Error: Command Failed"]
|
||
18 years ago
|
if {$is_toplevel} {
|
||
|
$w.ok conf -state normal
|
||
|
focus $w.ok
|
||
|
}
|
||
18 years ago
|
}
|
||
|
}
|
||
18 years ago
|
|
||
18 years ago
|
method _sb_set {sb orient first last} {
|
||
15 years ago
|
global NS
|
||
18 years ago
|
if {![winfo exists $sb]} {
|
||
18 years ago
|
if {$first == $last || ($first == 0 && $last == 1)} return
|
||
18 years ago
|
if {$orient eq {h}} {
|
||
15 years ago
|
${NS}::scrollbar $sb -orient h -command [list $w_t xview]
|
||
18 years ago
|
pack $sb -fill x -side bottom -before $w_t
|
||
|
} else {
|
||
15 years ago
|
${NS}::scrollbar $sb -orient v -command [list $w_t yview]
|
||
18 years ago
|
pack $sb -fill y -side right -before $w_t
|
||
|
}
|
||
|
}
|
||
18 years ago
|
$sb set $first $last
|
||
18 years ago
|
}
|
||
|
|
||
18 years ago
|
}
|