mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-12 23:23:01 +01:00
improve line history functionality
This commit is contained in:
parent
34cc4314a5
commit
10ae3865ca
@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
// #define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
/* convert a hex string to binary */
|
||||
unsigned char *hex_string_to_bin(char hex_string[]);
|
||||
|
@ -89,6 +89,20 @@ void reset_buf(wchar_t *buf, size_t *pos, size_t *len)
|
||||
*len = 0;
|
||||
}
|
||||
|
||||
#define HIST_PURGE MAX_LINE_HIST / 4
|
||||
|
||||
/* shifts hist items back and makes room for HIST_PURGE new entries */
|
||||
static void shift_hist_back(wchar_t (*hst)[MAX_STR_SIZE], int *hst_tot)
|
||||
{
|
||||
int i;
|
||||
int n = MAX_LINE_HIST - HIST_PURGE;
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
wmemcpy(hst[i], hst[i+HIST_PURGE], MAX_STR_SIZE);
|
||||
|
||||
*hst_tot = n;
|
||||
}
|
||||
|
||||
/* adds a line to the ln_history buffer at hst_pos and sets hst_pos to end of history. */
|
||||
void add_line_to_hist(const wchar_t *buf, size_t len, wchar_t (*hst)[MAX_STR_SIZE], int *hst_tot,
|
||||
int *hst_pos)
|
||||
@ -96,17 +110,12 @@ void add_line_to_hist(const wchar_t *buf, size_t len, wchar_t (*hst)[MAX_STR_SIZ
|
||||
if (len > MAX_STR_SIZE)
|
||||
return;
|
||||
|
||||
/* If history is full make room for newest entry and don't increment hst_tot */
|
||||
if (*hst_tot == MAX_LINE_HIST) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_LINE_HIST - 1; ++i)
|
||||
wmemcpy(hst[i], hst[i+1], MAX_STR_SIZE);
|
||||
} else {
|
||||
++(*hst_tot);
|
||||
}
|
||||
if (*hst_tot >= MAX_LINE_HIST)
|
||||
shift_hist_back(hst, hst_tot);
|
||||
|
||||
++(*hst_tot);
|
||||
*hst_pos = *hst_tot;
|
||||
|
||||
wmemcpy(hst[*hst_tot-1], buf, len + 1);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
#define T_KEY_KILL 0xB /* ctrl-k */
|
||||
#define T_KEY_DISCARD 0x15 /* ctrl-u */
|
||||
#define T_KEY_NEXT 0x10 /* ctrl-p */
|
||||
#define T_KEY_PREV 0x0f /* ctrl-o */
|
||||
#define T_KEY_PREV 0x0F /* ctrl-o */
|
||||
|
||||
/* Curses foreground colours (background is black) */
|
||||
enum {
|
||||
@ -111,7 +111,7 @@ struct StatusBar {
|
||||
bool is_online;
|
||||
};
|
||||
|
||||
#define MAX_LINE_HIST 64
|
||||
#define MAX_LINE_HIST 128
|
||||
|
||||
/* chat and groupchat window/buffer holder */
|
||||
struct ChatContext {
|
||||
|
Loading…
Reference in New Issue
Block a user