mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Allow forwards though input history
This commit is contained in:
parent
2379ae895f
commit
8f48685930
@ -26,12 +26,12 @@
|
|||||||
|
|
||||||
static char *_inp_buf[BUFMAX];
|
static char *_inp_buf[BUFMAX];
|
||||||
static int _buf_size;
|
static int _buf_size;
|
||||||
static int _buf_prev;
|
static int _buf_pos;
|
||||||
|
|
||||||
void inpbuf_init(void)
|
void inpbuf_init(void)
|
||||||
{
|
{
|
||||||
_buf_size = 0;
|
_buf_size = 0;
|
||||||
_buf_prev = -1;
|
_buf_pos = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inpbuf_append(char *inp)
|
void inpbuf_append(char *inp)
|
||||||
@ -39,16 +39,31 @@ void inpbuf_append(char *inp)
|
|||||||
if (_buf_size < BUFMAX) {
|
if (_buf_size < BUFMAX) {
|
||||||
_inp_buf[_buf_size] = (char*) malloc(strlen(inp) * sizeof(char));
|
_inp_buf[_buf_size] = (char*) malloc(strlen(inp) * sizeof(char));
|
||||||
strcpy(_inp_buf[_buf_size], inp);
|
strcpy(_inp_buf[_buf_size], inp);
|
||||||
_buf_prev = _buf_size;
|
_buf_pos = _buf_size;
|
||||||
_buf_size++;
|
_buf_size++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *inpbuf_get_previous(void)
|
char *inpbuf_previous(void)
|
||||||
{
|
{
|
||||||
if (_buf_size == 0 || _buf_prev == -1)
|
if (_buf_size == 0 || _buf_pos == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
return _inp_buf[_buf_prev--];
|
|
||||||
|
return _inp_buf[_buf_pos--];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *inpbuf_next(void)
|
||||||
|
{
|
||||||
|
if (_buf_size == 0)
|
||||||
|
return NULL;
|
||||||
|
if (_buf_pos == (_buf_size - 1))
|
||||||
|
return NULL;
|
||||||
|
if (_buf_pos + 2 >= _buf_size)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
int pos = _buf_pos + 2;
|
||||||
|
_buf_pos++;
|
||||||
|
|
||||||
|
return _inp_buf[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void inpbuf_init(void);
|
void inpbuf_init(void);
|
||||||
void inpbuf_append(char *inp);
|
void inpbuf_append(char *inp);
|
||||||
char *inpbuf_get_previous(void);
|
char *inpbuf_previous(void);
|
||||||
|
char *inpbuf_next(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
input_win.c
14
input_win.c
@ -125,7 +125,7 @@ void inp_poll_char(int *ch, char *input, int *size)
|
|||||||
|
|
||||||
// up arrow
|
// up arrow
|
||||||
} else if (*ch == KEY_UP) {
|
} else if (*ch == KEY_UP) {
|
||||||
char *prev = inpbuf_get_previous();
|
char *prev = inpbuf_previous();
|
||||||
if (prev) {
|
if (prev) {
|
||||||
strcpy(input, prev);
|
strcpy(input, prev);
|
||||||
*size = strlen(input);
|
*size = strlen(input);
|
||||||
@ -135,6 +135,18 @@ void inp_poll_char(int *ch, char *input, int *size)
|
|||||||
waddch(inp_win, input[i]);
|
waddch(inp_win, input[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// down arrow
|
||||||
|
} else if (*ch == KEY_DOWN) {
|
||||||
|
char *next = inpbuf_next();
|
||||||
|
if (next) {
|
||||||
|
strcpy(input, next);
|
||||||
|
*size = strlen(input);
|
||||||
|
inp_clear();
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < *size; i++)
|
||||||
|
waddch(inp_win, input[i]);
|
||||||
|
}
|
||||||
|
|
||||||
// else if not error, newline or special key,
|
// else if not error, newline or special key,
|
||||||
// show it and store it
|
// show it and store it
|
||||||
} else if (*ch != ERR &&
|
} else if (*ch != ERR &&
|
||||||
|
Loading…
Reference in New Issue
Block a user