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