Click to See Complete Forum and Search --> : locating output to specific location on screen.
Rob 'Feztaa' Park
07-11-2001, 09:06 PM
ok, I'm trying to port some of my calculator games into bash scripts... I've managed to port quite a few of them, but I've now run into a wall:
I don't know how to specify X,Y coordinates to specify where to write things.
For example, one program is a brownian motion simulator. It draws an "O" to the screen, then moves it around in random directions. How would I go about programming that as a bash script?
If anybody is familiar with QBasic, I'm essentially looking for bash's version of Qbasic's "Locate" command.
If this is not possible, can anybody recommend a language that I can do this with?
Thanks!
Strike
07-11-2001, 09:26 PM
ncurses is probably the best solution for this.
Rob 'Feztaa' Park
07-12-2001, 02:53 AM
Hmmmm, I'll look into it. Thanks.
Rob 'Feztaa' Park
07-12-2001, 03:45 AM
Hmmmm... I read the man page for it... seems like it's a header file to be included into C sources... how would I go about using it for bash scripting?
moyix's ghost
07-12-2001, 04:51 AM
I think that bash simply isn't powerful enough to handle what you're trying to do. I agree with Strike, ncurses and C are your best bets.
Rob 'Feztaa' Park
07-12-2001, 06:40 AM
ok, but what I'm asking is, does ncurses require C? is it just a C thing? that's what I'm wondering.
I'd just like to stick with scripting for the moment because I'm not at all familiar with C, and I'm not currently comfortable with the idea of "compiling" programs. heh, I suppose I could get myself set up with gcc.
Strike
07-12-2001, 07:44 AM
Yes, it's a C library. You will have to use C to use ncurses (well, technically you could use assembly language too, but ... C tends to be a tad bit easier :)). AFAIK, there's nothing on the level of simplicity of bash scripting that allows for what you want to do.
I'll sure perl has an ncurses module, too. :) To me, perl is not more complex than bash scripting. Just a really complex shell w/ limited interactivity (actually, IIRC, someone went ahead and created a psh - perl shell; but that might be a hallucination on my part). And again, I know perl can use ncurses. Check out some perl tut's on the web, it's not hard to pick up at all.
TheLinuxDuck
07-12-2001, 10:18 AM
Feztaa:
The solution you are looking for is simply to use ansi control codes. As long as the terminal that you are using the script on is an ansi terminal, then the control codes will allow you to do specific cursor control.
Here is a link (http://www.bluesock.org/~willg/dev/ansi.html) for some ansi escape codes.
And here is an example of their use in a bash script:
#!/bin/bash
printf "\x1b[2J\x1b[1;1H"
printf "Printed at the top of the screen, after a clear screen"
printf "\x1b[5;5H"
printf "Printed at 5,5"
printf "\x1b[10;10H"
printf "Printed at 10,10"
exit
You'll notice two things.
1. We had to use the hex equivalent of 'esc' (chr 27) to begin the escape sequence
2. We had to use printf. I am not sure how to do escape sequences with echo, so this is what I know works.
Hope this helps!
Rob 'Feztaa' Park
07-13-2001, 06:02 PM
hey, neat! thanks :)
Do you know of any way I can get rid of that box that sits at the end of the line? that's kind of annoyying :)
TheLinuxDuck
07-17-2001, 10:47 AM
Originally posted by Feztaa:
<STRONG>Do you know of any way I can get rid of that box that sits at the end of the line? that's kind of annoyying :)</STRONG>
box? Are you refering to the cursor? If so, I *think* there's an ansi escape code to hide the cursor. If not, you might be able to hide it by changing the color of the cursor to black on black. Not sure that will do the trick, but maybe.
augur
07-17-2001, 11:01 AM
Greetings,
Yes, there is an ansi escape code to turn the cursor off:
#!/bin/bash
printf "\x1b[?25l"
To turn the cursor back on:
#!/bin/bash
printf "\x1b[?25h"
Rob 'Feztaa' Park
07-17-2001, 08:05 PM
Yes, I was talking about the cursor
Is there a website somewhere that lists the ansi codes for things?
Ben Briggs
07-17-2001, 11:00 PM
Originally posted by kmj:
<STRONG>I'll sure perl has an ncurses module, too. :) To me, perl is not more complex than bash scripting. Just a really complex shell w/ limited interactivity (actually, IIRC, someone went ahead and created a psh - perl shell; but that might be a hallucination on my part). And again, I know perl can use ncurses. Check out some perl tut's on the web, it's not hard to pick up at all.</STRONG>
There is also a Python curses module. I think you (kmj) and many others, will agree that Python is easier for learning than Perl. Plus you can do a heck of a lot more with Python than bash (or any other shell for that matter).
Just a suggestion
Rob 'Feztaa' Park
07-18-2001, 01:19 AM
I am interested in learning them all, right now I am focusing on Bash, next I'm going to go for Python, then some Perl, and then C++ :)
The more languages I know, the more useful I am as a programmer, right? :)
not if you write poor code that nobody else can read...
TheLinuxDuck
07-19-2001, 09:07 AM
Originally posted by Feztaa:
<STRONG>Is there a website somewhere that lists the ansi codes for things?</STRONG>
Take a look in my first post in this thread. I put a link in the 'Here is a link for some ansi escape codes'. You can also do a search in google for ansi escape codes. (http://www.google.com/search?as_q=&num=100&btnG=Google+Search&as_epq=ansi+escape+codes&as_oq=&as_eq=&lr=&as_qdr=all&as_occt=any&as_dt=i&as_sitesearch=&safe=off)
Rob 'Feztaa' Park
07-19-2001, 05:17 PM
Cool, thx