summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Lynch2006-06-27 13:00:14 +0200
committerDan Lynch2006-06-27 13:00:14 +0200
commit6d34baaef954927c3d14c2ab6ea9581d6dd9aabd (patch)
tree84ea0cb3fad71344b5738466912e4a8782dd274c
parent- multiple static inline definitions added (diff)
downloadipxe-6d34baaef954927c3d14c2ab6ea9581d6dd9aabd.tar.gz
ipxe-6d34baaef954927c3d14c2ab6ea9581d6dd9aabd.tar.xz
ipxe-6d34baaef954927c3d14c2ab6ea9581d6dd9aabd.zip
- testable console framework implementing mucurses SCREEN struct
-rw-r--r--src/tests/curses_scr.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/tests/curses_scr.c b/src/tests/curses_scr.c
new file mode 100644
index 000000000..b328113a4
--- /dev/null
+++ b/src/tests/curses_scr.c
@@ -0,0 +1,65 @@
+#include "/home/dan/cvs/extcvs/eb/src/include/curses.h"
+#include <termios.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#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,
+};