libpayload: implement wborder function
[coreboot.git] / payloads / libpayload / curses / tinycurses.c
index 6fcb43fcf8fd9d462ecd37d8665b69c91bc48883..08b858e3c01f12ed319abad72b42e144ed88c704 100644 (file)
@@ -79,8 +79,8 @@ int COLOR_PAIRS;
 WINDOW *stdscr;
 WINDOW *curscr;
 WINDOW *newscr;
-int LINES;
-int COLS;
+int LINES = 25;
+int COLS = 80;
 int TABSIZE;
 int ESCDELAY;
 // char ttytype[];
@@ -202,7 +202,7 @@ int endwin(void)
 // char erasechar (void) {}
 // void filter (void) {}
 // int flash(void) {}
-// int flushinp (void) {}
+int flushinp(void) { /* TODO */ return 0; }
 // WINDOW *getwin (FILE *) {}
 bool has_colors (void) { /* TODO */ return(*(bool *)0); }
 // bool has_ic (void) {}
@@ -219,9 +219,10 @@ WINDOW *initscr(void)
        // def_prog_mode();
 
        if (curses_flags & F_ENABLE_CONSOLE) {
-               /* Clear the screen and kill the cursor. */
-               vga_clear();
-               vga_cursor_enable(0);
+               /* Clear the screen and kill the cursor */
+
+               video_console_clear();
+               video_console_cursor_enable(0);
        }
 
        // Speaker init?
@@ -322,7 +323,7 @@ WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
 /* D */ int nonl(void) { SP->_nl = FALSE; return OK; }
 // void noqiflush (void) {}
 // int noraw (void) {}
-// int notimeout (WINDOW *,bool) {}
+/* D */ int notimeout (WINDOW *win, bool f) { win->_notimeout = f; return OK; }
 // int overlay (const WINDOW*,WINDOW *) {}
 // int overwrite (const WINDOW*,WINDOW *) {}
 // int pair_content (short,short*,short*) {}
@@ -463,7 +464,39 @@ int wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
 }
 // int wbkgd (WINDOW *, chtype) {}
 void wbkgdset(WINDOW *win, chtype ch) { /* TODO */ }
-// int wborder (WINDOW *,chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype) {}
+
+int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
+               chtype tl, chtype tr, chtype bl, chtype br)
+{
+       int x, y;
+
+       for(y = 0; y <= win->_maxy; y++) {
+
+               if (y == 0) {
+                        mvwaddch(win, y, 0, tl);
+
+                       for(x = 1; x < win->_maxx; x++)
+                               mvwaddch(win, y, x, ts);
+
+                       mvwaddch(win, y, win->_maxx, tr);
+               }
+               else if (y == win->_maxy) {
+                       mvwaddch(win, y, 0, bl);
+
+                       for(x = 1; x < win->_maxx; x++)
+                               mvwaddch(win, y, x, bs);
+
+                       mvwaddch(win, y, win->_maxx, br);
+               }
+               else {
+                       mvwaddch(win, y, 0, ls);
+                       mvwaddch(win, y, win->_maxx, rs);
+               }
+       }
+
+       return OK;
+}
+
 // int wchgat (WINDOW *, int, attr_t, short, const void *) {}
 /* D */ int wclear(WINDOW *win)
 {
@@ -586,7 +619,7 @@ int wnoutrefresh(WINDOW *win)
                                 * but this will break wide characters!
                                 */
                                c |= (chtype) (win->_line[y].text[x].chars[0] & 0xff);
-                               vga_putc(y, x, c);
+                               video_console_putc(y, x, c);
                        }
                }
        }
@@ -655,7 +688,7 @@ int wsetscrreg(WINDOW *win, int top, int bottom)
 }
 // void wsyncdown (WINDOW *) {}
 // void wsyncup (WINDOW *) {}
-// void wtimeout (WINDOW *,int) {}
+/* D */ void wtimeout(WINDOW *win, int delay) { win->_delay = delay; }
 /* D */ int wtouchln(WINDOW *win, int y, int n, int changed)
 {
        int i;