diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-05-08 07:36:31 +0400 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2007-05-08 07:51:00 +0400 |
commit | 5f5dbd719d0d8ec136f32a0a56674902bd85f72f (patch) | |
tree | f5898a282daf34722256709c7ac2ac7f78f9bbb7 /git-gui/lib/console.tcl | |
parent | 3082acfa7c626a34aa419a163585051c2df2bf09 (diff) | |
parent | ebcaadabcb90eaf35a3bd69a50cccce4be4dcc2c (diff) |
Merge branch 'master' of git://repo.or.cz/git-gui
* 'master' of git://repo.or.cz/git-gui:
git-gui: Use vi-like keys in merge dialog
git-gui: Include commit id/subject in merge choices
git-gui: Show all possible branches for merge
git-gui: Move merge support into a namespace
git-gui: Allow vi keys to scroll the diff/blame regions
git-gui: Move console procs into their own namespace
git-gui: Refactor into multiple files to save my sanity
git-gui: Track our own embedded values and rebuild when they change
git-gui: Refactor to use our git proc more often
git-gui: Use option database defaults to set the font
git-gui: Cleanup common font handling for font_ui
git-gui: Correct line wrapping for too many branch message
git-gui: Warn users before making an octopus merge
git-gui: Include the subject in the status bar after commit
Also perform an evil merge change to update Git's main Makefile to
pass the proper options down into git-gui now that it depends on
reasonable values for 'sharedir' and 'TCL_PATH'.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'git-gui/lib/console.tcl')
-rw-r--r-- | git-gui/lib/console.tcl | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/git-gui/lib/console.tcl b/git-gui/lib/console.tcl new file mode 100644 index 0000000000..75f3e0463b --- /dev/null +++ b/git-gui/lib/console.tcl @@ -0,0 +1,201 @@ +# git-gui console support +# Copyright (C) 2006, 2007 Shawn Pearce + +namespace eval console { + +variable next_console_id 0 +variable console_data +variable console_cr + +proc new {short_title long_title} { + variable next_console_id + variable console_data + + set w .console[incr next_console_id] + set console_data($w) [list $short_title $long_title] + return [_init $w] +} + +proc _init {w} { + global M1B + variable console_cr + variable console_data + + set console_cr($w) 1.0 + toplevel $w + frame $w.m + label $w.m.l1 -text "[lindex $console_data($w) 1]:" \ + -anchor w \ + -justify left \ + -font font_uibold + text $w.m.t \ + -background white -borderwidth 1 \ + -relief sunken \ + -width 80 -height 10 \ + -font font_diff \ + -state disabled \ + -yscrollcommand [list $w.m.sby set] + label $w.m.s -text {Working... please wait...} \ + -anchor w \ + -justify left \ + -font font_uibold + scrollbar $w.m.sby -command [list $w.m.t yview] + pack $w.m.l1 -side top -fill x + pack $w.m.s -side bottom -fill x + pack $w.m.sby -side right -fill y + pack $w.m.t -side left -fill both -expand 1 + pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10 + + menu $w.ctxm -tearoff 0 + $w.ctxm add command -label "Copy" \ + -command "tk_textCopy $w.m.t" + $w.ctxm add command -label "Select All" \ + -command "focus $w.m.t;$w.m.t tag add sel 0.0 end" + $w.ctxm add command -label "Copy All" \ + -command " + $w.m.t tag add sel 0.0 end + tk_textCopy $w.m.t + $w.m.t tag remove sel 0.0 end + " + + button $w.ok -text {Close} \ + -state disabled \ + -command "destroy $w" + pack $w.ok -side bottom -anchor e -pady 10 -padx 10 + + bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y" + bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break" + bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break" + bind $w <Visibility> "focus $w" + wm title $w "[appname] ([reponame]): [lindex $console_data($w) 0]" + return $w +} + +proc exec {w cmd {after {}}} { + # -- Cygwin's Tcl tosses the enviroment when we exec our child. + # But most users need that so we have to relogin. :-( + # + if {[is_Cygwin]} { + set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"] + } + + # -- Tcl won't let us redirect both stdout and stderr to + # the same pipe. So pass it through cat... + # + set cmd [concat | $cmd |& cat] + + set fd_f [open $cmd r] + fconfigure $fd_f -blocking 0 -translation binary + fileevent $fd_f readable \ + [namespace code [list _read $w $fd_f $after]] +} + +proc _read {w fd after} { + variable console_cr + + set buf [read $fd] + if {$buf ne {}} { + if {![winfo exists $w]} {_init $w} + $w.m.t conf -state normal + 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} { + $w.m.t insert end [string range $buf $c $lf] + set console_cr($w) [$w.m.t index {end -1c}] + set c $lf + incr c + } else { + $w.m.t delete $console_cr($w) end + $w.m.t insert end "\n" + $w.m.t insert end [string range $buf $c $cr] + set c $cr + incr c + } + } + $w.m.t conf -state disabled + $w.m.t see end + } + + fconfigure $fd -blocking 1 + if {[eof $fd]} { + if {[catch {close $fd}]} { + set ok 0 + } else { + set ok 1 + } + if {$after ne {}} { + uplevel #0 $after $w $ok + } else { + done $w $ok + } + return + } + fconfigure $fd -blocking 0 +} + +proc chain {cmdlist w {ok 1}} { + if {$ok} { + if {[llength $cmdlist] == 0} { + done $w $ok + return + } + + set cmd [lindex $cmdlist 0] + set cmdlist [lrange $cmdlist 1 end] + + if {[lindex $cmd 0] eq {exec}} { + exec $w \ + [lindex $cmd 1] \ + [namespace code [list chain $cmdlist]] + } else { + uplevel #0 $cmd $cmdlist $w $ok + } + } else { + done $w $ok + } +} + +proc done {args} { + variable console_cr + variable console_data + + switch -- [llength $args] { + 2 { + set w [lindex $args 0] + set ok [lindex $args 1] + } + 3 { + set w [lindex $args 1] + set ok [lindex $args 2] + } + default { + error "wrong number of args: done ?ignored? w ok" + } + } + + if {$ok} { + if {[winfo exists $w]} { + $w.m.s conf -background green -text {Success} + $w.ok conf -state normal + focus $w.ok + } + } else { + if {![winfo exists $w]} { + _init $w + } + $w.m.s conf -background red -text {Error: Command Failed} + $w.ok conf -state normal + focus $w.ok + } + + array unset console_cr $w + array unset console_data $w +} + +} |