unixwz0r

boxexample.c

Sep 17th, 2021
801
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ncurses.h>
  2. #include <string.h> /* facilitate strlen() */
  3.  
  4. #define WHITEONRED 1
  5. #define WHITEONBLUE 2
  6. #define WHITEONBLACK 3
  7. #define BLACKONWHITE 4
  8.  
  9.  
  10. void wCenterTitle(WINDOW *pwin, const char * title)
  11.     {
  12.     int x, maxy, maxx, stringsize;
  13.     getmaxyx(pwin, maxy, maxx);
  14.     stringsize = 4 + strlen(title);
  15.     x = (maxx - stringsize)/2;
  16.     mvwaddch(pwin, 0, x, ACS_RTEE);
  17.     waddch(pwin, ' ');
  18.     waddstr(pwin, title);
  19.     waddch(pwin, ' ');
  20.     waddch(pwin, ACS_LTEE);
  21.     }
  22.  
  23. void wclrscr(WINDOW * pwin)
  24.     {
  25.     int y, x, maxy, maxx;
  26.     getmaxyx(pwin, maxy, maxx);
  27.     for(y=0; y < maxy; y++)
  28.         for(x=0; x < maxx; x++)
  29.             mvwaddch(pwin, y, x, ' ');
  30.     }
  31.  
  32. int main(int c, char *argv[])
  33.     {
  34.     WINDOW *base_win, *small_win;
  35.     int maxy, maxx;
  36.  
  37.     /* INITIALIZE CURSES AND COLORS AND REFRESH THE STANDARD SCREEN */
  38.     initscr();
  39.     getmaxyx(stdscr, maxy, maxx);
  40.     start_color();
  41.     init_pair(WHITEONRED, COLOR_WHITE, COLOR_RED);
  42.     init_pair(WHITEONBLUE, COLOR_WHITE, COLOR_BLUE);
  43.     init_pair(WHITEONBLACK, COLOR_WHITE, COLOR_BLACK);
  44.     init_pair(BLACKONWHITE, COLOR_BLACK, COLOR_WHITE);
  45.     wrefresh(stdscr); /* I don't know why this is necessary, but it is! */
  46.    
  47.     /* CREATE AND DISPLAY THE BASE WINDOW */
  48.     base_win = newwin(maxy, maxx, 0,0);
  49.     wattrset(base_win, COLOR_PAIR(WHITEONBLACK) | WA_BOLD);
  50.     wclrscr(base_win);
  51.     box(base_win, 0, 0);
  52.     wCenterTitle(base_win, "Tux Hat Linux Installer v4.0");
  53.     touchwin(base_win);
  54.     wrefresh(base_win);
  55.     getch();
  56.  
  57.  
  58.  
  59.  
  60.  
  61.     /* END CURSES */
  62.     endwin();
  63.     printf("\n\nwin.c\n");
  64.     return(0);
  65.     }
  66.  
RAW Paste Data