瀏覽代碼

- testable console framework implementing mucurses SCREEN struct

tags/v0.9.3
Dan Lynch 18 年之前
父節點
當前提交
6d34baaef9
共有 1 個文件被更改,包括 65 次插入0 次删除
  1. 65
    0
      src/tests/curses_scr.c

+ 65
- 0
src/tests/curses_scr.c 查看文件

@@ -0,0 +1,65 @@
1
+#include "/home/dan/cvs/extcvs/eb/src/include/curses.h"
2
+#include <termios.h>
3
+#include <stddef.h>
4
+#include <stdio.h>
5
+
6
+#define ESC 27
7
+#define MODE 3
8
+
9
+unsigned int _COLOUR_PAIRS = 4;
10
+unsigned int _COLOURS = 8;
11
+unsigned short _COLS = 80;
12
+unsigned short _LINES = 25;
13
+
14
+static struct termios original, runtime;
15
+
16
+void _init_screen( struct _curses_screen *scr __unused ) {
17
+	tcgetattr(fileno(stdin),&original);
18
+	tcgetattr(fileno(stdin),&runtime);
19
+	runtime.c_lflag &= ~(ICANON|ECHO);
20
+	tcsetattr(fileno(stdin),TCSANOW,&runtime);
21
+	printf("%c[=%dh",ESC,MODE);
22
+	LINES = 25; COLS = 80;
23
+}
24
+
25
+void _exit_screen( struct _curses_screen *scr __unused ) {
26
+	tcsetattr(fileno(stdin),TCSANOW,&original);
27
+	printf("%c[0",ESC);
28
+	printf("%c[u",ESC);
29
+}
30
+
31
+void _movetoyx( struct _curses_screen *scr __unused, unsigned int y, unsigned int x ) {
32
+	printf( "%c[%d;%dH", ESC, y+1, x+1 );
33
+}
34
+
35
+void _putc( struct _curses_screen *scr __unused, chtype c ) {
36
+	unsigned short pairno;
37
+	pairno = (unsigned short)(( c & A_COLOUR ) >> CPAIR_SHIFT);
38
+	
39
+	// print rendition (colour and attrs)
40
+	//printf( "%c[%d;%d",ESC, 
41
+	//	cpairs[pairno][0], cpairs[pairno][1] );
42
+	// print rendition (character)
43
+	printf( "%c", (char)(c & A_CHARTEXT) );
44
+}
45
+
46
+int _getc( struct _curses_screen *scr __unused ) {
47
+	return getc(stdin);
48
+}
49
+
50
+bool _peek( struct _curses_screen *scr __unused ) {
51
+	int c;
52
+	if ( ( c = getc(stdin) ) != EOF ) {
53
+		ungetc( c, stdin );
54
+		return TRUE;
55
+	} else { return FALSE; }
56
+}
57
+
58
+SCREEN _curscr = {
59
+	.init = _init_screen,
60
+	.exit = _exit_screen,
61
+	.movetoyx = _movetoyx,
62
+	.putc = _putc,
63
+	.getc = _getc,
64
+	.peek = _peek,
65
+};

Loading…
取消
儲存