PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > How can I implement this game in bash?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

How can I implement this game in bash?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/12/2006, 14h37   #1
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How can I implement this game in bash?

I think you all have heard about the game
named Rissian Diamonds.

Yes, I want to implement this in bash.
So, I need some commmands like curse library.
Are there such commands?
  Réponse avec citation
Vieux 10/12/2006, 23h10   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

On 2006-12-10, Bo Yang wrote:
> I think you all have heard about the game
> named Rissian Diamonds.


I have never heard of it. What is it?

> Yes, I want to implement this in bash.
> So, I need some commmands like curse library.
> Are there such commands?


There is no shell interface to the curses library apart from the
non-standardized tput. However, there is a standard for terminals
which is close to universal. If you use ISO-6429, which is almost
the same as the older ANSI x3.64, which is basically VT100. The
number of terminals which do not support the standard is very
small, and getting smaller.

By encapsulating screen codes in functions, they can easily be
replaced by those for a different terminal in the unlikely event
that it should be necessary.

These articles discuss using the mouse, cursor keys and function
keys in shell scripts:
<http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html>
<http://www.unixreview.com/documents/s=9525/ur0507a/ur0507a.html>

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 11/12/2006, 04h09   #3
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

Chris F.A. Johnson :
> On 2006-12-10, Bo Yang wrote:
>> I think you all have heard about the game
>> named Rissian Diamonds.

>
> I have never heard of it. What is it?


Oh, I am sorry. I have taken it for granted that the game is very
prevailing !
Sorry!
>
>> Yes, I want to implement this in bash.
>> So, I need some commmands like curse library.
>> Are there such commands?

>
> There is no shell interface to the curses library apart from the
> non-standardized tput. However, there is a standard for terminals
> which is close to universal. If you use ISO-6429, which is almost
> the same as the older ANSI x3.64, which is basically VT100. The
> number of terminals which do not support the standard is very
> small, and getting smaller.


Can you explain ISO-6429 and ANSI x3.64 for me? Are those standards for
terminals?
>
> By encapsulating screen codes in functions, they can easily be
> replaced by those for a different terminal in the unlikely event
> that it should be necessary.
>
> These articles discuss using the mouse, cursor keys and function
> keys in shell scripts:
> <http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html>
> <http://www.unixreview.com/documents/s=9525/ur0507a/ur0507a.html>
>


I just want to draw some basic geometry graphics in the terminals, are
there such commands?
  Réponse avec citation
Vieux 11/12/2006, 11h53   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

2006-12-10, 18:10(-05), Chris F.A. Johnson:
> On 2006-12-10, Bo Yang wrote:
>> I think you all have heard about the game
>> named Rissian Diamonds.

>
> I have never heard of it. What is it?
>
>> Yes, I want to implement this in bash.
>> So, I need some commmands like curse library.
>> Are there such commands?

>
> There is no shell interface to the curses library apart from the
> non-standardized tput.


tcsh has a builtin interface to the termcap database (echotc)

zsh has a builtin interface to both the termcap and terminfo
databases (echoti, echotc, the $termcap and $terminfo
associative arrays) in its zsh/term{cap,info} modules, and
associative arrays for ANSI colors and attributes in the
"colors" autoloadable function.

--
Stéphane
  Réponse avec citation
Vieux 11/12/2006, 13h19   #5
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

Stephane CHAZELAS :
> 2006-12-10, 18:10(-05), Chris F.A. Johnson:
>> On 2006-12-10, Bo Yang wrote:
>>> I think you all have heard about the game
>>> named Rissian Diamonds.

>> I have never heard of it. What is it?
>>
>>> Yes, I want to implement this in bash.
>>> So, I need some commmands like curse library.
>>> Are there such commands?

>> There is no shell interface to the curses library apart from the
>> non-standardized tput.

>
> tcsh has a builtin interface to the termcap database (echotc)
>
> zsh has a builtin interface to both the termcap and terminfo
> databases (echoti, echotc, the $termcap and $terminfo
> associative arrays) in its zsh/term{cap,info} modules, and
> associative arrays for ANSI colors and attributes in the
> "colors" autoloadable function.
>

I am sorry, I still didn't understand after look over your post.
Can the echoti and echotc make a green rect in my terminal?
Please give more and explaination, thank you!
  Réponse avec citation
Vieux 11/12/2006, 14h00   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

