ctrlunix.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  ### ### ### ######### ######### #########*/
00003 /*  Terminal packages - ANSI - Control operations*/
00004 /*  (Unix specific implementation).*/
00005 
00006 /*  This was originally taken from page 11820 (Pure Tcl Console Editor)*/
00007 /*  of the Tcler's Wiki, however page 14693 (Reading a single character*/
00008 /*  ...) is the same in a more self-contained manner.*/
00009 
00010 /*  ### ### ### ######### ######### #########*/
00011 /*  Requirements*/
00012 
00013 namespace ::term::ansi::ctrl::unix {}
00014 
00015 /*  ### ### ### ######### ######### #########*/
00016 /*  Make command easily available*/
00017 
00018 ret  ::term::ansi::ctrl::unix::import (optional ns =ctrl , type args) {
00019     if {![llength $args]} {set args *}
00020     set args ::term::ansi::ctrl::unix::[join $args " ::term::ansi::ctrl::unix::"]
00021     uplevel 1 [list namespace eval ${ns} [linsert $args 0 namespace import]]
00022     return
00023 }
00024 
00025 /*  ### ### ### ######### ######### #########*/
00026 /*  API*/
00027 
00028 /*  We use the <@stdin because stty works out what terminal to work with*/
00029 /*  using standard input on some platforms. On others it prefers*/
00030 /*  /dev/tty instead, but putting in the redirection makes the code more*/
00031 /*  portable*/
00032 
00033 ret  ::term::ansi::ctrl::unix::raw () {
00034     variable stty
00035     exec $stty raw -echo <@stdin
00036     return
00037 }
00038 
00039 ret  ::term::ansi::ctrl::unix::cooked () {
00040     variable stty
00041     exec $stty -raw echo <@stdin
00042     return
00043 }
00044 
00045 ret  ::term::ansi::ctrl::unix::columns () {
00046     variable tput
00047     return [exec $tput cols <@stdin]
00048 }
00049 
00050 ret  ::term::ansi::ctrl::unix::rows () {
00051     variable tput
00052     return [exec $tput lines <@stdin]
00053 }
00054 
00055 /*  ### ### ### ######### ######### #########*/
00056 /*  Package setup*/
00057 
00058 ret  ::term::ansi::ctrl::unix::INIT () {
00059     variable tput [auto_execok tput]
00060     variable stty [auto_execok stty]
00061 
00062     if {($tput eq "") || ($stty eq "")} {
00063     return -code error \
00064         "The external requirements for the \
00065         use of this package (tput, stty in \
00066         \$PATH) are not met."
00067     }
00068     return
00069 }
00070 
00071 namespace ::term::ansi::ctrl::unix {
00072     variable tput {}
00073     variable stty {}
00074 
00075     namespace export columns rows raw cooked
00076 }
00077 
00078 ::term::ansi::ctrl::unix::INIT
00079 
00080 /*  ### ### ### ######### ######### #########*/
00081 /*  Ready*/
00082 
00083 package provide term::ansi::ctrl::unix 0.1
00084 
00085 /** 
00086  * ### ### ### ######### ######### #########
00087 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1