Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include <string.h>
  3. void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string);
  4.  
  5. int main(void) {
  6.    
  7.     int sq = 'o';
  8.    
  9.     // STARTUP:
  10.     //
  11.     //
  12.     //
  13.     // START NCURSES
  14.     initscr();
  15.     raw();
  16.     keypad(stdscr, TRUE);
  17.     noecho();
  18.  
  19.     // GET STD TERMINAL SCREEN DIMS
  20.     int w, h;
  21.     getmaxyx(stdscr, h, w);
  22.  
  23.     // CREATE MENU SCREEN
  24.     WINDOW *menu = newwin(h, w, 0, 0);
  25.     wrefresh(menu);
  26.  
  27.  
  28.  
  29.     // COLORING: // // // // // // //  
  30.     //
  31.     //
  32.     // INITIALIZE COLORS
  33.  
  34.     if(has_colors() == FALSE) {
  35.         printf("Your screen does not support colour\n");
  36.     }
  37.  
  38.     start_color();
  39.     init_pair(1, COLOR_RED, COLOR_BLACK);
  40.     attron(COLOR_PAIR(1));
  41.     print_in_middle(menu, 0, 0, w, "Hello!\n");
  42.     wrefresh(menu);
  43.     attroff(COLOR_PAIR(1));
  44.     getch();
  45.  
  46.  
  47.  
  48.     // CLEANUP: // // // // // // //
  49.     //
  50.     //
  51.     //
  52.     // PAUSE
  53.     getch();
  54.  
  55.     delwin(menu);
  56.  
  57.     // PAUSE
  58.     getch();
  59.  
  60.     // UPDATE
  61.     refresh(); 
  62.  
  63.     // END NCURSES
  64.     endwin();
  65.  
  66.  
  67.     return 0;
  68. }
  69. void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string) {
  70.  
  71.     int length, x, y;
  72.     float temp;
  73.  
  74.     if(win == NULL)
  75.         win = stdscr;
  76.     getyx(win, y, x);
  77.     if(startx != 0)
  78.         x = startx;
  79.     if(starty != 0)
  80.         y = starty;
  81.     if(width == 0)
  82.         width = 80;
  83.  
  84.     length = strlen(string);
  85.     temp = (width - length)/ 2;
  86.     x = startx + (int)temp;
  87.     mvwprintw(win, y, x, "%s", string);
  88.     refresh();
  89.  
  90.     return;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement