From 6d34baaef954927c3d14c2ab6ea9581d6dd9aabd Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Tue, 27 Jun 2006 11:00:14 +0000 Subject: [PATCH] - testable console framework implementing mucurses SCREEN struct --- src/tests/curses_scr.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/tests/curses_scr.c diff --git a/src/tests/curses_scr.c b/src/tests/curses_scr.c new file mode 100644 index 00000000..b328113a --- /dev/null +++ b/src/tests/curses_scr.c @@ -0,0 +1,65 @@ +#include "/home/dan/cvs/extcvs/eb/src/include/curses.h" +#include +#include +#include + +#define ESC 27 +#define MODE 3 + +unsigned int _COLOUR_PAIRS = 4; +unsigned int _COLOURS = 8; +unsigned short _COLS = 80; +unsigned short _LINES = 25; + +static struct termios original, runtime; + +void _init_screen( struct _curses_screen *scr __unused ) { + tcgetattr(fileno(stdin),&original); + tcgetattr(fileno(stdin),&runtime); + runtime.c_lflag &= ~(ICANON|ECHO); + tcsetattr(fileno(stdin),TCSANOW,&runtime); + printf("%c[=%dh",ESC,MODE); + LINES = 25; COLS = 80; +} + +void _exit_screen( struct _curses_screen *scr __unused ) { + tcsetattr(fileno(stdin),TCSANOW,&original); + printf("%c[0",ESC); + printf("%c[u",ESC); +} + +void _movetoyx( struct _curses_screen *scr __unused, unsigned int y, unsigned int x ) { + printf( "%c[%d;%dH", ESC, y+1, x+1 ); +} + +void _putc( struct _curses_screen *scr __unused, chtype c ) { + unsigned short pairno; + pairno = (unsigned short)(( c & A_COLOUR ) >> CPAIR_SHIFT); + + // print rendition (colour and attrs) + //printf( "%c[%d;%d",ESC, + // cpairs[pairno][0], cpairs[pairno][1] ); + // print rendition (character) + printf( "%c", (char)(c & A_CHARTEXT) ); +} + +int _getc( struct _curses_screen *scr __unused ) { + return getc(stdin); +} + +bool _peek( struct _curses_screen *scr __unused ) { + int c; + if ( ( c = getc(stdin) ) != EOF ) { + ungetc( c, stdin ); + return TRUE; + } else { return FALSE; } +} + +SCREEN _curscr = { + .init = _init_screen, + .exit = _exit_screen, + .movetoyx = _movetoyx, + .putc = _putc, + .getc = _getc, + .peek = _peek, +};