1# -*- tcl -*- 2# ### ### ### ######### ######### ######### 3## Terminal packages - ANSI - Control operations 4## (Unix specific implementation). 5 6## This was originally taken from page 11820 (Pure Tcl Console Editor) 7## of the Tcler's Wiki, however page 14693 (Reading a single character 8## ...) is the same in a more self-contained manner. 9 10# ### ### ### ######### ######### ######### 11## Requirements 12 13namespace eval ::term::ansi::ctrl::unix {} 14 15# ### ### ### ######### ######### ######### 16## Make command easily available 17 18proc ::term::ansi::ctrl::unix::import {{ns ctrl} args} { 19 if {![llength $args]} {set args *} 20 set args ::term::ansi::ctrl::unix::[join $args " ::term::ansi::ctrl::unix::"] 21 uplevel 1 [list namespace eval ${ns} [linsert $args 0 namespace import]] 22 return 23} 24 25# ### ### ### ######### ######### ######### 26## API 27 28# We use the <@stdin because stty works out what terminal to work with 29# using standard input on some platforms. On others it prefers 30# /dev/tty instead, but putting in the redirection makes the code more 31# portable 32 33proc ::term::ansi::ctrl::unix::raw {} { 34 variable stty 35 exec $stty raw -echo <@stdin 36 return 37} 38 39proc ::term::ansi::ctrl::unix::cooked {} { 40 variable stty 41 exec $stty -raw echo <@stdin 42 return 43} 44 45proc ::term::ansi::ctrl::unix::columns {} { 46 variable tput 47 return [exec $tput cols <@stdin] 48} 49 50proc ::term::ansi::ctrl::unix::rows {} { 51 variable tput 52 return [exec $tput lines <@stdin] 53} 54 55# ### ### ### ######### ######### ######### 56## Package setup 57 58proc ::term::ansi::ctrl::unix::INIT {} { 59 variable tput [auto_execok tput] 60 variable stty [auto_execok stty] 61 62 if {($tput eq "") || ($stty eq "")} { 63 return -code error \ 64 "The external requirements for the \ 65 use of this package (tput, stty in \ 66 \$PATH) are not met." 67 } 68 return 69} 70 71namespace eval ::term::ansi::ctrl::unix { 72 variable tput {} 73 variable stty {} 74 75 namespace export columns rows raw cooked 76} 77 78::term::ansi::ctrl::unix::INIT 79 80# ### ### ### ######### ######### ######### 81## Ready 82 83package provide term::ansi::ctrl::unix 0.1 84 85## 86# ### ### ### ######### ######### ######### 87