Author: mesyeti <mesyeti@mesyeti.uk>
add clock and title to config
docs/config.md | 12 ++++++++++++ example_config.ini | 4 ++++ source/app.c | 33 +++++++++++++++++++++------------ source/app.h | 4 ++++ source/config.c | 25 +++++++++++++++++++++++++
diff --git a/docs/config.md b/docs/config.md index bae90fe6c0f1c2b584749cd0135f05231112fd60..3ee1cf76b453d4b3643722aea44cc9e0ef4db08b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -13,3 +13,15 @@ ### `file` Used to select which bitmap font is used. This points to a file in the `~/.config/yterm` folder. + +## Display section (`[display]`) +### `clock` +Whether the clock is displayed. + +Default = `true` + +### `title` +Whether the active pane title is displayed. Does not affect whether the active pane +title is used in the terminal's window title. + +Default = `true` diff --git a/example_config.ini b/example_config.ini index 99a54b1122c6f2a79e744402a9ca2a952f40526f..29f0139242bba2dc5d122eda3e387c2bbc4d58ef 100644 --- a/example_config.ini +++ b/example_config.ini @@ -1,3 +1,7 @@ [font] type = bitmap file = default_7x16.png + +[display] +clock = true +title = true diff --git a/source/app.c b/source/app.c index 57662e3b083240ba3aa48ddf66256779db42e948..4a56f93053ff92321d6ce27681aaf46bf50b8e5f 100644 --- a/source/app.c +++ b/source/app.c @@ -12,6 +12,10 @@ void App_Init(void) { app.running = true; + // default config + app.renderTitle = true; + app.renderClock = true; + Event_Init(); Window_Init(); Video_Init("yterm"); @@ -162,23 +166,28 @@ snprintf(info, sizeof(info), "yterm - [%d/%d]", (int) app.tabSel + 1, (int) app.tabNum); Buffer_Print(&screen.buffer, 0, 0, bar.attr, info); // clock - time_t now = time(NULL); - if (now != -1) { - struct tm* timeInfo = localtime(&now); + if (app.renderClock) { + time_t now = time(NULL); + + if (now != -1) { + struct tm* timeInfo = localtime(&now); - char time[32]; - snprintf( - time, sizeof(time), "%.2d:%.2d:%.2d", timeInfo->tm_hour, timeInfo->tm_min, - timeInfo->tm_sec - ); + char time[32]; + snprintf( + time, sizeof(time), "%.2d:%.2d:%.2d", timeInfo->tm_hour, timeInfo->tm_min, + timeInfo->tm_sec + ); - Buffer_Print(&screen.buffer, screen.buffer.width - strlen(time), 0, bar.attr, time); + Buffer_Print(&screen.buffer, screen.buffer.width - strlen(time), 0, bar.attr, time); + } } - char* title = app.paneSel->v.terminal.title; - int titleX = (screen.buffer.width / 2) - (strlen(title) / 2); + if (app.renderTitle) { + char* title = app.paneSel->v.terminal.title; + int titleX = (screen.buffer.width / 2) - (strlen(title) / 2); - Buffer_Print(&screen.buffer, titleX, 0, bar.attr, title); + Buffer_Print(&screen.buffer, titleX, 0, bar.attr, title); + } Rect within = {0, 1, screen.buffer.width, screen.buffer.height - 1}; Pane_Render(&app.tabs[app.tabSel], within); diff --git a/source/app.h b/source/app.h index 817b1fc73c570f4c336fab280a7d4362ae6f620b..b416f7cf7f86bddacbda1de9450f24cc1613ebc0 100644 --- a/source/app.h +++ b/source/app.h @@ -23,6 +23,10 @@ Input_BindID bindNextTab; Input_BindID bindReport; Input_BindID bindRedraw; Input_BindID bindPaste; + + // config + bool renderTitle; + bool renderClock; } App; extern App app; diff --git a/source/config.c b/source/config.c index ee5a859c5d1bc6a3e91565a7d94912627fab7f5b..695409e1c75545b0a5da0d92d11ea51458a5e769 100644 --- a/source/config.c +++ b/source/config.c @@ -1,3 +1,4 @@ +#include "app.h" #include "util.h" #include "config.h" #include "screen.h" @@ -15,6 +16,19 @@ CONF_FONT_TTF }; static int fontState; + +static const char* ParseBool(char* val, bool* out) { + if (strcmp(val, "true") == 0) { + *out = true; + return NULL; + } + else if (strcmp(val, "false") == 0) { + *out = false; + return NULL; + } + + return "Invalid boolean value"; +} static const char* Callback(char* sect, char* key, char* val, void* data) { (void) data; @@ -62,6 +76,17 @@ free(folder); screen.font = Font_FromBMFont(font); screen.fontLoaded = true; + } + else { + return "Invalid key"; + } + } + else if (strcmp(sect, "display") == 0) { + if (strcmp(key, "clock") == 0) { + return ParseBool(val, &app.renderClock); + } + else if (strcmp(key, "title") == 0) { + return ParseBool(val, &app.renderTitle); } else { return "Invalid key";