2006-12-11, 21:19(+08), Bo Yang:
> Stephane CHAZELAS :
>> 2006-12-10, 18:10(-05), Chris F.A. Johnson:
>>> On 2006-12-10, Bo Yang wrote:
>>>> I think you all have heard about the game
>>>> named Rissian Diamonds.
>>> I have never heard of it. What is it?
>>>
>>>> Yes, I want to implement this in bash.
>>>> So, I need some commmands like curse library.
>>>> Are there such commands?
>>> There is no shell interface to the curses library apart from the
>>> non-standardized tput.

>>
>> tcsh has a builtin interface to the termcap database (echotc)
>>
>> zsh has a builtin interface to both the termcap and terminfo
>> databases (echoti, echotc, the $termcap and $terminfo
>> associative arrays) in its zsh/term{cap,info} modules, and
>> associative arrays for ANSI colors and attributes in the
>> "colors" autoloadable function.
>>

> I am sorry, I still didn't understand after look over your post.
> Can the echoti and echotc make a green rect in my terminal?

[...]

That's a low level interface.

zmodload zsh/terminfo

rectangle() { # x y w h color
local i j
local x=$1 y=$2 w=$3 h=$4 color=$5
echoti setab $color
repeat $h {
echoti cup $((y++)) $x
repeat $w print -n ' '
}
}


--
Stéphane
  Réponse avec citation
Vieux 11/12/2006, 14h22   #7
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

Stephane CHAZELAS :
> 2006-12-11, 21:19(+08), Bo Yang:
>> Stephane CHAZELAS :
>>> 2006-12-10, 18:10(-05), Chris F.A. Johnson:
>>>> On 2006-12-10, Bo Yang wrote:
>>>>> I think you all have heard about the game
>>>>> named Rissian Diamonds.
>>>> I have never heard of it. What is it?
>>>>
>>>>> Yes, I want to implement this in bash.
>>>>> So, I need some commmands like curse library.
>>>>> Are there such commands?
>>>> There is no shell interface to the curses library apart from the
>>>> non-standardized tput.
>>> tcsh has a builtin interface to the termcap database (echotc)
>>>
>>> zsh has a builtin interface to both the termcap and terminfo
>>> databases (echoti, echotc, the $termcap and $terminfo
>>> associative arrays) in its zsh/term{cap,info} modules, and
>>> associative arrays for ANSI colors and attributes in the
>>> "colors" autoloadable function.
>>>

>> I am sorry, I still didn't understand after look over your post.
>> Can the echoti and echotc make a green rect in my terminal?

> [...]
>
> That's a low level interface.
>
> zmodload zsh/terminfo
>
> rectangle() { # x y w h color
> local i j
> local x=$1 y=$2 w=$3 h=$4 color=$5
> echoti setab $color
> repeat $h {
> echoti cup $((y++)) $x
> repeat $w print -n ' '
> }
> }

Understand!
I think I can use tput to do this in the same way!
Thank you Stephane!
Thanks!
  Réponse avec citation
Vieux 11/12/2006, 14h23   #8
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

Stephane CHAZELAS :
> 2006-12-11, 21:19(+08), Bo Yang:
>> Stephane CHAZELAS :
>>> 2006-12-10, 18:10(-05), Chris F.A. Johnson:
>>>> On 2006-12-10, Bo Yang wrote:
>>>>> I think you all have heard about the game
>>>>> named Rissian Diamonds.
>>>> I have never heard of it. What is it?
>>>>
>>>>> Yes, I want to implement this in bash.
>>>>> So, I need some commmands like curse library.
>>>>> Are there such commands?
>>>> There is no shell interface to the curses library apart from the
>>>> non-standardized tput.
>>> tcsh has a builtin interface to the termcap database (echotc)
>>>
>>> zsh has a builtin interface to both the termcap and terminfo
>>> databases (echoti, echotc, the $termcap and $terminfo
>>> associative arrays) in its zsh/term{cap,info} modules, and
>>> associative arrays for ANSI colors and attributes in the
>>> "colors" autoloadable function.
>>>

>> I am sorry, I still didn't understand after look over your post.
>> Can the echoti and echotc make a green rect in my terminal?

> [...]
>
> That's a low level interface.
>
> zmodload zsh/terminfo
>
> rectangle() { # x y w h color
> local i j
> local x=$1 y=$2 w=$3 h=$4 color=$5
> echoti setab $color
> repeat $h {
> echoti cup $((y++)) $x
> repeat $w print -n ' '
> }
> }
>
>

Understand!
I think I can draw a rectangle in bash with tput now!
Thank you Stephane!
Thanks!
  Réponse avec citation
Vieux 12/12/2006, 03h13   #9
Roland Mainz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

Bo Yang wrote:
>
> I think you all have heard about the game
> named Rissian Diamonds.
>
> Yes, I want to implement this in bash.
> So, I need some commmands like curse library.
> Are there such commands?


