ansi/send.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  ### ### ### ######### ######### #########*/
00003 /*  Terminal packages - ANSI - Control codes*/
00004 
00005 /*  ### ### ### ######### ######### #########*/
00006 /*  Requirements*/
00007 
00008 package require  term::send
00009 package require  term::ansi::code::ctrl
00010 
00011 namespace ::term::ansi::send {}
00012 
00013 /*  ### ### ### ######### ######### #########*/
00014 /*  Make command easily available*/
00015 
00016 ret  ::term::ansi::send::import (optional ns =send , type args) {
00017     if {![llength $args]} {set args *}
00018     set args ::term::ansi::send::[join $args " ::term::ansi::send::"]
00019     uplevel 1 [list namespace eval ${ns} [linsert $args 0 namespace import]]
00020     return
00021 }
00022 
00023 /*  ### ### ### ######### ######### #########*/
00024 /*  Internal - Setup.*/
00025 
00026 ret  ::term::ansi::send::ChName (type n) {
00027     if {![string match *-* $n]} {
00028     return ${n}ch
00029     }
00030     set nl   [split $n -]
00031     set stem [lindex       $nl 0]
00032     set sfx  [join [lrange $nl 1 end] -]
00033     return ${stem}ch-$sfx
00034 }
00035 
00036 ret  ::term::ansi::send::Args (type n -> , type arv , type achv , type avv) {
00037     upvar 1 $arv a $achv ach $avv av
00038     set code ::term::ansi::code::ctrl::$n
00039     set a   [info args $code]
00040     set ach [linsert $a 0 ch]
00041     set av  [expr {
00042     [llength $a]
00043     ? " \$[join $a " \$"]"
00044     : $a
00045     }]
00046     return $code
00047 }
00048 
00049 ret  ::term::ansi::send::INIT () {
00050     foreach n [::term::ansi::code::ctrl::names] {
00051     set nch  [ChName $n]
00052     set code [Args $n -> a ach av]
00053 
00054     if {[string equal [lindex $a end] args]} {
00055         # An args argument requires more care, and an eval
00056         set av [lrange $av 0 end-1]
00057         if {![string equal $av ""]} {set av " $av"}
00058         set gen "eval \[linsert \$args 0 $code$av\]"
00059 
00060         #8.5: set gen "$code$av \{expand\}\$args"
00061     } else {
00062         set gen $code$av
00063     }
00064 
00065     proc $n   $a   "wr        \[$gen\]" ; namespace export $n
00066     proc $nch $ach "wrch \$ch \[$gen\]" ; namespace export $nch
00067     }
00068     return
00069 }
00070 
00071 namespace ::term::ansi::send {
00072     namespace import ::term::send::wr
00073     namespace import ::term::send::wrch
00074     namespace export wr wrch
00075 }
00076 
00077 ::term::ansi::send::INIT
00078 
00079 /*  ### ### ### ######### ######### #########*/
00080 /*  Ready*/
00081 
00082 package provide term::ansi::send 0.1
00083 
00084 /** 
00085  * ### ### ### ######### ######### #########
00086 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1