Path: utzoo!attcan!uunet!wyse!mips!dce From: dce@mips.COM (David Elliott) Newsgroups: comp.sources.d Subject: Re: using curses from a script? Message-ID: <8812@dunkshot.mips.COM> Date: 25 Nov 88 17:50:52 GMT References: <7668@well.UUCP> <1247@vsedev.VSE.COM> <949@vsi.COM> Reply-To: dce@mips.COM (David Elliott) Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 72 In article <949@vsi.COM> friedl@vsi.COM (Stephen J. Friedl) writes: >System V Release 3.1 (maybe 3.0?) has a tput that does >parameterization the right way: > > $ tput 12 37 ; echo foobar My System V.3.1 source doesn't work this way, but if you say tput cup 12 37 ; echo foobar it works just fine. In general, tput takes a capability name and acts upon it based on what kind of capability it is: * INTs are printed on stdout. * BOOLEANs cause the exit code of tput to be set the same way the boolean value is set. * STRINGs are printed with all arguments given handled as parameters. Numeric parameters are converted to numbers and others are passed as strings. This allows both cursor motion type things and function key program type things. Tput is quite useful. With it, I was able to rewrite the hgrep filter posted to comp.sources.unix last week as a sed script: #!/bin/sh # # hgrep - Run grep and hilite the pattern searched # PATH=/bin:/usr/bin Pattern="" H_on=`tput smso` H_off=`tput rmso` main() { for i { case "$i" in -*) continue ;; *) Pattern="$i" break ;; esac } if [ -t 1 ] then grep ${1+"$@"} | hilite else exec grep ${1+"$@"} fi } hilite() { sed 's/\('"$Pattern"'\)/'"$H_on"'\1'"$H_off"'/g' } main ${1+"$@"} -- David Elliott dce@mips.com or {ames,prls,pyramid,decwrl}!mips!dce "Did you see his eyes? Did you see his crazy eyes?" -- Iggy (who else?)