11
22#define _GNU_SOURCE
3- #include <curses.h>
43#include <signal.h>
54#include <stdlib.h>
65#include <stdbool.h>
@@ -112,7 +111,7 @@ int putenv(char*);
112111
113112}*/
114113
115- //#link ncurses
114+ bool CRT_linuxConsole = false;
116115
117116bool CRT_linuxConsole = false;
118117
@@ -126,17 +125,15 @@ char CRT_scrollBar;
126125
127126int CRT_colors [Colors ];
128127
129- static SCREEN * CRT_term ;
130-
131128Hashtable * CRT_keys ;
132129
133130void CRT_parseTerminalFile (char * term ) {
134131
135132 FILE * fd = Files_open ("r" , "terminals/%s" , term );
136133 if (!fd ) {
137- mvprintw (0 ,0 ,"Warning: could not parse terminal rules file terminals/%s" , term );
138- mvprintw (1 ,0 ,"Press any key." );
139- getch ();
134+ Display_printAt (0 ,0 ,"Warning: could not parse terminal rules file terminals/%s" , term );
135+ Display_printAt (1 ,0 ,"Press any key." );
136+ Display_getch ();
140137 return ;
141138 }
142139 while (!feof (fd )) {
@@ -150,7 +147,7 @@ void CRT_parseTerminalFile(char* term) {
150147 String_convertEscape (sequence , "^[" , 033 );
151148 int keynum = (int ) Hashtable_getString (CRT_keys , key );
152149 if (keynum )
153- define_key (sequence , keynum );
150+ Display_defineKey (sequence , keynum );
154151 nextLine :
155152 String_freeArray (tokens );
156153 }
@@ -170,27 +167,11 @@ void CRT_init() {
170167
171168 CRT_delay = 0 ;
172169
173- CRT_term = newterm (term , stdout , stdin );
174- raw ();
175- noecho ();
176- if (CRT_delay )
177- halfdelay (CRT_delay );
178- nonl ();
179- intrflush (stdscr , false);
180- keypad (stdscr , true);
181- ESCDELAY = 100 ;
182- if (has_colors ()) {
183- start_color ();
184- CRT_hasColors = true;
185- use_default_colors ();
186- for (int i = 0 ; i < 8 ; i ++ )
187- for (int j = 0 ; j < 8 ; j ++ )
188- init_pair (i * 8 + j , i == 7 ?-1 :i , j == 0 ?-1 :j );
189- init_pair (White * 8 + Black , Black , -1 );
170+ CRT_hasColors = Display_init (term );
171+ if (CRT_hasColors ) {
190172 CRT_scrollHandle = ' ' ;
191173 CRT_scrollBar = ' ' ;
192174 } else {
193- CRT_hasColors = false;
194175 CRT_scrollHandle = '*' ;
195176 CRT_scrollBar = '|' ;
196177 }
@@ -476,23 +457,19 @@ void CRT_init() {
476457// signal(11, CRT_handleSIGSEGV);
477458#endif
478459 signal (SIGTERM , CRT_handleSIGTERM );
479-
480- mousemask (BUTTON1_PRESSED , NULL );
481460}
482461
483462void CRT_done () {
484463 Hashtable_delete (CRT_keys );
485- curs_set (1 );
486- endwin ();
487- delscreen (CRT_term );
464+ Display_done ();
488465}
489466
490467int CRT_readKey () {
491- nocbreak ();
492- cbreak ();
493- int ret = getch ();
494- if (CRT_delay )
495- halfdelay (CRT_delay );
468+ // nocbreak();
469+ // cbreak();
470+ int ret = Display_getch ();
471+ // if (CRT_delay)
472+ // halfdelay(CRT_delay);
496473 return ret ;
497474}
498475
@@ -508,8 +485,8 @@ void CRT_handleSIGTERM(int signal) {
508485}
509486
510487int CRT_getCharacter () {
511- refresh ();
512- int ch = getch ();
488+ Display_refresh ();
489+ int ch = Display_getch ();
513490 #if defined __linux || defined __CYGWIN__
514491 if (ch == KEY_LEFT || ch == KEY_RIGHT || ch == KEY_UP || ch == KEY_DOWN
515492 || ch == KEY_HOME || ch == KEY_END || ch == KEY_IC || ch == KEY_DC || ch == '\t' ) {
0 commit comments