Move cursor restoration into io.c.
[super-star-trek.git] / conio.c
diff --git a/conio.c b/conio.c
index adf42e5e58adfd0de2aa8489ab3a20551210f7a3..32cbb8c559b36b0f967cb4e46b1407aeba344e62 100644 (file)
--- a/conio.c
+++ b/conio.c
@@ -60,7 +60,7 @@ static void docolor (int color) /* Set DOS-like text mode colors */
 }
 
 /* Call this before any call to linux conio - except the port functions ! */
-void __attribute__((constructor)) initconio (void) /* This is needed, because ncurses needs to be initialized */
+void initconio (void)
 {
    int x,y;
    short pair;
@@ -120,16 +120,22 @@ char *cgets (char *str) /* ugly function :-( */
 }
 
 void clreol (void)
+/* clear to end of line -- can be a no-op in tty mode */
 {
-   wclrtoeol(conio_scr);
-   wrefresh(conio_scr);
+   if (conio_scr) {
+       wclrtoeol(conio_scr);
+       wrefresh(conio_scr);
+   }
 }
 
 void clrscr (void)
+/* clear screen -- can be a no-op in tty mode */
 {
-   wclear(conio_scr);
-   wmove(conio_scr,0,0);
-   wrefresh(conio_scr);
+   if (conio_scr) {
+       wclear(conio_scr);
+       wmove(conio_scr,0,0);
+       wrefresh(conio_scr);
+   }
 }
 
 int cprintf (char *format, ... )
@@ -140,8 +146,12 @@ int cprintf (char *format, ... )
    va_start(argp,format);
    vsprintf(buffer,format,argp);
    va_end(argp);
-   i=waddstr(conio_scr,buffer);
-   wrefresh(conio_scr);
+
+   if (conio_scr) {
+       i=waddstr(conio_scr,buffer);
+       wrefresh(conio_scr);
+   } else 
+       i=printf(buffer);
    return(i);
 }
 
@@ -211,17 +221,22 @@ void gettextinfo(struct text_info *inforec)
 } 
 
 void gotoxy (int x, int y)
+/* address cursor -- OK for this to be a no-op in TTY mode */
 {
-   y--;
-   x--;
-   wmove(conio_scr,y,x);
-   wrefresh(conio_scr);
+    if (conio_scr) {
+       y--;
+       x--;
+       wmove(conio_scr,y,x);
+       wrefresh(conio_scr);
+   }
 }
 
 void highvideo (void)
 {
-   textcolor(15); /* White */
-   textbackground(0); /* Black */
+    if (conio_scr) {
+       textcolor(15); /* White */
+       textbackground(0); /* Black */
+    }
 }
 
 void insline (void)
@@ -272,11 +287,14 @@ void textbackground (int color)
    docolor(color);
 }
 
+
 void textcolor (int color)
 {
-   fgc=color;
-   color=(bgc*16)+fgc;
-   docolor(color);
+    if (conio_scr) {
+       fgc=color;
+       color=(bgc*16)+fgc;
+       docolor(color);
+   }
 }
  
 void textmode (int mode)
@@ -286,20 +304,26 @@ void textmode (int mode)
 
 int wherex (void)
 {
-   int y;
-   int x;
-   getyx(conio_scr,y,x);
-   x++;
-   return(x);
+    if (conio_scr) {
+       int y;
+       int x;
+       getyx(conio_scr,y,x);
+       x++;
+       return(x);
+    }
+    return (0);
 }
 
 int wherey (void)
 {
-   int y;
-   int x;
-   getyx(conio_scr,y,x);
-   y++;
-   return(y);
+    if (conio_scr) {
+       int y;
+       int x;
+       getyx(conio_scr,y,x);
+       y++;
+       return(y);
+    }
+    return (0);
 }
 
 void window (int left,int top,int right,int bottom)