Prev: Print the section from a file from sed except first or last line
Next: Buy Beautiful Ghost Track Jacket!!!
From: Ivan Shmakov on 19 Nov 2009 16:41 >>>>> "IS" == Ivan Shmakov <ivan(a)main.uusia.org> writes: [...] IS> Ncurses comes with tput(1) bundled. I'm not sure how widely it is IS> available. [...] ... And tput(1), together with Bash arrays, allows, e. g., the following display hack to be implemented. (I wished to code it for a while...) #!/bin/bash cleanup () { trap EXIT reset } trap cleanup EXIT set_place () { local i="$1" cols rows if [ -z "${row[$i]}" -o -z "${col[$i]}" ] ; then cols=$(tput cols) rows=$(tput lines) row[$i]=$((1 + $RANDOM % ($rows - 1))) col[$i]=$((1 + $RANDOM % ($cols - 1))) fi ## . tput cup "${row[$i]}" "${col[$i]}" } set_color () { local i="$1" if [ -z "${color[$i]}" ] ; then color[$i]=$((1 + $RANDOM % 15)) fi ## . tput setaf "${color[$i]}" } new_char_p () { local i="$1" new if [ -n "${small[$i]}" ] ; then case "${ttl[$i]}" in (0) new=' ' ;; (1) new='.' ;; (2) new='*' ;; (*) new='.' ;; esac else case "${ttl[$i]}" in ([0]) new=' ' ;; ([1-2]) new=. ;; ([3-5]) new=o ;; ([6-7]) new=O ;; ([8-9]) new=o ;; (*) new=. ;; esac fi ## . test "$new" != "${char[$i]}" \ && char[$i]=$new } put_char () { local i="$1" printf %s\\b "${char[$i]}" } max=17 update_create_new () { local i i=0 while [ "$i" -lt "$max" ] ; do i=$((1 + $i)) if [ -n "${ttl[$i]}" ] ; then continue fi ttl[$i]=$((13 + $RANDOM % 71)) if [ $(($RANDOM % 7)) -lt 5 ] ; then small[$i]=1 fi done } update_evolve () { local i i=0 while [ "$i" -lt "$max" ] ; do i=$((1 + $i)) if [ -z "${ttl[$i]}" ] ; then continue fi ttl[$i]=$((-1 + ${ttl[$i]})) if new_char_p "$i" ; then set_place "$i" set_color "$i" put_char "$i" fi done } update_remove_old () { local i i=0 while [ "$i" -lt "$max" ] ; do i=$((1 + $i)) if [ -z "${ttl[$i]}" ] ; then continue fi if [ "${ttl[$i]}" -le 0 ] ; then ttl[$i]= row[$i]= col[$i]= color[$i]= char[$i]= small[$i]= fi done } update () { update_create_new update_evolve update_remove_old } tput civis clear while sleep .1s ; do update done -- FSF associate member #7257
From: Chris F.A. Johnson on 19 Nov 2009 17:06 On 2009-11-19, Ivan Shmakov wrote: >>>>>> "IS" == Ivan Shmakov <ivan(a)main.uusia.org> writes: > > [...] > > IS> Ncurses comes with tput(1) bundled. I'm not sure how widely it is > IS> available. > > [...] > > ... And tput(1), together with Bash arrays, allows, e. g., the > following display hack to be implemented. (I wished to code it > for a while...) It doesn't work everywhere. On some systems, the following does nothing: > tput setaf "${color[$i]}" -- Chris F.A. Johnson, author <http://shell.cfajohnson,com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: Thomas Dickey on 19 Nov 2009 20:17 On Nov 19, 5:06 pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: > On 2009-11-19, Ivan Shmakov wrote: .... > > IS>Ncursescomes with tput(1) bundled. I'm not sure how widely it is > > IS> available. .... > > ... And tput(1), together with Bash arrays, allows, e. g., the > > following display hack to be implemented. (I wished to code it > > for a while...) > > It doesn't work everywhere. On some systems, the following does > nothing: > > > tput setaf "${color[$i]}" er - you're responding to his comment in a misleading manner. It's unlikely that he's using bash on a system where ncurses and tput wouldn't work as suggested, unless of course he uses a tput that doesn't come bundled with ncurses. awai -- Thomas E. Dickey <dickey(a)invisible-island.net> http://invisible-island.net ftp://invisible-island.net
From: Chris F.A. Johnson on 19 Nov 2009 20:46 On 2009-11-20, Thomas Dickey wrote: > On Nov 19, 5:06?pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: >> On 2009-11-19, Ivan Shmakov wrote: > ... >> > IS>Ncursescomes with tput(1) bundled. ?I'm not sure how widely it is >> > IS> available. > ... >> > ? ?... And tput(1), together with Bash arrays, allows, e. g., the >> > ? ?following display hack to be implemented. ?(I wished to code it >> > ? ?for a while...) >> >> ? ? It doesn't work everywhere. On some systems, the following does >> ? ? nothing: >> >> > ? ? tput setaf "${color[$i]}" > > er - you're responding to his comment in a misleading manner. > > It's unlikely that he's using bash on a system where ncurses > and tput wouldn't work as suggested, unless of course he uses > a tput that doesn't come bundled with ncurses. I use bash on at least one system where it doesn't work. I have no idea what, if anything, it was bundled with. I've used many more such systems in the past. While there are a few terminals (or emulators) that do not conform for the most part to the ISO 6429 standard, the vast majority do. If a terminal doesn't conform, that's a good-enough reason not to use it. I have found it far closer to universal than either version of tput. -- Chris F.A. Johnson, author <http://shell.cfajohnson,com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: Ivan Shmakov on 19 Nov 2009 22:32 >>>>> "CFAJ" == Chris F A Johnson <cfajohnson(a)gmail.com> writes: >>>>> "IS" Ivan Shmakov wrote: IS> Ncurses comes with tput(1) bundled. I'm not sure how widely it is IS> available. [...] CFAJ> It doesn't work everywhere. On some systems, the following does CFAJ> nothing: > tput setaf "${color[$i]}" I've meant ``a fully-working tput(1)'' by ``it'' specifically in the sentence above. My Shell experience was limited mostly to GNU/Linux systems, and would /it/ fail on one under my rule, I'd immediately suspect a problem with the terminfo(5) database to be reported to the developers in charge. -- FSF associate member #7257
|
Next
|
Last
Pages: 1 2 Prev: Print the section from a file from sed except first or last line Next: Buy Beautiful Ghost Track Jacket!!! |