/* freeansi.h                         */
/* the C header that does ansi stuff  */
/* the one with the annoying mnemonic */
/* by eyenot                          */
/* to be added: PRNG                  */
/*              reflective tracking   */
/*              - (bifurcable)        */
/*              bitwise rotate        */
/* req.1:... interests me; I am looking forward to seeing how it works 
out. It looks like it has almost everything from Curses that I ever 
use (except for getch(), addch(), noecho() and cbreak(); I will need 
to see how you implement similar functions). If it goes well, I will 
definitely use your library instead of Curses.
		implementable: getch() (with forlook)
			noecho() (with protected mode) */
/* reference: lunarsurf.com/~eyenot
preferred ansi table: http://www.inwap.com/pdp10/ansicode.txt
preferred fprint outputs:
http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=printf

why not make a library to automate all the ansi codes
and use that to replace the ncurses
use this program to experiment with what codes will work

locate convention for all codes works row-column
screen scrolling [r, [D, [M works but is tricky
scrolling can be turned on/off through esc.codes,
should probably try to default it to off through farestore()
since this makes for easier drawing on absolute dim.
(otherwise drawing to scrolline scrolls)

home cursor might be 0,0 or might be 0,24 depending on terminal
instead of assuming home cursor try to do a reset to 0,0 every scrclr
since it is a feature, may as well eventually accomodate reset home curs.

naming prefix fa
*/

/* it would be nice if these were color-pairs */
/* can't seem to find blink-bit OFF */

void farestore()
{
printf("\e[0m");
}

void famove(unsigned char row, unsigned char col)
{
printf("\e[%01.1u;%01.1uH",col,row);
}

void facsr_up(void)
{
printf("\e[A");
}

void facsr_down(void)
{
printf("\e[B");
}

void facsr_left(void)
{
printf("\e[D");
}

void facsr_right(void)
{
printf("\e[C");
}

void facls(void)
{
printf("\e[2J");
}

void faboldon(void)
{
printf("\e[1m");
}

void faboldoff(void)
{
printf("\e[22m");
}

void fadelay(unsigned char d)
{
/*this is cheap*/
while (d>0) 
	{
		facsr_right();facsr_left();
		d--;
	}
}


void facolor(unsigned char fg, unsigned char bg)
{
if (fg > 7) fg=7;
if (bg > 7) bg=7;
printf("\e[3%01.1u;4%01.1um",fg,bg);
}

void fafg(unsigned char fg)
{
if (fg > 7) fg=7;
printf("\e[3%01.1um", fg);
}

void fabg(unsigned char bg)
{
if (bg > 7 ) bg=7;
printf("\e[4%01.1um", bg);
}

