mirror of
https://github.com/Tha14/toxic.git
synced 2025-06-30 08:26:45 +02:00
allow line editing via arrow keys in chat/groupchat windows
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "toxic_windows.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
// XXX: FIX
|
||||
unsigned char *hex_string_to_bin(char hex_string[])
|
||||
@ -158,3 +159,62 @@ bool valid_nick(uint8_t *nick)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Buffer helper tools. Assumes buffers are no larger than MAX_STR_SIZE
|
||||
*/
|
||||
|
||||
/* Adds char to buffer at pos */
|
||||
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 */
|
||||
int i;
|
||||
|
||||
for (i = *len; i >= *pos && i >= 0; --i)
|
||||
buf[i+1] = buf[i];
|
||||
|
||||
buf[(*pos)++] = ch;
|
||||
++(*len);
|
||||
}
|
||||
|
||||
/* Deletes the character before pos via the backspace key */
|
||||
void del_char_from_buf(wint_t ch, 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 */
|
||||
for (i = *pos-1; i <= *len; ++i)
|
||||
buf[i] = buf[i+1];
|
||||
|
||||
--(*pos);
|
||||
--(*len);
|
||||
}
|
||||
|
||||
/* sets pos and len to 0 */
|
||||
void reset_buf(wchar_t *buf, size_t *pos, size_t *len)
|
||||
{
|
||||
buf[0] = L'\0';
|
||||
*pos = 0;
|
||||
*len = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user