diff --git a/input_win.c b/input_win.c index 4077c944..9da0506c 100644 --- a/input_win.c +++ b/input_win.c @@ -30,10 +30,13 @@ * The example below shows the values of size, input, a call to wgetyx to * find the current cursor location, and the index of the input string. * - * size : " 7 " - * input : " example " - * inp_x : "012345678" - * index : " 0123456 " (inp_x - 1) + * view : |mple| + * input : "example te" + * index : "0123456789" + * inp_x : "0123456789" + * size : 10 + * pad_start : 3 + * cols : 4 */ #include @@ -63,7 +66,7 @@ void create_input_window(void) inp_win = newpad(1, MAX_INP_SIZE); wbkgd(inp_win, COLOR_PAIR(1)); keypad(inp_win, TRUE); - wmove(inp_win, 0, 1); + wmove(inp_win, 0, 0); prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } @@ -79,7 +82,7 @@ void inp_clear(void) int rows, cols; getmaxyx(stdscr, rows, cols); wclear(inp_win); - wmove(inp_win, 0, 1); + wmove(inp_win, 0, 0); pad_start = 0; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } @@ -110,13 +113,13 @@ void inp_get_char(int *ch, char *input, int *size) getyx(inp_win, inp_y, inp_x); // handle insert if not at end of input - if (inp_x <= *size) { + if (inp_x < *size) { winsch(inp_win, *ch); wmove(inp_win, inp_y, inp_x+1); - for (i = *size; i > inp_x -1; i--) + for (i = *size; i > inp_x; i--) input[i] = input[i-1]; - input[inp_x -1] = *ch; + input[inp_x] = *ch; (*size)++; @@ -148,7 +151,7 @@ void inp_get_password(char *passwd) wclear(inp_win); noecho(); mvwgetnstr(inp_win, 0, 1, passwd, 20); - wmove(inp_win, 0, 1); + wmove(inp_win, 0, 0); echo(); status_bar_clear(); } @@ -187,7 +190,7 @@ static int _handle_edit(const int ch, char *input, int *size) if (*size > 0) { // if at end, delete last char - if (inp_x > *size) { + if (inp_x >= *size) { wmove(inp_win, inp_y, inp_x-1); wdelch(inp_win); (*size)--; @@ -254,7 +257,7 @@ static int _handle_edit(const int ch, char *input, int *size) return 1; case KEY_HOME: - wmove(inp_win, inp_y, 1); + wmove(inp_win, inp_y, 0); pad_start = 0; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); return 1;