aHardyX

ncurses trial 2

Aug 5th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define FALSE   0
  7. #define TRUE    1
  8.  
  9. /*
  10.  * GLOBAL VARIABLES
  11.  */
  12.  
  13. WINDOW *layer1, *layer2, *layerBottom, *AddButton;
  14.  
  15. char *TEXT_LIBRARY[3] =
  16.         {
  17.             "Patta Address Book",
  18.             "All Contacts",
  19.             "^A: Add \t^E: Edit \t^D: Delete \t^S: Search \t^G: Groups \t^X: Export \t^Q: Quit\t"
  20.         };
  21.  
  22. int scrX;
  23. int scrY;
  24.  
  25. /*
  26.  * FUNCTION DECLARATIONS
  27.  */
  28. int     checkScrSize();
  29.  
  30.  
  31. /* Prints the text at center of Window/Layer. Parameters: WINDOW*, the row number and the string */
  32. void    center_print(WINDOW*, int, const char*);
  33.  
  34. /*
  35.  * FUNCTION DEFINATIONS
  36.  */
  37.  
  38. int checkScrSize()
  39. {
  40.     getmaxyx(stdscr, scrY, scrX);
  41.     if(scrX < 80 || scrY < 24)
  42.         return FALSE;
  43.     return TRUE;
  44. }
  45.  
  46. void center_print(WINDOW *win, int textY, const char *text)
  47. {
  48.     int length = strlen(text);
  49.     int winX, winY, textX;
  50.  
  51.     getmaxyx(win, winY, winX);
  52.  
  53.     textX = (winX/2)-(length/2);
  54.  
  55.     mvwprintw(win, textY,textX, "%s", text);
  56. }
  57.  
  58. int main()
  59. {
  60.     start_color();
  61.     init_pair(1, COLOR_BLUE, COLOR_BLACK);
  62.  
  63.     initscr();
  64.     if (checkScrSize() == FALSE)
  65.     {
  66.         endwin();
  67.         printf("Please change you terminal size to atleast 80x24 and restart the program\n");
  68.         exit(0);
  69.     }
  70.  
  71.     center_print(stdscr,0,TEXT_LIBRARY[0]);
  72.  
  73.     refresh();
  74.  
  75.     /* Window/Layer Properties */
  76.     layer1 = newwin(scrY-4, scrX/2, 1,0);
  77.         box(layer1,0,0);
  78.     layer2 = newwin(scrY-4, (scrX/2), 1,(scrX/2));
  79.         box(layer2,0,0);
  80.     layerBottom = newwin(4,scrX,scrY-3,0);
  81.  
  82.     center_print(layer1, 2, TEXT_LIBRARY[1]);
  83.     attron(A_BOLD);
  84.     center_print(layerBottom, 0, "This is a status bar.");
  85.     attroff(A_BOLD);
  86.     mvwprintw(layerBottom,1,0,TEXT_LIBRARY[2]);
  87.    
  88.    
  89.  
  90.     /* Window/Layer Initialization */
  91.     wrefresh(layer1);
  92.     wrefresh(layer2);
  93.     wrefresh(layerBottom);
  94.  
  95.     /* Window/Layer Deletion */
  96.     delwin(layer1);
  97.     delwin(layer2);
  98.     delwin(layerBottom);
  99.  
  100.     getch();
  101.  
  102.     endwin();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment