Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ncurses.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define FALSE 0
- #define TRUE 1
- /*
- * GLOBAL VARIABLES
- */
- WINDOW *layer1, *layer2, *layerBottom, *AddButton;
- char *TEXT_LIBRARY[3] =
- {
- "Patta Address Book",
- "All Contacts",
- "^A: Add \t^E: Edit \t^D: Delete \t^S: Search \t^G: Groups \t^X: Export \t^Q: Quit\t"
- };
- int scrX;
- int scrY;
- /*
- * FUNCTION DECLARATIONS
- */
- int checkScrSize();
- /* Prints the text at center of Window/Layer. Parameters: WINDOW*, the row number and the string */
- void center_print(WINDOW*, int, const char*);
- void center_color_print(WINDOW*, int, int, int, const char*);
- /*
- * FUNCTION DEFINATIONS
- */
- int checkScrSize()
- {
- getmaxyx(stdscr, scrY, scrX);
- if(scrX < 80 || scrY < 24)
- return FALSE;
- return TRUE;
- }
- void center_print(WINDOW *win, int textY, const char *text)
- {
- int length = strlen(text);
- int winX, winY, textX;
- getmaxyx(win, winY, winX);
- textX = (winX/2)-(length/2);
- mvwprintw(win, textY,textX, "%s", text);
- }
- void center_color_print(WINDOW *win, int FOREGROUND, int BACKGROUND, int textY, const char *text)
- {
- init_pair(1, FOREGROUND, BACKGROUND);
- int length = strlen(text);
- int winX, winY, textX;
- getmaxyx(win, winY, winX);
- textX = (winX/2)-(length/2);
- attron(COLOR_PAIR(1));
- mvwprintw(win, textY,textX, "%s", text);
- attroff(COLOR_PAIR(1));
- }
- int main()
- {
- initscr();
- init_pair(1, COLOR_BLACK, COLOR_RED);
- start_color();
- if (checkScrSize() == FALSE)
- {
- endwin();
- printf("Please change you terminal size to atleast 80x24 and restart the program\n");
- exit(0);
- }
- center_print(stdscr,0,TEXT_LIBRARY[0]);
- refresh();
- /* Window/Layer Properties */
- layer1 = newwin(scrY-4, scrX/2, 1,0);
- box(layer1,0,0);
- layer2 = newwin(scrY-4, (scrX/2), 1,(scrX/2));
- box(layer2,0,0);
- layerBottom = newwin(4,scrX,scrY-3,0);
- center_print(layer1, 2, TEXT_LIBRARY[1]);
- center_color_print(layerBottom, COLOR_GREEN, COLOR_BLACK, 0, "This is a status bar.");
- attron(COLOR_PAIR(1));
- mvwprintw(layerBottom,1,0,TEXT_LIBRARY[2]);
- attroff(COLOR_PAIR(1));
- /* Window/Layer Initialization */
- wrefresh(layer1);
- wrefresh(layer2);
- wrefresh(layerBottom);
- /* Window/Layer Deletion */
- delwin(layer1);
- delwin(layer2);
- delwin(layerBottom);
- getch();
- endwin();
- }
Advertisement
Add Comment
Please, Sign In to add comment