/**********************************************************************
 * Nano-GUI -- a Nano-X environment for Linux                         *
 *                          By Darran D. Rimron <darran@rimron.co.uk> *
 *                                                                    *
 * Based on Nano-Term, a Nano-X demo                                  *
 *                                         By Al Riddoch & Greg Haerr *
 *                                                                    *
 * ---------+--------+---------+------------------------------------- *
 * Date     | Author | Version | Reason                               *
 * ---------+--------+---------+------------------------------------- *
 * 19991112 | Rimron | 0.0.1   | Start Application                    *
 * 19991226 | Rimron | 0.0.2   | Add clock, improve terminal          *
 * ---------+--------+---------+------------------------------------- *
 * See NanoGUI.CHANGES and CHANGELOG for full and graphic change info *
 * ------------------------------------------------------------------ *
 *                                                                    *
 *      Best viewed with console-vim & a tabstop of 3 (:set ts=3)     *
 **********************************************************************/

int ACTIVE_BORDER_COLOR = YELLOW;
int INACTIVE_BORDER_COLOR = WHITE;

int CLOCK_PEN_COLOR = RED;
int CLOCK_PAPER_COLOR = BLACK;

int MAIN_PAPER_COLOR = BLACK;
int MAIN_PEN_COLOR = WHITE;
int MAIN_CURSOR_PEN_COLOR = BLACK;
int MAIN_CURSOR_PAPER_COLOR = GREEN;

int SCREEN_PEN_COLOR = RED;
int SCREEN_PAPER_COLOR = CYAN;

#define  DISABLED       0
#define  ANALOG         1
#define  DIGITAL        2
#define  CALANDER       3

#define	NO_CURSOR			0	/* Textmode apps often use this for "GUI's" */
#define	BLOCK_CURSOR		1	/* type BLOCK (solid square - default in DevFB) */
#define	UNDERSCORE_CURSOR	2	/* type underscore (like _) */
#define	BITMAP_CURSOR		3	/* Bitmap Cursor, not yet implimented :) */

#define	DEFAULT_CURSOR		BLOCK_CURSOR

/*
char itoa(int anint)
{
	char achar;

	sprintf(achar,"%d",anint);
	return(achar);
}
*/

void do_buttondown();
void do_buttonup();
void do_motion();
void text_init();
int  term_init();
void do_keystroke();
void do_focusin();
void do_focusout();
void do_enter();
void do_exit();
void do_fdinput();
void errorcatcher();			/* routine to handle errors */
void printg();
void HandleEvent(GR_EVENT *ep);
void char_del();

#define  _  ((unsigned) 0)    /* off bits */
#define  X  ((unsigned) 1)    /* on bits */
#define  MASK(a,b,c,d,e,f,g) \
   (((((((((((((a * 2) + b) * 2) + c) * 2) + d) * 2) \
   + e) * 2) + f) * 2) + g) << 9)

static GR_WINDOW_ID     main_window;   /* id for Main Window */
static GR_WINDOW_ID     clock_window;  /* id for Main Window */
static GR_GC_ID         gc1;           /* graphics context */
static GR_GC_ID         gc2;           /* graphics context */
static GR_GC_ID         gc3;           /* graphics context */
static GR_COORD         text_xpos;     /* x coord for text */
static GR_COORD         text_ypos;     /* y coord for text */
static GR_SCREEN_INFO   si;            /* screen info */
static int  			   shellIO;


static int		is_esc_seq;
static char		esc_string[16];
static int		esc_pos=0;

static int	npar[16];		/* ECMA-48 CSI spec. states that the number of */
static int	npar_part=0;	/* parameters passed [npar] can not exceed 16 */

//static int		cursor=DEFAULT_CURSOR;
