From 97536d2a72028b2f689ced30c7748f0dcd020087 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Sat, 28 Jun 2014 20:33:46 -0400 Subject: [PATCH] add setting option to disable timestamps --- doc/toxic.conf.5 | 9 ++++++++- misc/toxic.conf.example | 3 +++ src/misc_tools.c | 5 +++++ src/settings.c | 11 +++++++++++ src/settings.h | 8 ++++++-- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/toxic.conf.5 b/doc/toxic.conf.5 index 11036f3..2fecf20 100644 --- a/doc/toxic.conf.5 +++ b/doc/toxic.conf.5 @@ -13,7 +13,7 @@ client. Lines starting with "#" are comments and will be ignored. .PP Keys: -.RS +.PP .B time .RS Select between 24 and 12 hour time. @@ -21,6 +21,13 @@ Select between 24 and 12 hour time. Values: 24, 12 .RE .PP +.B timestamps +.RS +Enable or disable timestamps. +.br +Values: 1 to enable, 0 to disable +.RE +.PP .B autolog .RS Enable or disable autologging. diff --git a/misc/toxic.conf.example b/misc/toxic.conf.example index babf468..ea88780 100644 --- a/misc/toxic.conf.example +++ b/misc/toxic.conf.example @@ -1,6 +1,9 @@ # 24 or 12 hour time time:24; +# 1 to enable timestamps, 0 to disable +timestamps:1; + # 1 to enable autologging, 0 to disable autolog:0; diff --git a/src/misc_tools.c b/src/misc_tools.c index bc0d19f..ab9a29f 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -58,6 +58,11 @@ struct tm *get_time(void) /*Puts the current time in buf in the format of [HH:mm:ss] */ void get_time_str(uint8_t *buf, int bufsize) { + if (user_settings->timestamps == TIMESTAMPS_OFF) { + buf[0] = '\0'; + return; + } + const char *t = user_settings->time == TIME_12 ? "[%-I:%M:%S] " : "[%H:%M:%S] "; strftime(buf, bufsize, t, get_time()); } diff --git a/src/settings.c b/src/settings.c index 9b00660..be73e2d 100644 --- a/src/settings.c +++ b/src/settings.c @@ -36,6 +36,7 @@ static void uset_autolog(struct user_settings *s, const char *val); static void uset_time(struct user_settings *s, const char *val); +static void uset_timestamps(struct user_settings *s, const char *val); static void uset_alerts(struct user_settings *s, const char *val); static void uset_colours(struct user_settings *s, const char *val); static void uset_hst_size(struct user_settings *s, const char *val); @@ -52,6 +53,7 @@ struct { } user_settings_list[] = { { "autolog", uset_autolog }, { "time", uset_time }, + { "timestamps", uset_timestamps }, { "disable_alerts", uset_alerts }, { "colour_theme", uset_colours }, { "history_size", uset_hst_size }, @@ -79,6 +81,14 @@ static void uset_time(struct user_settings *s, const char *val) s->time = n == TIME_12 ? TIME_12 : TIME_24; } +static void uset_timestamps(struct user_settings *s, const char *val) +{ + int n = atoi(val); + + /* default on if invalid value */ + s->timestamps = n == TIMESTAMPS_OFF ? TIMESTAMPS_OFF : TIMESTAMPS_ON; +} + static void uset_alerts(struct user_settings *s, const char *val) { int n = atoi(val); @@ -155,6 +165,7 @@ static void set_default_settings(struct user_settings *s) /* see settings_values enum in settings.h for defaults */ uset_autolog(s, "0"); uset_time(s, "24"); + uset_timestamps(s, "1"); uset_alerts(s, "0"); uset_colours(s, "0"); uset_hst_size(s, "700"); diff --git a/src/settings.h b/src/settings.h index 3400466..515624c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -26,9 +26,9 @@ #include "toxic.h" #ifdef _SUPPORT_AUDIO - #define NUM_SETTINGS 8 + #define NUM_SETTINGS 9 #else - #define NUM_SETTINGS 6 + #define NUM_SETTINGS 7 #endif /* _SUPPORT_AUDIO */ /* holds user setting values */ @@ -36,6 +36,7 @@ struct user_settings { int autolog; /* boolean */ int alerts; /* boolean */ int time; /* 12 or 24 */ + int timestamps; /* boolean */ int colour_theme; /* boolean (0 for default toxic colours) */ int history_size; /* int between MIN_HISTORY and MAX_HISTORY */ char download_path[MAX_STR_SIZE]; @@ -53,6 +54,9 @@ enum { TIME_24 = 24, TIME_12 = 12, + TIMESTAMPS_OFF = 0, + TIMESTAMPS_ON = 1, + ALERTS_DISABLED = 1, ALERTS_ENABLED = 0,