/* This the Jabber-like-GnuPG-Instant-Messenger (JlGIM) by */ /* MMB and DK */ #include #include #include using namespace std; void initializeNcurses(void); void endNcurses(void); void selectCommunication(void); void printHello(void); const int ESCAPE = 27; const int BACKSPACE = 127; const int DEL = 330; int main() { initializeNcurses(); printHello(); selectCommunication(); endNcurses(); return 0; } /* This sets the nCurses environment, which we need to display stuff on the terminal */ void initializeNcurses() { initscr(); keypad(stdscr, 1); // We need this for arrow keys etc. cbreak(); // Give characters to our programme immedaitely start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_BLACK, COLOR_BLACK); } /* We probably will be glad of having it separated when there's more to do than to simply endwin Ncurses. At least it makes things a bit tidier */ void endNcurses() { endwin(); } void selectCommunication() { char ch; int where = 0; FIELD *field[4]; FORM *my_form; noecho(); field[0] = new_field(1, 50, 4, 25, 0, 0); field[1] = new_field(1, 50, 6, 25, 0, 0); field[2] = new_field(1, 50, 9, 25, 0, 0); field[3] = NULL; /* field options */ set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); set_field_back(field[1], A_UNDERLINE); field_opts_off(field[1], O_AUTOSKIP); set_field_back(field[2], A_UNDERLINE); field_opts_off(field[2], O_AUTOSKIP); /* Create the form and post it */ my_form = new_form(field); post_form(my_form); refresh(); /* General forms stuff */ mvprintw(4, 2, "Your fingerprint:"); mvprintw(6, 2, "Your password:"); mvprintw(9, 2, "Contact's fingerprint:"); mvprintw(4, 25, ""); set_current_field(my_form, field[0]); form_opts_off(my_form, O_BS_OVERLOAD); curs_set(1); refresh(); /* Loop through to get user requests */ while((ch = getch()) != ESCAPE) { switch(ch) { case KEY_DOWN: form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); if(2 == where) where = 0; else where++; break; case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); if(0 == where) where = 2; else where--; break; case BACKSPACE: case DEL: form_driver(my_form, REQ_DEL_PREV); form_driver(my_form, REQ_END_LINE); break; default: if(where == 1) { // xform_driver(my_form, 42); break; } form_driver(my_form, ch); break; } } /* Unpost form and free the memory */ unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); free_field(field[2]); } void printHello() { char greeting [] = "This the Jabber-like-GnuPG-Instant-Messenger (JlGIM) by DK and MMB"; curs_set(0); getmaxyx(stdscr,LINES,COLS); attron(A_BOLD | COLOR_PAIR(1)); mvprintw(LINES/2,((COLS/2)-(strlen(greeting)/2)),"%s",greeting); attroff(A_BOLD | COLOR_PAIR(1)); refresh(); halfdelay(30); getch(); cbreak(); }