Ejemplo n.º 1
0
Archivo: ui.c Proyecto: unixwitch/pwman
int
ui_ask_char(char const *msg, char *valid)
{
int		x = strlen(msg) + 5;
char		c = 0;

	do {
		ui_statusline_clear();
		if (c != 0) {
			ui_statusline_msg("Bad choice, press any key to try again");
			getch();
			ui_statusline_clear();
		}
		ui_statusline_msg(msg);

		echo();
		show_cursor();

		c = mvwgetch(bottom, 0, x);

		noecho();
		hide_cursor();

	} while (!strchr(valid, c));

	ui_statusline_clear();
	return c;
}
Ejemplo n.º 2
0
Archivo: ui.c Proyecto: ab/pwman
void
ui_statusline_ask_char(char *msg, char *c, char* valid)
{
	int x = strlen(msg) + 5;
	char input[STRING_SHORT];

	*c = 0;
	do {
		ui_statusline_clear();
		if(*c != 0){
			ui_statusline_msg("Bad choice, press any key to try again");
			getch();
			ui_statusline_clear();
		}
		ui_statusline_msg(msg);

		echo();
		show_cursor();

		*c = mvwgetch(bottom, 1, x);

		noecho();
		hide_cursor();
		
	} while ( !strchr(valid, *c) );
	
	ui_statusline_clear();
}
Ejemplo n.º 3
0
Archivo: ui.c Proyecto: ab/pwman
char *
ui_statusline_ask_str_with_autogen(char *msg, char *input, int len, char *(*autogen)(char *), int ch)
{
	int i = 0;
	int c;
	char *text[2], *s;
	int x;

	if(input == NULL){
		input = malloc(len);
	}
	text[0] = malloc(STRING_MEDIUM);
	text[1] = malloc(STRING_SHORT);
	
	strncpy(text[1], msg, STRING_SHORT);
	if(s = strrchr(text[1], ':')){
		*s = 0;
	}
	snprintf(text[0], STRING_MEDIUM, "%s(%c for autogen):\t", text[1],ch);
	x = strlen(text[0]) + 5;

	ui_statusline_clear();
	ui_statusline_msg(text[0]);

	show_cursor();
	noecho();

	wmove(bottom, 1, x);

	while(i < len){
		c = wgetch(bottom);
		if(c == 0x7f){
			if(i){
				i--;
				mvwaddch(bottom, 1, x+i, ' ');
				wmove(bottom, 1, x+i);
			}
		} else if(c == 0xd){
			input[i] = 0;
			break;
		} else if(c == ch){
			input = autogen(input);
			break;
		} else {
			input[i] = c;
			mvwaddch(bottom, 1, x + i, c);
			i++;
		}
	}
	
	hide_cursor();
	
	ui_statusline_clear();

	free(text[0]);
	free(text[1]);

	return input;
}
Ejemplo n.º 4
0
Archivo: ui.c Proyecto: unixwitch/pwman
static void
ui_display_help()
{
int		i, l = 0;
WINDOW         *helpwin;
int		width = 65;

	helpwin = newwin(LINES - 5, width, 3, (COLS - width) / 2);
	box(helpwin, 0, 0);
	uilist_clear();

	for (i = 0; help[i] != NULL; i++) {
		mvwaddstr(helpwin, l + 1, 1, help[i]);
		l++;

		if (!((i + 1) % (LINES - 8)) || (help[i + 1] == NULL)) {
			wrefresh(helpwin);
			ui_statusline_msg("Press any key to continue...");
			getch();
			wclear(helpwin);
			box(helpwin, 0, 0);
			l = 0;
		}
	}
	uilist_refresh();
	ui_statusline_clear();
	delwin(helpwin);
}
Ejemplo n.º 5
0
Archivo: ui.c Proyecto: ab/pwman
char *
ui_statusline_ask_passwd(char *msg, char *input, int len, int cancel)
{
	int i = 0;
	int c;
	int x = strlen(msg) + 5;

	if(!input){
		input = malloc(len);
	}
	ui_statusline_clear();
	ui_statusline_msg(msg);

	show_cursor();
	noecho();

	wmove(bottom, 1, x);

	while(i < len){
		c = wgetch(bottom);
		if(c == 0x7f){ /* 0x7f = delete */
			if(i){
				i--;
				mvwaddch(bottom, 1, x+i, ' ');
				wmove(bottom, 1, x+i);
			}
		} else if(c == 0xd){ /* 0xd == enter/return */
			input[i] = 0;
			break;
		} else if(c == cancel){
			free(input);
			input = NULL;

			return input;
		} else {
			input[i] = c;
			mvwaddch(bottom, 1, x + i, '*');
			i++;
		}
	}
	
	hide_cursor();
	
	ui_statusline_clear();
	
	return input;
}
Ejemplo n.º 6
0
Archivo: ui.c Proyecto: ab/pwman
int 
ui_statusline_msg(char * msg)
{
	ui_statusline_clear();
	mvwaddstr(bottom, 1, 0, msg);
	refresh();
	wrefresh(bottom);
}
Ejemplo n.º 7
0
Archivo: ui.c Proyecto: unixwitch/pwman
int
ui_statusline_msg(char const *msg)
{
	ui_statusline_clear();
	mvwaddstr(bottom, 0, 0, msg);
	refresh();
	wrefresh(bottom);
	return 0;
}
Ejemplo n.º 8
0
Archivo: ui.c Proyecto: ab/pwman
void
ui_statusline_ask_num(char *msg, int *i)
{
	int x = strlen(msg) + 5;
	char input[STRING_SHORT];

	ui_statusline_clear();
	ui_statusline_msg(msg);

	echo();
	show_cursor();

	mvwgetnstr(bottom, 1, x, input, STRING_SHORT);
	*i = atoi(input);
	
	noecho();
	hide_cursor();

	ui_statusline_clear();
}
Ejemplo n.º 9
0
Archivo: ui.c Proyecto: ab/pwman
int 
ui_statusline_yes_no(char *msg, int def)
{
	int ret = -1, len;
	char *msg2;
	int ch;
	
	len = strlen(msg) + 10;
	msg2 = malloc(len);

	snprintf(msg2, len,  "%s%s", msg, def ? " (Y/n)?" : " (y/N)?", NULL);

	while(ret == -1){
		ui_statusline_msg(msg2);
		
		ch = getch();
		switch( ch ){
			case 'n':
			case 'N':
				ret = FALSE;
				break;
			case 'y':
			case 'Y':
				ret = TRUE;
				break;
			case 13:
				ret = def;
				break;
			default:
				ui_statusline_msg("Bad option, try again.");
				getch();
				break;
		}
	}

	free(msg2);
	ui_statusline_clear();

	return ret;
}
Ejemplo n.º 10
0
Archivo: ui.c Proyecto: ab/pwman
int 
ui_display_help()
{
	int i;
	WINDOW *helpwin;

	helpwin = newwin(LINES - 5, COLS - 6, 3, 3);
	uilist_clear();

	for(i = 0; help[i] != NULL; i++){
		waddstr(helpwin, help[i]);
		if( !((i+1) % (LINES - 9)) || (help[i+1] == NULL) ){
	/*		refresh();*/
			wrefresh(helpwin);
			ui_statusline_msg("Press any key to continue...");
			getch();
			wclear(helpwin);
		}
	}
	uilist_refresh();
	ui_statusline_clear();
	delwin(helpwin);
}
Ejemplo n.º 11
0
Archivo: ui.c Proyecto: unixwitch/pwman
int
ui_run()
{
int		ch;
int		load_worked = 0;

#ifdef DEBUG
int		debug_i = 0;

#endif

	time_base = time(NULL);

	while (1) {
		can_resize = TRUE;
		if (should_resize) {
			ui_resize();
		}
		ch = getch();
		ui_statusline_clear();
		can_resize = FALSE;

		if ((time_base < (time(NULL) - (options->passphrase_timeout * 60)))
		    && options->passphrase_timeout != 0 && tolower(ch) != 'q') {
			folder_write_file();
			folder_free_all();

			ui_statusline_msg("Passphrase has timed out and you must enter it again.");
			getch();

			load_worked = folder_read_file();
			if (load_worked != 0) {
				ui_statusline_msg("Error - unable to re-load the password file!");
				break;
			}
			if (search_results != NULL)
				search_remove();

			time_base = time(NULL);
			continue;
		}
		switch (ch) {
		case 'Q':
		case 'q':
			if (search_results != NULL)
				search_remove();
			else if (action_list_at_top_level())
				return 0;
			break;

		case '?':
			ui_display_help();
			break;

		case KEY_PPAGE:
			uilist_page_up();
			break;

		case KEY_NPAGE:
			uilist_page_down();
			break;

		case KEY_UP:
		case 'k':
			uilist_up();
			break;

		case KEY_DOWN:
		case 'j':
			uilist_down();
			break;

		case 'A':
			if (!options->readonly)
				action_list_add_sublist();
			else
				statusline_readonly();
			break;

		case 'U':
			action_list_up_one_level();
			break;

		case 'r':
			if (!options->readonly) {
				action_list_rename();
				folder_write_file();
			} else {
				statusline_readonly();
			}
			break;

		case 'a':
			if (!options->readonly) {
				action_list_add_pw();
				folder_write_file();
			} else {
				statusline_readonly();
			}
			break;

		case 'e':
		case ' ':
		case 13:	/* return/enter key */
			action_list_select_item();
			break;

		case 'x':
			action_list_mark();
			break;

		case 'B':
			action_list_copy_username();
			break;

		case 'C':
			action_list_copy_pw();
			break;

		case 'd':
		case 0x14A:	/* DEL key */
			if (!options->readonly)
				action_list_delete_item();
			else 
				statusline_readonly();
			break;

		case 'm':
			if (!options->readonly)
				action_list_move_item();
			else
				statusline_readonly();
			break;

		case 'o':
			action_edit_options();
			break;

		case 0x17:	/* control-w */
			if (!options->readonly)
				folder_write_file();
			else
				statusline_readonly();
			break;

		case 0x12:	/* control-r */
			action_list_read_file();
			break;

		case 0x07:	/* control-g */
			pwgen_indep();
			break;

		case 0x06:	/* control-f */
			gnupg_forget_passphrase();
			break;

		case 0x0C:	/* control-l */
			ui_refresh_windows();
			break;

		case '/':
		case 'F':
			search_get();
			break;

		case 'f':
			filter_get();
			break;

		case 'E':
			action_list_export();
			break;

		case 'I':
			if (!options->readonly) {
				folder_import_passwd();
				uilist_refresh();
			} else {
				statusline_readonly();
			}
			break;

		case 'L':
			action_list_locate();
			break;

		case 'l':
			action_list_launch();
			break;

		case 0x0B:	/* control-k (up) */
		case '[':
			action_list_move_item_up();
			break;

		case 0x0A:	/* control-j (down) */
		case ']':
			action_list_move_item_down();
			break;

#ifdef DEBUG
		case '$':
			debug_i++;
			snprintf(msg, 80, "Name %d", debug_i);

			folder_add(current_pw_sublist, msg, "myhost", "myuser", "mypasswd", "mylaucnh");
			uilist_refresh();
			break;
#endif

		default:
			break;
		}
	}
	return 0;
}
Ejemplo n.º 12
0
Archivo: ui.c Proyecto: ab/pwman
char *
ui_statusline_ask_str(char *msg, char *input, int len)
{
	char *tmp;
	char *tmp2;
	char *tmp3;
	int x = strlen(msg) + 5;

	if(input == NULL){
		input = malloc(len);
	}
	ui_statusline_clear();
	ui_statusline_msg(msg);

	echo();
	show_cursor();
	mvwgetnstr(bottom, 1, x, input, len);
	noecho();
	hide_cursor();

	ui_statusline_clear();

	// Tabs don't play nicely with ncurses or xml
	// So, swap any for (a single) space
	tmp = input;
	while(*tmp != 0) {
		if(*tmp == 9) *tmp = ' ';
		tmp++;
	}

	// In some cases (eg when inside screen), the backspace
	// comes through to us. Handle it here if needed
	tmp = input;
	while(*tmp != 0) {
		if(*tmp == 8) {
         // tmp2 is where to copy to, tmp3 is where to copy from
         tmp3 = tmp + 1;
         if(tmp == input) {
            tmp2 = tmp;
         } else {
            tmp2 = tmp - 1;
         }

         // When we're done, start from the character
         //  we copied in to
         tmp = tmp2;

         // Process forward
         while(*tmp3 != 0) {
            *tmp2 = *tmp3;
            tmp2++;
            tmp3++;
         }
         *tmp2 = 0;
      } else {
   		tmp++;
      }
	}
	
	// All done
	return input;
}