James wrote:
> -I need some help. (new to c) I want to print strings at x,y cordinates on
> -the screen. But without using ncurses.
Ask Henrik said: Use curses. Failing that, use the terminfo functions.
> it must be possible (because otherwise how does ncurses do it) but i
> don't know how...
ncurses does it by reading the terminfo/termcap database to find out
which character sequence sets the cursor position on the type of
terminal being used. This can be found by looking up the terminfo
entry for `cup', or the termcap entry for `cm'.
For an ANSI terminal, this is `\E[%i%p1%d;%p2%dH'. Translation:
\E => Escape: (ASCII 27)
%i => add 1 to first two parameters
%p1 => push parameter 1
%d => pop top value and print as decimal
; => literal semicolon
%p2 => push parameter 2
%d => pop top value and print as decimal
H => literal H
So to move to row 10 column 20 (where the top-left corner is 0,0), you
would send \E[11;21H, e.g.
echo -ne '\033[11;21H' ; sleep 10
> writing directly to video ram?
Nope; that wouldn't work on xterms, serial terminals, Windows telnet
packages etc.
> -Also how do i make text appear in colors.
Again, use curses. Failing that, use the terminfo functions.
> do ansi escape sequences work in linux?
Yes. Both xterm and the Linux console use the ANSI sequences for
colour.
> i had a big list of what you could use for such wonderful effects as
> bright red flashing text on a bright green background
You don't need a list. All of the appropriate sequences can be
obtained from the terminfo database.
Hardcoding particular control sequences into a program means that the
program will only work on certain terminal types. It's far better to
use the terminfo functions, then the program works on any terminal
which is in the terminfo database.
> ncurses is easier though!
Curses allows you to maintain a virtual `screen' which you can `draw'
upon, and automatically sends whatever control sequences are necessary
to cause the terminal to display that screen.
It's much easier than having to work out what control sequences have
to be sent for every type of character-cell terminal (and emulator)
known to mankind.
--
Glynn Clements <[EMAIL PROTECTED]>