1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 23:53:28 +01:00

add setting to control history size

This commit is contained in:
Jfreegman 2014-05-25 19:54:34 -04:00
parent 083ca2f3b7
commit f0962bd060
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 25 additions and 4 deletions

View File

@ -7,6 +7,9 @@ autolog:0;
# 1 to disbale terminal alerts on messages, 0 to enable # 1 to disbale terminal alerts on messages, 0 to enable
disable_alerts:0; 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 # 1 to use native terminal colours, 0 to use toxic default colour theme
colour_theme:0; colour_theme:0;

View File

@ -31,6 +31,9 @@
#include "toxic_windows.h" #include "toxic_windows.h"
#include "line_info.h" #include "line_info.h"
#include "groupchat.h" #include "groupchat.h"
#include "settings.h"
extern struct user_settings *user_settings;
void line_info_init(struct history *hst) 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->next = new_line;
hst->line_end = new_line; hst->line_end = new_line;
if (++hst->line_items > MAX_HISTORY) { if (++hst->line_items > user_settings->history_size) {
--hst->line_items; --hst->line_items;
line_info_root_fwd(hst); line_info_root_fwd(hst);
} }
@ -216,7 +219,7 @@ void line_info_print(ToxWindow *self)
getmaxyx(self->window, y2, x2); getmaxyx(self->window, y2, x2);
if (self->is_prompt) 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) if (x2 <= SIDEBAR_WIDTH)
return; return;

View File

@ -20,7 +20,8 @@
* *
*/ */
#define MAX_HISTORY 700 #define MAX_HISTORY 10000
#define MIN_HISTORY 20
enum { enum {
SYS_MSG, SYS_MSG,

View File

@ -27,6 +27,7 @@
#include "configdir.h" #include "configdir.h"
#include "audio_call.h" #include "audio_call.h"
#include "settings.h" #include "settings.h"
#include "line_info.h"
static void uset_autolog(struct user_settings *s, int val); static void uset_autolog(struct user_settings *s, int val);
static void uset_time(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_colours(struct user_settings *s, int val);
static void uset_ain_dev(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_aout_dev(struct user_settings *s, int val);
static void uset_hst_size(struct user_settings *s, int val);
struct { struct {
const char *name; const char *name;
@ -45,6 +47,7 @@ struct {
{ "colour_theme", uset_colours }, { "colour_theme", uset_colours },
{ "audio_in_dev", uset_ain_dev }, { "audio_in_dev", uset_ain_dev },
{ "audio_out_dev", uset_aout_dev }, { "audio_out_dev", uset_aout_dev },
{ "history_size", uset_hst_size },
}; };
static void uset_autolog(struct user_settings *s, int val) 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; 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) int settings_load(struct user_settings *s, char *path)
{ {
char *user_config_dir = get_user_config_dir(); 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); 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 == NULL && !path) {
if ((fp = fopen(dflt_path, "w")) == NULL) if ((fp = fopen(dflt_path, "w")) == NULL)
return -1; return -1;

View File

@ -20,7 +20,7 @@
* *
*/ */
#define NUM_SETTINGS 6 #define NUM_SETTINGS 7
/* holds user setting values */ /* holds user setting values */
struct user_settings { struct user_settings {
@ -30,6 +30,7 @@ struct user_settings {
int colour_theme; /* boolean (0 for default toxic colours) */ int colour_theme; /* boolean (0 for default toxic colours) */
long int audio_in_dev; long int audio_in_dev;
long int audio_out_dev; long int audio_out_dev;
int history_size; /* int between MIN_HISTORY and MAX_HISTORY */
}; };
enum { enum {
@ -44,6 +45,8 @@ enum {
NATIVE_COLS = 1, NATIVE_COLS = 1,
DFLT_COLS = 0, DFLT_COLS = 0,
DFLT_HST_SIZE = 700,
}; };
int settings_load(struct user_settings *s, char *path); int settings_load(struct user_settings *s, char *path);