mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 20:13:24 +01:00
minor improvements
This commit is contained in:
parent
192a06c4f0
commit
b1b2cc44df
20
src/chat.c
20
src/chat.c
@ -289,17 +289,25 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
else
|
||||
wmove(self->window, y, x-1);
|
||||
}
|
||||
} else if (key == KEY_DC) { /* DEL key: Remove character at pos */
|
||||
}
|
||||
|
||||
else if (key == KEY_DC) { /* DEL key: Remove character at pos */
|
||||
del_char_buf_frnt(ctx->line, &ctx->pos, &ctx->len);
|
||||
} else if (key == KEY_HOME) { /* HOME key: Move cursor to beginning of line */
|
||||
}
|
||||
|
||||
else if (key == KEY_HOME) { /* HOME key: Move cursor to beginning of line */
|
||||
ctx->pos = 0;
|
||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||
} else if (key == KEY_END) { /* END key: move cursor to end of line */
|
||||
}
|
||||
|
||||
else if (key == KEY_END) { /* END key: move cursor to end of line */
|
||||
ctx->pos = ctx->len;
|
||||
int end_y = (ctx->len / x2) + (y2 - CURS_Y_OFFSET);
|
||||
int end_x = ctx->len % x2;
|
||||
wmove(self->window, end_y, end_x);
|
||||
} else if (key == KEY_LEFT) {
|
||||
}
|
||||
|
||||
else if (key == KEY_LEFT) {
|
||||
if (ctx->pos > 0) {
|
||||
--ctx->pos;
|
||||
|
||||
@ -308,7 +316,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
else
|
||||
wmove(self->window, y, x-1);
|
||||
}
|
||||
} else if (key == KEY_RIGHT) {
|
||||
}
|
||||
|
||||
else if (key == KEY_RIGHT) {
|
||||
if (ctx->pos < ctx->len) {
|
||||
++ctx->pos;
|
||||
|
||||
|
@ -161,7 +161,8 @@ bool valid_nick(uint8_t *nick)
|
||||
}
|
||||
|
||||
/*
|
||||
* Buffer helper tools. Assumes buffers are no larger than MAX_STR_SIZE
|
||||
* Buffer helper tools.
|
||||
* Assumes buffers are no larger than MAX_STR_SIZE and are always null terminated at len
|
||||
*/
|
||||
|
||||
/* Adds char to buffer at pos */
|
||||
@ -170,15 +171,7 @@ void add_char_to_buf(wint_t ch, wchar_t *buf, size_t *pos, size_t *len)
|
||||
if (*pos < 0 || *len >= MAX_STR_SIZE)
|
||||
return;
|
||||
|
||||
/* if cursor is at end of line simply insert char at last position and increment */
|
||||
if (buf[*pos] == L'\0') {
|
||||
buf[(*pos)++] = ch;
|
||||
buf[*pos] = L'\0';
|
||||
++(*len);
|
||||
return;
|
||||
}
|
||||
|
||||
/* move all chars in front of pos one space forward and insert char in pos */
|
||||
/* move all chars including null in front of pos one space forward and insert char in pos */
|
||||
int i;
|
||||
|
||||
for (i = *len; i >= *pos && i >= 0; --i)
|
||||
@ -194,13 +187,6 @@ void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len)
|
||||
if (*pos <= 0)
|
||||
return;
|
||||
|
||||
/* if cursor is at end of line delete previous char */
|
||||
if (buf[*pos] == L'\0') {
|
||||
buf[--(*pos)] = L'\0';
|
||||
--(*len);
|
||||
return;
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
/* similar to add_char_to_buf but deletes a char */
|
||||
|
21
src/prompt.c
21
src/prompt.c
@ -54,18 +54,19 @@ void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
|
||||
Returns request number on success, -1 if queue is full or other error. */
|
||||
static int add_friend_request(uint8_t *public_key)
|
||||
{
|
||||
if (num_frnd_requests < MAX_FRIENDS_NUM) {
|
||||
int i;
|
||||
if (num_frnd_requests >= MAX_FRIENDS_NUM)
|
||||
return;
|
||||
|
||||
for (i = 0; i <= num_frnd_requests; ++i) {
|
||||
if (!strlen(pending_frnd_requests[i])) {
|
||||
memcpy(pending_frnd_requests[i], public_key, TOX_CLIENT_ID_SIZE);
|
||||
int i;
|
||||
|
||||
if (i == num_frnd_requests)
|
||||
++num_frnd_requests;
|
||||
for (i = 0; i <= num_frnd_requests; ++i) {
|
||||
if (!strlen(pending_frnd_requests[i])) {
|
||||
memcpy(pending_frnd_requests[i], public_key, TOX_CLIENT_ID_SIZE);
|
||||
|
||||
return i;
|
||||
}
|
||||
if (i == num_frnd_requests)
|
||||
++num_frnd_requests;
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,4 +283,4 @@ ToxWindow new_prompt(void)
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user