diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2017-09-05 09:29:17 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2017-09-08 21:08:53 +0200 |
commit | d20f9a5d2e5b9903f7412cdec9e1bf28a94d02da (patch) | |
tree | e57836c1d8f3847baaa90538f758475950914709 | |
parent | 172efd71798a00469658b0f0e6fc730bac6fa5fe (diff) | |
download | calcurse-d20f9a5d2e5b9903f7412cdec9e1bf28a94d02da.tar.gz calcurse-d20f9a5d2e5b9903f7412cdec9e1bf28a94d02da.zip |
Make the day heading position configurable
The date at the top of the appointments list may be positioned either to
the left, in the middle or to the right. Default is to the right. Can be
configured from the general options menu.
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r-- | src/calcurse.h | 7 | ||||
-rw-r--r-- | src/config.c | 27 | ||||
-rw-r--r-- | src/custom.c | 24 | ||||
-rw-r--r-- | src/ui-day.c | 5 | ||||
-rw-r--r-- | src/vars.c | 1 |
5 files changed, 62 insertions, 2 deletions
diff --git a/src/calcurse.h b/src/calcurse.h index 133b6b9..2707305 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -249,6 +249,12 @@ enum win { NBWINS }; +enum pos { + LEFT, + CENTER, + RIGHT +}; + /* General configuration variables. */ struct conf { unsigned auto_save; @@ -265,6 +271,7 @@ struct conf { const char *mergetool; char output_datefmt[BUFSIZ]; /* format for displaying date */ int input_datefmt; /* format for reading date */ + enum pos heading_pos; /* left/center/right for heading in appts panel */ char day_heading[BUFSIZ]; /* format for displaying heading in appts panel */ }; diff --git a/src/config.c b/src/config.c index 896b192..c46d718 100644 --- a/src/config.c +++ b/src/config.c @@ -77,6 +77,8 @@ static int config_parse_input_datefmt(void *, const char *); static int config_serialize_input_datefmt(char **, void *); static int config_parse_notifyall(void *, const char *); static int config_serialize_notifyall(char **, void *); +static int config_parse_heading_pos(void *, const char *); +static int config_serialize_heading_pos(char **, void *); #define CONFIG_HANDLER_BOOL(var) (config_fn_parse_t) config_parse_bool, \ (config_fn_serialize_t) config_serialize_bool, &(var) @@ -96,6 +98,7 @@ static const struct confvar confmap[] = { {"appearance.sidebarwidth", config_parse_sidebar_width, config_serialize_sidebar_width, NULL}, {"appearance.theme", config_parse_color_theme, config_serialize_color_theme, NULL}, {"appearance.todoview", config_parse_todo_view, config_serialize_todo_view, NULL}, + {"appearance.headingpos", config_parse_heading_pos, config_serialize_heading_pos, NULL}, {"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)}, {"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)}, {"format.inputdate", config_parse_input_datefmt, config_serialize_input_datefmt, NULL}, @@ -307,6 +310,19 @@ static int config_parse_notifyall(void *dummy, const char *val) return 1; } +static int config_parse_heading_pos(void *dummy, const char *val) +{ + if (!strcmp(val, "left-justified")) + conf.heading_pos = LEFT; + else if (!strcmp(val, "centered")) + conf.heading_pos = CENTER; + else if (!strcmp(val, "right-justified")) + conf.heading_pos = RIGHT; + else + return 0; + return 1; +} + /* Set a configuration variable. */ static int config_set_conf(const char *key, const char *value) { @@ -482,6 +498,17 @@ static int config_serialize_notifyall(char **buf, void *dummy) return 1; } +static int config_serialize_heading_pos(char **buf, void *dummy) +{ + if (conf.heading_pos == LEFT) + *buf = mem_strdup("left-justified"); + else if (conf.heading_pos == CENTER) + *buf = mem_strdup("centered"); + else + *buf = mem_strdup("right-justified"); + return 1; +} + /* Serialize the value of a configuration variable. */ static int config_serialize_conf(char **buf, const char *key, diff --git a/src/custom.c b/src/custom.c index 1826156..4d02b4f 100644 --- a/src/custom.c +++ b/src/custom.c @@ -528,6 +528,7 @@ enum { FIRST_DAY_OF_WEEK, OUTPUT_DATE_FMT, INPUT_DATE_FMT, + HEADING_POS, DAY_HEADING_FMT, NB_OPTIONS }; @@ -549,9 +550,11 @@ static void print_general_option(int i, WINDOW *win, int y, int hilt, void *cb_d "general.firstdayofweek = ", "format.outputdate = ", "format.inputdate = ", + "appearance.headingposition = ", "format.dayheading = " }; const char *panel; + const char *position; if (hilt) custom_apply_attr(win, ATTR_HIGHEST); @@ -653,6 +656,19 @@ static void print_general_option(int i, WINDOW *win, int y, int hilt, void *cb_d datefmt_str[0], datefmt_str[1], datefmt_str[2], datefmt_str[3]); break; + case HEADING_POS: + if (conf.heading_pos == LEFT) + position = _("to the left"); + else if (conf.heading_pos == CENTER) + position = _("in the middle"); + else + position = _("to the right"); + custom_apply_attr(win, ATTR_HIGHEST); + mvwaddstr(win, y, XPOS + strlen(opt[HEADING_POS]), position); + custom_remove_attr(win, ATTR_HIGHEST); + mvwaddstr(win, y + 1, XPOS, + _("(position of the heading in the appointments panel)")); + break; case DAY_HEADING_FMT: custom_apply_attr(win, ATTR_HIGHEST); mvwaddstr(win, y, XPOS + strlen(opt[DAY_HEADING_FMT]), @@ -674,7 +690,7 @@ static enum listbox_row_type general_option_row_type(int i, void *cb_data) static int general_option_height(int i, void *cb_data) { - if (i == 11) + if (i == INPUT_DATE_FMT) return 4; else return 3; @@ -704,6 +720,12 @@ static void general_option_edit(int i) else conf.default_panel++; break; + case HEADING_POS: + if (conf.heading_pos == RIGHT) + conf.heading_pos = LEFT; + else + conf.heading_pos++; + break; case AUTO_SAVE: conf.auto_save = !conf.auto_save; break; diff --git a/src/ui-day.c b/src/ui-day.c index 6a06941..0be23af 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -938,7 +938,10 @@ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) char *buf = fmt_day_heading(date); utf8_chop(buf, width); custom_apply_attr(win, ATTR_HIGHEST); - mvwprintw(win, y, width - utf8_strwidth(buf) - 1, "%s", buf); + mvwprintw(win, y, + conf.heading_pos == RIGHT ? width - utf8_strwidth(buf) - 1 : + conf.heading_pos == LEFT ? 1 : + (width - utf8_strwidth(buf)) / 2, "%s", buf); custom_remove_attr(win, ATTR_HIGHEST); mem_free(buf); } else if (item->type == DAY_SEPARATOR) { @@ -121,6 +121,7 @@ void vars_init(void) conf.progress_bar = 1; strncpy(conf.output_datefmt, "%D", 3); conf.input_datefmt = 1; + conf.heading_pos = RIGHT; strcpy(conf.day_heading, DAY_HEADING_DEFAULT); datefmt_str[0] = _("mm/dd/yyyy"); |