diff --git a/misc/toxic.conf b/misc/toxic.conf index b480f4f..455b0fa 100644 --- a/misc/toxic.conf +++ b/misc/toxic.conf @@ -7,6 +7,9 @@ autolog:0; # 1 to disbale terminal alerts on messages, 0 to enable disable_alerts:0; +# maximum lines for chat window history +history_size:700; + # 1 to use native terminal colours, 0 to use toxic default colour theme colour_theme:0; diff --git a/src/line_info.c b/src/line_info.c index 923613a..655d0d5 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -31,6 +31,9 @@ #include "toxic_windows.h" #include "line_info.h" #include "groupchat.h" +#include "settings.h" + +extern struct user_settings *user_settings; void line_info_init(struct history *hst) { @@ -164,7 +167,7 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na hst->line_end->next = new_line; hst->line_end = new_line; - if (++hst->line_items > MAX_HISTORY) { + if (++hst->line_items > user_settings->history_size) { --hst->line_items; line_info_root_fwd(hst); } @@ -216,7 +219,7 @@ void line_info_print(ToxWindow *self) getmaxyx(self->window, y2, x2); if (self->is_prompt) - y2 = MAX_HISTORY; /* temporary fix to make prompt scroll */ + y2 = user_settings->history_size; /* temporary fix to make prompt scroll */ if (x2 <= SIDEBAR_WIDTH) return; diff --git a/src/line_info.h b/src/line_info.h index be0e1e3..3d921e5 100644 --- a/src/line_info.h +++ b/src/line_info.h @@ -20,7 +20,8 @@ * */ -#define MAX_HISTORY 700 +#define MAX_HISTORY 10000 +#define MIN_HISTORY 20 enum { SYS_MSG, diff --git a/src/settings.c b/src/settings.c index 877e920..0e14d9d 100644 --- a/src/settings.c +++ b/src/settings.c @@ -27,6 +27,7 @@ #include "configdir.h" #include "audio_call.h" #include "settings.h" +#include "line_info.h" static void uset_autolog(struct user_settings *s, int val); static void uset_time(struct user_settings *s, int val); @@ -34,6 +35,7 @@ static void uset_alerts(struct user_settings *s, int val); static void uset_colours(struct user_settings *s, int val); static void uset_ain_dev(struct user_settings *s, int val); static void uset_aout_dev(struct user_settings *s, int val); +static void uset_hst_size(struct user_settings *s, int val); struct { const char *name; @@ -45,6 +47,7 @@ struct { { "colour_theme", uset_colours }, { "audio_in_dev", uset_ain_dev }, { "audio_out_dev", uset_aout_dev }, + { "history_size", uset_hst_size }, }; static void uset_autolog(struct user_settings *s, int val) @@ -87,6 +90,12 @@ static void uset_aout_dev(struct user_settings *s, int val) s->audio_out_dev = (long int) val; } +static void uset_hst_size(struct user_settings *s, int val) +{ + /* if val is out of range use default history size */ + s->history_size = (val > MAX_HISTORY || val < MIN_HISTORY) ? DFLT_HST_SIZE : val; +} + int settings_load(struct user_settings *s, char *path) { char *user_config_dir = get_user_config_dir(); @@ -102,6 +111,8 @@ int settings_load(struct user_settings *s, char *path) free(user_config_dir); + uset_hst_size(s, DFLT_HST_SIZE); /* must be forced in case no setting specified */ + if (fp == NULL && !path) { if ((fp = fopen(dflt_path, "w")) == NULL) return -1; diff --git a/src/settings.h b/src/settings.h index 4c75051..a989030 100644 --- a/src/settings.h +++ b/src/settings.h @@ -20,7 +20,7 @@ * */ -#define NUM_SETTINGS 6 +#define NUM_SETTINGS 7 /* holds user setting values */ struct user_settings { @@ -30,6 +30,7 @@ struct user_settings { int colour_theme; /* boolean (0 for default toxic colours) */ long int audio_in_dev; long int audio_out_dev; + int history_size; /* int between MIN_HISTORY and MAX_HISTORY */ }; enum { @@ -44,6 +45,8 @@ enum { NATIVE_COLS = 1, DFLT_COLS = 0, + + DFLT_HST_SIZE = 700, }; int settings_load(struct user_settings *s, char *path);