📄 shell.tcl
字号:
set v(prior) $cmd regsub -all {[^ ]} $v(prompt) . x $w insert end $x } $w mark set insert end $w mark set out {insert linestart} $w yview insert}# Change the line to the previous line#proc console:Prior w { upvar #0 $w v if {$v(current)<=0} return incr v(current) -1 set line [lindex $v(history) $v(current)] console:SetLine $w $line}# Change the line to the next line#proc console:Next w { upvar #0 $w v if {$v(current)>=$v(historycnt)} return incr v(current) 1 set line [lindex $v(history) $v(current)] console:SetLine $w $line}# Change the contents of the entry line#proc console:SetLine {w line} { upvar #0 $w v scan [$w index insert] %d.%d row col set start $row.$v(plength) $w delete $start end $w insert end $line $w mark set insert end $w yview insert}# Called when the mouse button is pressed at position $x,$y on# the console widget.#proc console:Button1 {w x y} { global tkPriv upvar #0 $w v set v(mouseMoved) 0 set v(pressX) $x set p [console:nearestBoundry $w $x $y] scan [$w index insert] %d.%d ix iy scan $p %d.%d px py if {$px==$ix} { $w mark set insert $p } $w mark set anchor $p focus $w}# Find the boundry between characters that is nearest# to $x,$y#proc console:nearestBoundry {w x y} { set p [$w index @$x,$y] set bb [$w bbox $p] if {![string compare $bb ""]} {return $p} if {($x-[lindex $bb 0])<([lindex $bb 2]/2)} {return $p} $w index "$p + 1 char"}# This routine extends the selection to the point specified by $x,$y#proc console:SelectTo {w x y} { upvar #0 $w v set cur [console:nearestBoundry $w $x $y] if {[catch {$w index anchor}]} { $w mark set anchor $cur } set anchor [$w index anchor] if {[$w compare $cur != $anchor] || (abs($v(pressX) - $x) >= 3)} { if {$v(mouseMoved)==0} { $w tag remove sel 0.0 end } set v(mouseMoved) 1 } if {[$w compare $cur < anchor]} { set first $cur set last anchor } else { set first anchor set last $cur } if {$v(mouseMoved)} { $w tag remove sel 0.0 $first $w tag add sel $first $last $w tag remove sel $last end update idletasks }}# Called whenever the mouse moves while button-1 is held down.#proc console:B1Motion {w x y} { upvar #0 $w v set v(y) $y set v(x) $x console:SelectTo $w $x $y}# Called whenever the mouse leaves the boundries of the widget# while button 1 is held down.#proc console:B1Leave {w x y} { upvar #0 $w v set v(y) $y set v(x) $x console:motor $w}# This routine is called to automatically scroll the window when# the mouse drags offscreen.#proc console:motor w { upvar #0 $w v if {![winfo exists $w]} return if {$v(y)>=[winfo height $w]} { $w yview scroll 1 units } elseif {$v(y)<0} { $w yview scroll -1 units } else { return } console:SelectTo $w $v(x) $v(y) set v(timer) [after 50 console:motor $w]}# This routine cancels the scrolling motor if it is active#proc console:cancelMotor w { upvar #0 $w v catch {after cancel $v(timer)} catch {unset v(timer)}}# Do a Copy operation on the stuff currently selected.#proc console:Copy w { if {![catch {set text [$w get sel.first sel.last]}]} { clipboard clear -displayof $w clipboard append -displayof $w $text }}# Return 1 if the selection exists and is contained# entirely on the input line. Return 2 if the selection# exists but is not entirely on the input line. Return 0# if the selection does not exist.#proc console:canCut w { set r [catch { scan [$w index sel.first] %d.%d s1x s1y scan [$w index sel.last] %d.%d s2x s2y scan [$w index insert] %d.%d ix iy }] if {$r==1} {return 0} if {$s1x==$ix && $s2x==$ix} {return 1} return 2}# Do a Cut operation if possible. Cuts are only allowed# if the current selection is entirely contained on the# current input line.#proc console:Cut w { if {[console:canCut $w]==1} { console:Copy $w $w delete sel.first sel.last }}# Do a paste opeation.#proc console:Paste w { if {[console:canCut $w]==1} { $w delete sel.first sel.last } if {[catch {selection get -displayof $w -selection CLIPBOARD} topaste]} { return } set prior 0 foreach line [split $topaste \n] { if {$prior} { console:Enter $w update } set prior 1 $w insert insert $line }}# Enable or disable entries in the Edit menu#proc console:EnableEditMenu w { upvar #0 $w.t v set m $v(editmenu) if {$m=="" || ![winfo exists $m]} return switch [console:canCut $w.t] { 0 { $m entryconf Copy -state disabled $m entryconf Cut -state disabled } 1 { $m entryconf Copy -state normal $m entryconf Cut -state normal } 2 { $m entryconf Copy -state normal $m entryconf Cut -state disabled } }}# Prompt for the user to select an input file, the "source" that file.#proc console:SourceFile w { set types { {{TCL Scripts} {.tcl}} {{All Files} *} } set f [tk_getOpenFile -filetypes $types -title "TCL Script To Source..."] if {$f!=""} { uplevel #0 source $f }}# Prompt the user for the name of a writable file. Then write the# entire contents of the console screen to that file.#proc console:SaveFile w { set types { {{Text Files} {.txt}} {{All Files} *} } set f [tk_getSaveFile -filetypes $types -title "Write Screen To..."] if {$f!=""} { if {[catch {open $f w} fd]} { tk_messageBox -type ok -icon error -message $fd } else { puts $fd [string trimright [$w get 1.0 end] \n] close $fd } }}# Erase everything from the console above the insertion line.#proc console:Clear w { $w delete 1.0 {insert linestart}}# Start the console## console:create {.@console} {% } {Tcl/Tk Console}###############################################################################if {[info command sqlite]==""} { load ./tclsqlite.so sqlite}proc set_title {title} { if {$title==""} { set main SQLite } else { set main "SQLite - $title" } wm title . $main wm iconname . SQLite}set_title {}frame .mb -bd 1 -relief raisedpack .mb -side top -fill xmenubutton .mb.file -text File -underline 0 -menu .mb.file.mpack .mb.file -side left -padx 5set m [menu .mb.file.m]$m add separator$m add command -label Exit -command exitmenubutton .mb.edit -text Edit -underline 0 -menu .mb.edit.mpack .mb.edit -side left -padx 5#menu .mb.edit.mframe .fpack .f -side top -fill both -expand 1console:create_child .f {sqlite> } .mb.edit.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -