# include	<stdio.h>

static enum {e_normal, e_bold, e_init} mode = e_init;

static	char	*text[] = {
	"\033[30m",
	"\033[31m",
	"\033[32m",
	"\033[33m",
	"\033[34m",
	"\033[35m",
	"\033[36m",
	"\033[37m",
	"\033[1m\033[30m",
	"\033[1m\033[31m",
	"\033[1m\033[32m",
	"\033[1m\033[33m",
	"\033[1m\033[34m",
	"\033[1m\033[35m",
	"\033[1m\033[36m",
	"\033[1m\033[37m",
		};

esc(str)
char	*str;
{
	printf("\033%s", str);
	fflush(stdout);
}
cls() { esc("[H"); esc("[2J"); }
char *t_cls() { return "\033[H\033[2J"; }
bold()
{
	if (mode != e_bold)
		esc("[1m");
	mode = e_bold;
}
char *
t_bold()
{
	if (mode != e_bold)
		return "\033[1m";
	return "";
}
char *
t_normal()
{
	if (mode != e_normal)
		return "\033[0m";
	return "";
}
normal()
{
	if (mode != e_normal)
		esc("[0m");
	mode = e_normal;
}
move(x,y)
{
	printf("\033[%d;%dH", x, y);
	fflush(stdout);
}
blink()
{
	esc("[5m");
}
steady()
{
	esc("[0m");
}
static	char	*s = "%s";

# define	FN(n1, n2, n3, n4, n) \
		n1() { printf(s, text[n]); fflush(stdout); } \
		n2() { printf(s, text[8+n]); fflush(stdout); } \
		char *n3() { return text[n]; } \
		char *n4() { return text[8+n]; }

FN(black, lt_black, t_black, t_lt_black, 0)
FN(red, lt_red, t_red, t_lt_red, 1)
FN(green, lt_green, t_green, t_lt_green, 2)
FN(yellow, lt_yellow, t_yellow, t_lt_yellow, 3)
FN(blue, lt_blue, t_blue, t_lt_blue, 4)
FN(magnenta, lt_magenta, t_magenta, t_lt_magenta, 5)
FN(cyan, lt_cyan, t_cyan, t_lt_cyan, 6)
FN(white, lt_white, t_white, t_lt_white, 7)
