#include "display.h"
+#define USE_NCURSES
+
int display_init(t_display *display) {
struct winsize ws;
/* space as display pixel default */
memset(display->screen,0x20,display->max_x*display->max_y);
+#ifdef USE_NCURSES
+ initscr();
+ nonl();
+ noecho();
+ cbreak();
+ curs_set(0);
+#endif
+
return D_SUCCESS;
}
int x,y;
+#ifdef USE_NCURSES
+ mvprintw(0,0,"%s",display->screen);
+ for(y=0;y<display->max_y;y++)
+ for(x=0;x<display->max_x;x++)
+ mvaddch(y,x,*(display->screen+y*display->max_x+x));
+ refresh();
+#else
for(y=0;y<display->max_y;y++) {
for(x=0;x<display->max_x;x++)
printf("%c",*(display->screen+y*display->max_x+x));
printf("\n");
}
+#endif
return D_SUCCESS;
}
int x,y;
+#ifdef USE_NCURSES
+ for(y=0;y<line;y++) {
+ for(x=0;x<display->max_x;x++)
+ mvaddch(y,x,*(display->screen+y*display->max_x+x));
+ refresh();
+ }
+#else
for(y=0;y<line;y++) {
for(x=0;x<display->max_x;x++)
printf("%c",*(display->screen+y*display->max_x+x));
printf("\n");
}
+#endif
+
+ return D_SUCCESS;
+}
+
+int display_set_cursor(t_display *display,int x,int y) {
+
+#ifdef USE_NCURSES
+ move(y,x);
+ refresh();
+#endif
return D_SUCCESS;
}
int display_shutdown(t_display *display) {
+#ifdef USE_NCURSES
+ endwin();
+#endif
+
free(display->screen);
puts("[display] shutdown");