1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

fixed issue #116

* don't set pad_start to 0 while typing
* use _inp_clear_no_pad() in input_win.c
This commit is contained in:
Dmitry Podgorny 2013-01-05 03:00:08 +02:00
parent f210b49285
commit 37488836fd

View File

@ -67,6 +67,7 @@ static int pad_start = 0;
static int _handle_edit(const wint_t ch, char *input, int *size);
static int _printable(const wint_t ch);
static gboolean _special_key(const wint_t ch);
static void _inp_clear_no_pad(void);
void
create_input_window(void)
@ -110,8 +111,7 @@ inp_clear(void)
{
int rows, cols;
getmaxyx(stdscr, rows, cols);
wclear(inp_win);
wmove(inp_win, 0, 0);
_inp_clear_no_pad();
pad_start = 0;
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
}
@ -165,6 +165,8 @@ inp_get_char(char *input, int *size)
// if it wasn't an arrow key etc
if (!_handle_edit(ch, input, size)) {
if (_printable(ch)) {
int rows, cols;
getmaxyx(stdscr, rows, cols);
getyx(inp_win, inp_y, inp_x);
// handle insert if not at end of input
@ -186,6 +188,11 @@ inp_get_char(char *input, int *size)
wprintw(inp_win, next_ch);
wmove(inp_win, inp_y, inp_x + 1);
if (inp_x - pad_start > cols-3) {
pad_start++;
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
}
// otherwise just append
} else {
char bytes[MB_CUR_MAX];
@ -194,14 +201,11 @@ inp_get_char(char *input, int *size)
input[(*size)++] = bytes[i];
}
input[*size] = '\0';
inp_clear();
wprintw(inp_win, input);
wprintw(inp_win, bytes);
display_size++;
// if gone over screen size follow input
int rows, cols;
getmaxyx(stdscr, rows, cols);
if (display_size - pad_start > cols-2) {
pad_start++;
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
@ -343,7 +347,7 @@ _handle_edit(const wint_t ch, char *input, int *size)
g_free(start);
inp_clear();
_inp_clear_no_pad();
wprintw(inp_win, input);
wmove(inp_win, 0, inp_x -1);
@ -363,7 +367,7 @@ _handle_edit(const wint_t ch, char *input, int *size)
g_free(end);
g_string_free(new, FALSE);
inp_clear();
_inp_clear_no_pad();
wprintw(inp_win, input);
wmove(inp_win, 0, inp_x -1);
}
@ -374,10 +378,10 @@ _handle_edit(const wint_t ch, char *input, int *size)
if (pad_start < 0) {
pad_start = 0;
}
}
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
}
}
return 1;
case KEY_DC: // DEL
@ -390,8 +394,13 @@ _handle_edit(const wint_t ch, char *input, int *size)
g_free(start);
inp_clear();
_inp_clear_no_pad();
wprintw(inp_win, input);
if (pad_start > 0) {
--pad_start;
}
} else if (inp_x < display_size-1) {
gchar *start = g_utf8_substring(input, 0, inp_x);
gchar *end = g_utf8_substring(input, inp_x+1, *size);
@ -407,10 +416,13 @@ _handle_edit(const wint_t ch, char *input, int *size)
g_free(end);
g_string_free(new, FALSE);
inp_clear();
_inp_clear_no_pad();
wprintw(inp_win, input);
wmove(inp_win, 0, inp_x);
}
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
return 1;
case KEY_LEFT:
@ -496,3 +508,10 @@ _special_key(const wint_t ch)
char *str = unctrl(ch);
return ((strlen(str) > 1) && g_str_has_prefix(str, "^"));
}
static void
_inp_clear_no_pad(void)
{
wclear(inp_win);
wmove(inp_win, 0, 0);
}