diff options
author | toni <matzeton@googlemail.com> | 2014-12-08 02:55:13 +0100 |
---|---|---|
committer | toni <matzeton@googlemail.com> | 2014-12-08 09:49:48 +0100 |
commit | f92a04e64285e75b55c1ef68b31225514ac6304b (patch) | |
tree | 75cfcf1e7a6a6de60537028a6ff2632f4e72a8dd | |
parent | 94272da26e2bbb578b5f5e6b17080a0c1ce8df83 (diff) | |
parent | 9c31f67c257100af2af2d892c761b44087fc3eff (diff) |
Merge branch 'master' of github.com:lnslbrty/naskpass
-rw-r--r-- | ui.c | 16 | ||||
-rw-r--r-- | ui_input.c | 52 | ||||
-rw-r--r-- | ui_input.h | 11 |
3 files changed, 52 insertions, 27 deletions
@@ -131,7 +131,7 @@ init_ui(void) wnd_main = initscr(); start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_WHITE, COLOR_WHITE); + init_pair(2, COLOR_WHITE, COLOR_BLACK); init_pair(3, COLOR_BLACK, COLOR_WHITE); raw(); keypad(stdscr, TRUE); @@ -165,7 +165,7 @@ stop_ui_thrd(void) { } static bool -process_key(int key, struct input *a, WINDOW *win) +process_key(wchar_t key, struct input *a, WINDOW *win) { bool retval = true; @@ -196,12 +196,8 @@ process_key(int key, struct input *a, WINDOW *win) int main(int argc, char **argv) { - struct input *pw_input = init_input(3,7,20,"PASSWORD",128,COLOR_PAIR(3)); - struct anic *heartbeat = init_anic(2,2,A_BOLD | COLOR_PAIR(3)); - struct anic *a = init_anic(4,4,0); - struct anic *b = init_anic(6,6,COLOR_PAIR(1)); - a->state = '-'; - b->state = '\\'; + struct input *pw_input = init_input(10,10,20,"PASSWORD",128,COLOR_PAIR(3), COLOR_PAIR(2)); + struct anic *heartbeat = init_anic(2,2,A_BOLD | COLOR_PAIR(1)); char key = '\0'; if (sem_init(&sem_rdy, 0, 0) == -1) { @@ -210,7 +206,6 @@ main(int argc, char **argv) } init_ui(); register_anic(heartbeat); - register_anic(a); register_anic(b); register_input(NULL, pw_input); activate_input(wnd_main, pw_input); if (run_ui_thrd() != 0) { @@ -224,13 +219,10 @@ main(int argc, char **argv) pthread_mutex_unlock(&mtx_busy); } stop_ui_thrd(); - unregister_ui_elt(a); unregister_ui_elt(heartbeat); - unregister_ui_elt(b); unregister_ui_elt(pw_input); free_input(pw_input); free_anic(heartbeat); - free_anic(a); free_anic(b); free_ui(); return (0); } @@ -1,12 +1,13 @@ #include <stdlib.h> #include <string.h> +#include <wchar.h> #include "ui.h" #include "ui_input.h" struct input * -init_input(unsigned int x, unsigned int y, unsigned int width, char *prompt, size_t input_len, chtype attrs) +init_input(unsigned int x, unsigned int y, unsigned int width, char *prompt, size_t input_len, chtype attrs, chtype shadow) { struct input *a = calloc(1, sizeof(struct input)); @@ -18,8 +19,13 @@ init_input(unsigned int x, unsigned int y, unsigned int width, char *prompt, siz a->input_max = input_len; a->input_len = 0; a->input_pos = 0; +#ifdef NCURSES_WIDECHAR + a->prompt = wcsdup(prompt); +#else a->prompt = strdup(prompt); +#endif a->attrs = attrs; + a->shadow = shadow; return (a); } @@ -34,17 +40,34 @@ free_input(struct input *a) } static void -print_wnd(int x, int y, size_t len, size_t addwidth) +print_wnd(size_t addwidth, struct input *a) { - mvhline(y-2, x-2, 0, len+addwidth+3); - mvhline(y+2, x-2, 0, len+addwidth+3); - mvvline(y-1, x-3, 0, 3); - mvvline(y-1, x+len+addwidth+1, 0, 3); - mvaddch(y-2, x-3, ACS_ULCORNER); - mvaddch(y+2, x-3, ACS_LLCORNER); - mvaddch(y-2, x+len+addwidth+1, ACS_URCORNER); - mvaddch(y+2, x+len+addwidth+1, ACS_LRCORNER); - mvprintw(12, 1, "(%d,%d),len:%lu,addw:%lu", x, y, len, addwidth); + int i, x = a->x, y = a->y; + size_t relwidth = addwidth*2, len = strlen(a->prompt) + a->width; + char tmp[len+relwidth+1]; + + memset(tmp, ' ', len+relwidth); + tmp[len+relwidth] = '\0'; + for (i = -1; i <= 1; i++) + mvprintw(y+i, x-addwidth, tmp); + + mvhline(y-2, x-addwidth, 0, len+relwidth); + mvhline(y+2, x-addwidth, 0, len+relwidth); + mvvline(y-1, x-addwidth-1, 0, 3); + mvvline(y-1, x+len+addwidth, 0, 3); + mvaddch(y-2, x-addwidth-1, ACS_ULCORNER); + mvaddch(y+2, x-addwidth-1, ACS_LLCORNER); + mvaddch(y-2, x+len+addwidth, ACS_URCORNER); + mvaddch(y+2, x+len+addwidth, ACS_LRCORNER); + + attron(a->shadow); + for (i = x-addwidth+1; i < x+len+relwidth; i++) + mvaddch(y+3, i, ACS_CKBOARD); + for (i = -1; i < 3; i++) { + mvaddch(y+i, x+len+relwidth-2, ACS_CKBOARD); + mvaddch(y+i, x+len+relwidth-1, ACS_CKBOARD); + } + attroff(a->shadow); } static void @@ -74,7 +97,8 @@ print_input(WINDOW *win, struct input *a) size_t p_len = strlen(a->prompt); attron(a->attrs); - print_wnd(a->x, a->y, 10, 2); + print_wnd(3, a); + attron(a->attrs); if (win == NULL) { mvprintw(a->y, a->x, a->prompt); tmp = calloc(a->width+1, sizeof(char)); @@ -103,11 +127,11 @@ activate_input(WINDOW *win, struct input *a) } int -add_input(WINDOW *win, struct input *a, int key) +add_input(WINDOW *win, struct input *a, wchar_t key) { if (a == NULL) return (UICB_ERR_UNDEF); if (a->input_len >= a->input_max) return (UICB_ERR_BUF); - *(a->input + a->input_pos) = (char) key; + *(a->input + a->input_pos) = (wchar_t) key; ++a->input_pos; ++a->input_len; a->cur_pos = (a->cur_pos+1 < a->width ? a->cur_pos+1 : a->cur_pos); @@ -9,16 +9,25 @@ struct input { unsigned int y; unsigned int width; unsigned int cur_pos; +#ifdef NCURSES_WIDECHAR + wchar_t *input; +#else char *input; +#endif size_t input_max; size_t input_len; size_t input_pos; +#ifdef NCURSES_WIDECHAR + wchar_t *prompt; +#else char *prompt; +#endif chtype attrs; + chtype shadow; }; struct input * -init_input(unsigned int x, unsigned int y, unsigned int width, char *prompt, size_t input_len, chtype attrs); +init_input(unsigned int x, unsigned int y, unsigned int width, char *prompt, size_t input_len, chtype attrs, chtype shadow); void free_input(struct input *a); |