From 8ba47220ff3415902c9bc1ea22349a09ef838203 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 20:56:49 +0100 Subject: [PATCH 01/14] Changed input window to use pad instead of window --- input_win.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/input_win.c b/input_win.c index 6958dc1b..a52c5c68 100644 --- a/input_win.c +++ b/input_win.c @@ -58,12 +58,11 @@ void create_input_window(void) int rows, cols; getmaxyx(stdscr, rows, cols); - inp_win = newwin(1, cols, rows-1, 0); + inp_win = newpad(1, cols); wbkgd(inp_win, COLOR_PAIR(1)); keypad(inp_win, TRUE); -// wattrset(inp_win, A_BOLD); wmove(inp_win, 0, 1); - wrefresh(inp_win); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); } void inp_win_resize(const char * const input, const int size) @@ -71,15 +70,16 @@ void inp_win_resize(const char * const input, const int size) int rows, cols; getmaxyx(stdscr, rows, cols); mvwin(inp_win, rows-1, 0); - wresize(inp_win, 1, cols); - wrefresh(inp_win); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); } void inp_clear(void) { + int rows, cols; + getmaxyx(stdscr, rows, cols); wclear(inp_win); wmove(inp_win, 0, 1); - wrefresh(inp_win); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); } void inp_non_block(void) @@ -146,7 +146,9 @@ void inp_get_password(char *passwd) void inp_put_back(void) { - wrefresh(inp_win); + int rows, cols; + getmaxyx(stdscr, rows, cols); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); } /* From 7cfbf1cdc9a1ffe1bed432617fe7671e9c1ab1f9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 21:12:14 +0100 Subject: [PATCH 02/14] Max size added for input --- input_win.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/input_win.c b/input_win.c index a52c5c68..a1545755 100644 --- a/input_win.c +++ b/input_win.c @@ -48,6 +48,7 @@ #include "command.h" static WINDOW *inp_win; +static int MAX_INP_SIZE = 1000; static int _handle_edit(const int ch, char *input, int *size); static int _printable(const int ch); @@ -58,19 +59,18 @@ void create_input_window(void) int rows, cols; getmaxyx(stdscr, rows, cols); - inp_win = newpad(1, cols); + inp_win = newpad(1, MAX_INP_SIZE); wbkgd(inp_win, COLOR_PAIR(1)); keypad(inp_win, TRUE); wmove(inp_win, 0, 1); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); } void inp_win_resize(const char * const input, const int size) { int rows, cols; getmaxyx(stdscr, rows, cols); - mvwin(inp_win, rows-1, 0); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); } void inp_clear(void) @@ -79,7 +79,7 @@ void inp_clear(void) getmaxyx(stdscr, rows, cols); wclear(inp_win); wmove(inp_win, 0, 1); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); } void inp_non_block(void) @@ -148,7 +148,7 @@ void inp_put_back(void) { int rows, cols; getmaxyx(stdscr, rows, cols); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols); + prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); } /* From 5e490fb1fed6272448dd19bd9fc63a60f3abbff4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 21:24:39 +0100 Subject: [PATCH 03/14] Formatting comment --- input_win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input_win.c b/input_win.c index a1545755..d8e61f12 100644 --- a/input_win.c +++ b/input_win.c @@ -99,7 +99,7 @@ void inp_get_char(int *ch, char *input, int *size) int i; -// echo off, and get some more input + // echo off, and get some more input noecho(); *ch = wgetch(inp_win); From ed4377e228fcdb281f3853d3908a790e09763a07 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 21:51:43 +0100 Subject: [PATCH 04/14] Input follows cursor when longer than screen --- input_win.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/input_win.c b/input_win.c index d8e61f12..803570ad 100644 --- a/input_win.c +++ b/input_win.c @@ -49,6 +49,7 @@ static WINDOW *inp_win; static int MAX_INP_SIZE = 1000; +static int pad_start = 0; static int _handle_edit(const int ch, char *input, int *size); static int _printable(const int ch); @@ -63,14 +64,14 @@ void create_input_window(void) wbkgd(inp_win, COLOR_PAIR(1)); keypad(inp_win, TRUE); wmove(inp_win, 0, 1); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } void inp_win_resize(const char * const input, const int size) { int rows, cols; getmaxyx(stdscr, rows, cols); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); + prefresh(inp_win, pad_start, 0, rows-1, 0, rows-1, cols-1); } void inp_clear(void) @@ -79,7 +80,8 @@ void inp_clear(void) getmaxyx(stdscr, rows, cols); wclear(inp_win); wmove(inp_win, 0, 1); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); + pad_start = 0; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } void inp_non_block(void) @@ -123,6 +125,14 @@ void inp_get_char(int *ch, char *input, int *size) } else { waddch(inp_win, *ch); input[(*size)++] = *ch; + + // if gone over screen size follow input + int rows, cols; + getmaxyx(stdscr, rows, cols); + if (*size > cols-2) { + pad_start++; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + } } reset_search_attempts(); @@ -148,7 +158,7 @@ void inp_put_back(void) { int rows, cols; getmaxyx(stdscr, rows, cols); - prefresh(inp_win, 0, 0, rows-1, 0, rows-1, cols-1); + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } /* From 8abba0db914bc8e8286aa2517b76ff1d7d3e17a2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 21:59:01 +0100 Subject: [PATCH 05/14] Home key moves to start of pad --- input_win.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/input_win.c b/input_win.c index 803570ad..a32ee4d7 100644 --- a/input_win.c +++ b/input_win.c @@ -168,7 +168,7 @@ void inp_put_back(void) */ static int _handle_edit(const int ch, char *input, int *size) { - int i; + int i, rows, cols; char *prev = NULL; char *next = NULL; char *found = NULL; @@ -177,6 +177,7 @@ static int _handle_edit(const int ch, char *input, int *size) int inp_x = 0; char inp_cpy[*size]; + getmaxyx(stdscr, rows, cols); getyx(inp_win, inp_y, inp_x); switch(ch) { @@ -243,6 +244,8 @@ static int _handle_edit(const int ch, char *input, int *size) case KEY_HOME: wmove(inp_win, inp_y, 1); + pad_start = 0; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); return 1; case KEY_END: From 78e70abc17f1290001cd9c05beab04f46d292596 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 22:19:01 +0100 Subject: [PATCH 06/14] End key moves to end of pad --- input_win.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/input_win.c b/input_win.c index a32ee4d7..97099dc1 100644 --- a/input_win.c +++ b/input_win.c @@ -226,7 +226,7 @@ static int _handle_edit(const int ch, char *input, int *size) return 1; case KEY_RIGHT: - if (inp_x <= *size ) + if (inp_x <= *size) wmove(inp_win, inp_y, inp_x+1); return 1; @@ -249,6 +249,10 @@ static int _handle_edit(const int ch, char *input, int *size) return 1; case KEY_END: + if (*size > cols-2) { + pad_start = ((*size) - cols) + 2; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + } wmove(inp_win, inp_y, (*size) + 1); return 1; From 859a0591256f65b900da38509c4b4fb809c21e12 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 7 Jul 2012 23:57:52 +0100 Subject: [PATCH 07/14] Removed whitespace --- input_win.c | 1 - 1 file changed, 1 deletion(-) diff --git a/input_win.c b/input_win.c index 97099dc1..d497ee5d 100644 --- a/input_win.c +++ b/input_win.c @@ -99,7 +99,6 @@ void inp_get_char(int *ch, char *input, int *size) int inp_y = 0; int inp_x = 0; int i; - // echo off, and get some more input noecho(); From 5fb985152f2deadbff8fa707f1b014f9de4d36c5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 02:21:39 +0100 Subject: [PATCH 08/14] Left, right keys scroll input --- input_win.c | 60 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/input_win.c b/input_win.c index d497ee5d..4077c944 100644 --- a/input_win.c +++ b/input_win.c @@ -128,7 +128,7 @@ void inp_get_char(int *ch, char *input, int *size) // if gone over screen size follow input int rows, cols; getmaxyx(stdscr, rows, cols); - if (*size > cols-2) { + if (*size - pad_start > cols-2) { pad_start++; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } @@ -222,36 +222,48 @@ static int _handle_edit(const int ch, char *input, int *size) case KEY_LEFT: if (inp_x > 1) wmove(inp_win, inp_y, inp_x-1); + + // current position off screen to left + if (inp_x < pad_start) { + pad_start--; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + } return 1; case KEY_RIGHT: if (inp_x <= *size) wmove(inp_win, inp_y, inp_x+1); - return 1; - - case KEY_UP: - prev = history_previous(input, size); - if (prev) - _replace_input(input, prev, size); - return 1; - - case KEY_DOWN: - next = history_next(input, size); - if (next) - _replace_input(input, next, size); - return 1; - - case KEY_HOME: - wmove(inp_win, inp_y, 1); - pad_start = 0; - prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); - return 1; - - case KEY_END: - if (*size > cols-2) { - pad_start = ((*size) - cols) + 2; + + // current position off screen to right + if ((inp_x - pad_start) > cols-2) { + pad_start++; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } + return 1; + + case KEY_UP: + prev = history_previous(input, size); + if (prev) + _replace_input(input, prev, size); + return 1; + + case KEY_DOWN: + next = history_next(input, size); + if (next) + _replace_input(input, next, size); + return 1; + + case KEY_HOME: + wmove(inp_win, inp_y, 1); + pad_start = 0; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + return 1; + + case KEY_END: + if (*size > cols-2) { + pad_start = ((*size) - cols) + 2; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + } wmove(inp_win, inp_y, (*size) + 1); return 1; From 15a87f0abb3ddeee425e23f8ab99eaa01abaadfc Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 02:43:28 +0100 Subject: [PATCH 09/14] Delete working on new placement of input win --- input_win.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) 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; From 2d8c21b3ec82dd7309300bdc0bb3e5e82146b376 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 02:52:46 +0100 Subject: [PATCH 10/14] Delete in middle of input --- input_win.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/input_win.c b/input_win.c index 9da0506c..2094ff4d 100644 --- a/input_win.c +++ b/input_win.c @@ -196,8 +196,8 @@ static int _handle_edit(const int ch, char *input, int *size) (*size)--; // if in middle, delete and shift chars left - } else if (inp_x > 1 && inp_x <= *size) { - for (i = inp_x-1; i < *size; i++) + } else if (inp_x > 0 && inp_x < *size) { + for (i = inp_x; i < *size; i++) input[i-1] = input[i]; (*size)--; From 82d7a1d2736e3c1f71c92d1eba9e8a0b4b56f3de Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 02:56:14 +0100 Subject: [PATCH 11/14] DEL key --- input_win.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/input_win.c b/input_win.c index 2094ff4d..6fe7a3f8 100644 --- a/input_win.c +++ b/input_win.c @@ -210,12 +210,12 @@ static int _handle_edit(const int ch, char *input, int *size) return 1; case KEY_DC: // DEL - if (inp_x <= *size) { + if (inp_x < *size) { wdelch(inp_win); // if not last char, shift chars left - if (inp_x < *size) - for (i = inp_x-1; i < *size; i++) + if (inp_x < *size - 1) + for (i = inp_x; i < *size; i++) input[i] = input[i+1]; (*size)--; From 157a864ffe1b4c95cc9b93fdfb9abf132c8d4a88 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 02:59:19 +0100 Subject: [PATCH 12/14] Left arrow --- input_win.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/input_win.c b/input_win.c index 6fe7a3f8..0d34e894 100644 --- a/input_win.c +++ b/input_win.c @@ -223,11 +223,11 @@ static int _handle_edit(const int ch, char *input, int *size) return 1; case KEY_LEFT: - if (inp_x > 1) + if (inp_x > 0) wmove(inp_win, inp_y, inp_x-1); // current position off screen to left - if (inp_x < pad_start) { + if (inp_x - 1 < pad_start) { pad_start--; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } From d92499da7927b5ab4212d9353cfde20f0df56691 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 03:18:39 +0100 Subject: [PATCH 13/14] Home and end keys --- input_win.c | 57 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/input_win.c b/input_win.c index 0d34e894..0322885e 100644 --- a/input_win.c +++ b/input_win.c @@ -234,40 +234,47 @@ static int _handle_edit(const int ch, char *input, int *size) return 1; case KEY_RIGHT: - if (inp_x <= *size) + if (inp_x < *size) { wmove(inp_win, inp_y, inp_x+1); - // current position off screen to right - if ((inp_x - pad_start) > cols-2) { - pad_start++; + // current position off screen to right + if ((inp_x + 1 - pad_start) >= cols) { + pad_start++; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + } + } + return 1; + + case KEY_UP: + prev = history_previous(input, size); + if (prev) { + _replace_input(input, prev, size); + pad_start = 0; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); } return 1; - case KEY_UP: - prev = history_previous(input, size); - if (prev) - _replace_input(input, prev, size); - return 1; - - case KEY_DOWN: - next = history_next(input, size); - if (next) - _replace_input(input, next, size); - return 1; - - case KEY_HOME: - wmove(inp_win, inp_y, 0); + case KEY_DOWN: + next = history_next(input, size); + if (next) { + _replace_input(input, next, size); pad_start = 0; prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); - return 1; + } + return 1; - case KEY_END: - if (*size > cols-2) { - pad_start = ((*size) - cols) + 2; - prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); - } - wmove(inp_win, inp_y, (*size) + 1); + case KEY_HOME: + wmove(inp_win, inp_y, 0); + pad_start = 0; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + return 1; + + case KEY_END: + wmove(inp_win, inp_y, *size); + if (*size > cols-2) { + pad_start = *size - cols + 1; + prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); + } return 1; case 9: // tab From 0cfda7e11ca7143511d436341dbbb8e8c1bb51eb Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Jul 2012 03:31:54 +0100 Subject: [PATCH 14/14] Started resize --- input_win.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/input_win.c b/input_win.c index 0322885e..44c77302 100644 --- a/input_win.c +++ b/input_win.c @@ -72,8 +72,15 @@ void create_input_window(void) void inp_win_resize(const char * const input, const int size) { - int rows, cols; + int rows, cols, inp_x, inp_y; getmaxyx(stdscr, rows, cols); + getyx(inp_win, inp_y, inp_x); + + // if lost cursor off screen, move contents to show it + if (inp_x >= pad_start + cols) { + pad_start = inp_x - 10; + } + prefresh(inp_win, pad_start, 0, rows-1, 0, rows-1, cols-1); }