1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-04 20:16:44 +02:00

allow line editing via arrow keys in chat/groupchat windows

This commit is contained in:
Jfreegman
2013-11-30 22:12:43 -05:00
parent c25296e65a
commit bb6b28b7c3
5 changed files with 135 additions and 24 deletions

View File

@ -223,25 +223,41 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
/* BACKSPACE key: Remove one character from line */
if (key == 0x107 || key == 0x8 || key == 0x7f) {
if (ctx->pos > 0) {
ctx->line[--ctx->pos] = L'\0';
del_char_from_buf(key, ctx->line, &ctx->pos, &ctx->len);
if (x == 0)
mvwdelch(self->window, y - 1, x2 - 1);
wmove(self->window, y-1, x2-1);
else
mvwdelch(self->window, y, x - 1);
wmove(self->window, y, x-1);
}
} else
/* Add printable chars to buffer and print on input space */
} else if (key == KEY_LEFT && ctx->pos > 0) {
--ctx->pos;
if (x == 0)
wmove(self->window, y-1, x2-1);
else
wmove(self->window, y, x-1);
} else if (key == KEY_RIGHT && ctx->line[ctx->pos] != L'\0') {
++ctx->pos;
if (x == x2-1)
wmove(self->window, y+1, 0);
else
wmove(self->window, y, x+1);
} else
#if HAVE_WIDECHAR
if (iswprint(key))
#else
if (isprint(key))
#endif
{
if (ctx->pos < (MAX_STR_SIZE-1)) {
mvwaddstr(self->window, y, x, wc_to_char(key));
ctx->line[ctx->pos++] = key;
ctx->line[ctx->pos] = L'\0';
{ /* prevents buffer overflows and strange behaviour when cursor goes past the window */
if ( (ctx->len < MAX_STR_SIZE-1) && (ctx->len < (x2 * (CHATBOX_HEIGHT - 1)-1)) ) {
add_char_to_buf(key, ctx->line, &ctx->pos, &ctx->len);
if (x == x2-1)
wmove(self->window, y+1, 0);
else
wmove(self->window, y, x+1);
}
}
@ -287,8 +303,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
if (close_win)
free(ctx);
else {
ctx->line[0] = L'\0';
ctx->pos = 0;
reset_buf(ctx->line, &ctx->pos, &ctx->len);
}
free(line);
@ -302,6 +317,10 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
getmaxyx(self->window, y, x);
ChatContext *ctx = self->chatwin;
wclear(ctx->linewin);
mvwprintw(ctx->linewin, 1, 0, "%s\n", wcs_to_char(ctx->line));
wclrtobot(ctx->sidebar);
mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x);
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y-CHATBOX_HEIGHT);
@ -338,7 +357,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
ChatContext *ctx = self->chatwin;
ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x-SIDEBAR_WIDTH-1, 0, 0);
scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, 2, x, y-CHATBOX_HEIGHT, 0);
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x, y-CHATBOX_HEIGHT, 0);
ctx->sidebar = subwin(self->window, y-CHATBOX_HEIGHT+1, SIDEBAR_WIDTH, 0, x-SIDEBAR_WIDTH);
print_groupchat_help(ctx);