-void
-headerline(char *str)
-{
- werase(top);
-
- mvwhline(top, 1, 0, ACS_HLINE, COLS);
-
- mvwprintw(top, 0, 0, "%s | %s", PACKAGE " " VERSION, str);
-
- refresh();
- wrefresh(top);
-}
-
-
-void
-refresh_screen()
-{
-#ifdef SIGWINCH
- if( should_resize ) {
- resize_abook();
- return;
- }
-#endif
- clear();
-
- refresh_statusline();
- headerline(MAIN_HELPLINE);
- list_headerline();
-
- refresh_list();
-}
-
-#ifdef DEBUG
-extern int curitem;
-extern list_item *database;
-static void
-dump_item()
-{
- int i;
-
- fprintf(stderr,"sizeof(list_item) = %d\n", sizeof(list_item));
- fprintf(stderr,"--- dumping item %d ---\n", curitem);
-
- for(i=0; i<ITEM_FIELDS; i++)
- fprintf(stderr,"%d - %d\n",
- i, (int)database[curitem][i]);
-
- fprintf(stderr,"--- end of dump ---\n");
-
-}
-#endif
-
-extern char *selected;
-extern int curitem;
-
-static void
-get_commands()
-{
- int ch;
-
- for(;;) {
- can_resize = TRUE; /* it's safe to resize now */
- hide_cursor();
- if( should_resize )
- refresh_screen();
- ch = getch();
- show_cursor();
- can_resize = FALSE; /* it's not safe to resize anymore */
- switch( ch ) {
- case 'q': return;
- case '?': display_help(mainhelp); break;
- case 'a': add_item(); break;
- case '\r': edit_item(-1); break;
- case KEY_DC:
- case 'd':
- case 'r': remove_items(); break;
- case 12: refresh_screen(); break;
-
- case 'k':
- case KEY_UP: scroll_up(); break;
- case 'j':
- case KEY_DOWN: scroll_down(); break;
- case 'K':
- case KEY_PPAGE: page_up(); break;
- case 'J':
- case KEY_NPAGE: page_down(); break;
-
- case 'H':
- case KEY_HOME: goto_home(); break;
- case 'E':
- case KEY_END: goto_end(); break;
-
- case 'w': save_database();
- break;
- case 'l': read_database(); break;
- case 'i': import_database(); break;
- case 'e': export_database(); break;
- case 'C': clear_database(); break;
-
- case 'y': edit_options(); break;
- case 'o': open_datafile(); break;
-
- case 's': sort_database(); break;
- case 'S': sort_surname(); break;
-
- case '/': find(0); break;
- case '\\': find(1); break;
-
- case ' ': if(curitem >= 0) {
- selected[curitem] = !selected[curitem];
- print_number_of_items();
- refresh_list();
- }
- break;
- case '+': select_all();
- refresh_list();
- break;
- case '-': select_none();
- refresh_list();
- break;
- case '*': invert_selection();
- refresh_list();
- break;
- case 'A': move_curitem(MOVE_ITEM_UP);
- break;
- case 'Z': move_curitem(MOVE_ITEM_DOWN);
- break;
-
- case 'm': launch_mutt(); break;
-
- case 'p': print_database(); break;
-
- case 'u': launch_lynx(); break;
-#ifdef DEBUG
- case 'D': dump_item();
-#endif
- }
- }
-}
-
-
-static void
-display_help(char **tbl)
-{
- int i, j = 3;
-
- erase();
- headerline("help");
- refresh_statusline();
-
- for( i = 0; tbl[i] != NULL; i++) {
- mvaddstr(j++, 0, tbl[i]);
- if( ( !( (i+1) % (LINES-7) ) ) ||
- (tbl[i+1] == NULL) ) {
- refresh();
- statusline_msg("Press any key to continue...");
- erase();
- refresh_statusline();
- headerline("help");
- j = 3;
- }
- }
- refresh_screen();
-}
-
-void
-display_editor_help(WINDOW *w)
-{
- int i;
-
- werase(w);
-
- headerline("editor help");
-
- for( i = 0; editorhelp[i] != NULL; i++) {
- waddstr(w, editorhelp[i]);
- if( ( !( (i+1) % (LINES-8) ) ) ||
- (editorhelp[i+1] == NULL) ) {
- refresh();
- wrefresh(w);
- statusline_msg("Press any key to continue...");
- wclear(w);
- }
- }
-}
-
-
-void
-statusline_msg(char *msg)
-{
- clear_statusline();
- statusline_addstr(msg);
- getch();
-#ifdef DEBUG
- fprintf(stderr, "statusline_msg(\"%s\")\n", msg);
-#endif
- clear_statusline();
-}
-
-void
-statusline_addstr(char *str)
-{
- mvwaddstr(bottom, 1, 0, str);
- refresh();
- wrefresh(bottom);
-}
-
-/*
- * function statusline_getnstr
- *
- * parameters:
- * (char *str)
- * if n >= 0 str is a pointer which points a place where to store
- * the string, else str is ingnored
- * (int n)
- * the maximum length of the string
- * If n < 0 function will allocate needed space for the string.
- * Value 0 is not allowed for n.
- * (int use_filesel)
- * if this value is nonzero the fileselector is enabled
- *
- * returns (char *)
- * If n < 0 a pointer to a newly allocated string is returned.
- * If n > 0 a nonzero value is returned if user has typed a valid
- * string. If not NULL value is returned. Never really use the
- * _pointer_ if n > 0.
- *
- */
-
-char *
-statusline_getnstr(char *str, int n, int use_filesel)
-{
- char *buf;
- int y, x;
-
- getyx(bottom, y, x);
- wmove(bottom, 1, x);
-
- buf = wenter_string(bottom, n,
- (use_filesel ? ESTR_USE_FILESEL:0) | ESTR_DONT_WRAP);
-
- if(n < 0)
- return buf;
-
- if(buf == NULL)
- str[0] = 0;
- else
- strncpy(str, buf, n);
-
- str[n-1] = 0;
-
- free(buf);
-
- return buf;
-}
-
-void
-refresh_statusline()
-{
- werase(bottom);
-
- mvwhline(bottom, 0, 0, ACS_HLINE, COLS);
- mvwhline(bottom, 2, 0, ACS_HLINE, COLS);
-
- refresh();
- wrefresh(bottom);
-}
-
-
-char *
-ask_filename(char *prompt, int flags)
-{
- char *buf = NULL;
-
- clear_statusline();
-
- statusline_addstr(prompt);
- buf = statusline_getnstr(NULL, -1, flags);
-
- clear_statusline();
-
- return buf;
-}
-
-void
-clear_statusline()
-{
- wmove(bottom, 1, 0);
- wclrtoeol(bottom);
- wrefresh(bottom);
- refresh();
-}
-