|
|
@@ -1,88 +0,0 @@
|
|
1
|
|
-#include "../include/curses.h"
|
|
2
|
|
-#include <termios.h>
|
|
3
|
|
-#include <stddef.h>
|
|
4
|
|
-#include <stdio.h>
|
|
5
|
|
-#include <string.h>
|
|
6
|
|
-
|
|
7
|
|
-#define ESC 27
|
|
8
|
|
-#define MODE 3
|
|
9
|
|
-
|
|
10
|
|
-unsigned int _COLOUR_PAIRS = 4;
|
|
11
|
|
-unsigned int _COLOURS = 8;
|
|
12
|
|
-unsigned short _COLS = 80;
|
|
13
|
|
-unsigned short _LINES = 25;
|
|
14
|
|
-
|
|
15
|
|
-static struct termios original, runtime;
|
|
16
|
|
-
|
|
17
|
|
-void _init_screen( struct _curses_screen *scr __unused ) {
|
|
18
|
|
- tcgetattr(fileno(stdin),&original);
|
|
19
|
|
- tcgetattr(fileno(stdin),&runtime);
|
|
20
|
|
- runtime.c_lflag &= ~(ICANON|ECHO);
|
|
21
|
|
- tcsetattr(fileno(stdin),TCSANOW,&runtime);
|
|
22
|
|
- //printf("%c[=%dh",ESC,MODE);
|
|
23
|
|
- LINES = 25; COLS = 80;
|
|
24
|
|
-}
|
|
25
|
|
-
|
|
26
|
|
-void _exit_screen( struct _curses_screen *scr __unused ) {
|
|
27
|
|
- printf("%c[1;1H",ESC);
|
|
28
|
|
- printf("%c[2J",ESC);
|
|
29
|
|
- tcsetattr(fileno(stdin),TCSANOW,&original);
|
|
30
|
|
-}
|
|
31
|
|
-
|
|
32
|
|
-void _movetoyx( struct _curses_screen *scr __unused, unsigned int y, unsigned int x ) {
|
|
33
|
|
- printf( "%c[%d;%dH", ESC, y+1, x+1 );
|
|
34
|
|
-}
|
|
35
|
|
-
|
|
36
|
|
-void _putc( struct _curses_screen *scr __unused, chtype c ) {
|
|
37
|
|
- unsigned short pairno;
|
|
38
|
|
- pairno = (unsigned short)(( c & A_COLOUR ) >> CPAIR_SHIFT);
|
|
39
|
|
-
|
|
40
|
|
- // print rendition (colour and attrs)
|
|
41
|
|
- //printf( "%c[%d;%d",ESC,
|
|
42
|
|
- // cpairs[pairno][0], cpairs[pairno][1] );
|
|
43
|
|
- // print rendition (character)
|
|
44
|
|
- //printf("char is \"%d\"", c );
|
|
45
|
|
- putchar( c );
|
|
46
|
|
- fflush(stdout); // There must be a better way to do this...
|
|
47
|
|
-}
|
|
48
|
|
-
|
|
49
|
|
-int _getc( struct _curses_screen *scr __unused ) {
|
|
50
|
|
- int c;
|
|
51
|
|
- char buffer[16];
|
|
52
|
|
- char *ptr;
|
|
53
|
|
- c = getchar();
|
|
54
|
|
- if ( c == '\n' )
|
|
55
|
|
- return KEY_ENTER;
|
|
56
|
|
- /*
|
|
57
|
|
- WE NEED TO PROCESS ANSI SEQUENCES TO PASS BACK KEY_* VALUES
|
|
58
|
|
- if ( c == ESC ) {
|
|
59
|
|
- ptr = buffer;
|
|
60
|
|
- while ( scr->peek( scr ) == TRUE ) {
|
|
61
|
|
- *(ptr++) = getchar();
|
|
62
|
|
- }
|
|
63
|
|
-
|
|
64
|
|
- // ANSI sequences
|
|
65
|
|
- if ( strcmp ( buffer, "[D" ) == 0 )
|
|
66
|
|
- return KEY_LEFT;
|
|
67
|
|
- }
|
|
68
|
|
- */
|
|
69
|
|
-
|
|
70
|
|
- return c;
|
|
71
|
|
-}
|
|
72
|
|
-
|
|
73
|
|
-bool _peek( struct _curses_screen *scr __unused ) {
|
|
74
|
|
- int c;
|
|
75
|
|
- if ( ( c = getchar() ) != EOF ) {
|
|
76
|
|
- ungetc( c, stdin );
|
|
77
|
|
- return TRUE;
|
|
78
|
|
- } else { return FALSE; }
|
|
79
|
|
-}
|
|
80
|
|
-
|
|
81
|
|
-SCREEN _curscr = {
|
|
82
|
|
- .init = _init_screen,
|
|
83
|
|
- .exit = _exit_screen,
|
|
84
|
|
- .movetoyx = _movetoyx,
|
|
85
|
|
- .putc = _putc,
|
|
86
|
|
- // .getc = _getc,
|
|
87
|
|
- // .peek = _peek,
|
|
88
|
|
-};
|