You can use "tput" or issue VT100 commands which are more or less
understood by most terminals including "xterm", "dtterm", "kconsole"
etc. ... however I am not sure how usefull bash is in this case since
each rendering command will result in a |fork()| and that's very
time-intensive and unpredictable from a timing point of view.

BTW:
http://svn.genunix.org/repos/on/bran...n/fun/gnaw.ksh
is a PacMan-like game written in ksh93 which shows how to cache "tput"
output for use in a game ("tput" and other time-intensive stuff is done
before the game starts and during the game's main loop things like
|fork()|'ed child processes are avoided and ksh93 builtin commands
(which do not require a |fork()|) are used whereever possible).

----

Bye,
Roland

--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O
  Réponse avec citation
Vieux 12/12/2006, 03h43   #10
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

On 2006-12-12, Roland Mainz wrote:
> Bo Yang wrote:
>>
>> I think you all have heard about the game
>> named Rissian Diamonds.
>>
>> Yes, I want to implement this in bash.
>> So, I need some commmands like curse library.
>> Are there such commands?

>
> You can use "tput" or issue VT100 commands which are more or less
> understood by most terminals including "xterm", "dtterm", "kconsole"
> etc. ... however I am not sure how usefull bash is in this case since
> each rendering command will result in a |fork()| and that's very
> time-intensive and unpredictable from a timing point of view.


Bash doesn't need to fork if you use the VT100/ISO-6429 codes with
printf.

> BTW:
> http://svn.genunix.org/repos/on/bran...n/fun/gnaw.ksh
> is a PacMan-like game written in ksh93 which shows how to cache "tput"
> output for use in a game ("tput" and other time-intensive stuff is done
> before the game starts and during the game's main loop things like
>|fork()|'ed child processes are avoided and ksh93 builtin commands
> (which do not require a |fork()|) are used whereever possible).


Interesting, but it doesn't work in the version of ksh93 that I
have (Version M 1993-12-28 n). The problem is 'read -t ....'.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 12/12/2006, 06h53   #11
Roland Mainz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

"Chris F.A. Johnson" wrote:
> On 2006-12-12, Roland Mainz wrote:
> > Bo Yang wrote:
> >>
> >> I think you all have heard about the game
> >> named Rissian Diamonds.
> >>
> >> Yes, I want to implement this in bash.
> >> So, I need some commmands like curse library.
> >> Are there such commands?

> >
> > You can use "tput" or issue VT100 commands which are more or less
> > understood by most terminals including "xterm", "dtterm", "kconsole"
> > etc. ... however I am not sure how usefull bash is in this case since
> > each rendering command will result in a |fork()| and that's very
> > time-intensive and unpredictable from a timing point of view.

>
> Bash doesn't need to fork if you use the VT100/ISO-6429 codes with
> printf.


Uhm... is "printf" a bash builtin ?

> > BTW:
> > http://svn.genunix.org/repos/on/bran...n/fun/gnaw.ksh
> > is a PacMan-like game written in ksh93 which shows how to cache "tput"
> > output for use in a game ("tput" and other time-intensive stuff is done
> > before the game starts and during the game's main loop things like
> >|fork()|'ed child processes are avoided and ksh93 builtin commands
> > (which do not require a |fork()|) are used whereever possible).

>
> Interesting, but it doesn't work in the version of ksh93 that I
> have (Version M 1993-12-28 n). The problem is 'read -t ....'.


Newer versions of "gnaw" need the following fix (more or less because
"gnaw" was developed as some kind of technology demonstrator/demo for
"ksh93 in Solaris" during ksh93s alpha):
-- snip --
06-11-16 The discipline functions have been modified to allow each
subscript to act independently. Currently the discipline
function will not be called when called from a discipline
function of the same variable.
-- snip --
This was fixed in ksh93s (=ksh93, vesion "s"; see
https://mailman.research.att.com/pip...q4/001484.html
for download urls for the current alpha version (which may disappear
when the next alpha gets released)) ... ksh93n is very very old... ;-/

BTW: A screenshot of "gnaw" can be found at
http://www.opensolaris.org/os/projec...n/screenshots/
(bottom of the page).

----

Bye,
Roland

--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O
  Réponse avec citation
Vieux 12/12/2006, 08h10   #12
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I implement this game in bash?

On 2006-12-12, Roland Mainz wrote:
>>
>> Bash doesn't need to fork if you use the VT100/ISO-6429 codes with
>> printf.

>
> Uhm... is "printf" a bash builtin ?


Since bash-2.02-alpha1 which dates from 1997.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,23290 seconds with 20 queries