diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-06-27 08:57:21 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-06-27 08:59:35 +0200 |
commit | 8fe9dd1c2bb12b4909491dd54cce810e335e5c6f (patch) | |
tree | c3dc151d82d45f6cfd303a9c213d81c9c5e1f815 /src/ui-calendar.c | |
parent | 203ac0aa61cff1cd386bc0e1a74c234f8bf2681c (diff) | |
download | calcurse-8fe9dd1c2bb12b4909491dd54cce810e335e5c6f.zip |
Remove duplicate code in draw_monthly_view()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/ui-calendar.c')
-rw-r--r-- | src/ui-calendar.c | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/src/ui-calendar.c b/src/ui-calendar.c index 35c2a7e..dcafc0f 100644 --- a/src/ui-calendar.c +++ b/src/ui-calendar.c @@ -435,6 +435,8 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day, } for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7) { + unsigned attr; + check_day.dd = c_day; check_day.mm = slctd_day.mm; check_day.yyyy = slctd_day.yyyy; @@ -453,42 +455,27 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day, ofs_x = (w - 27) / 2 - day_1_sav - 4 * c_day; } - WINS_CALENDAR_LOCK; if (c_day == current_day->dd && current_day->mm == slctd_day.mm && current_day->yyyy == slctd_day.yyyy - && current_day->dd != slctd_day.dd) { - /* This is today, so print it in yellow. */ - custom_apply_attr(sw->inner, ATTR_LOWEST); - mvwprintw(sw->inner, ofs_y + 1, - ofs_x + day_1_sav + 4 * c_day + 1, "%2d", - c_day); - custom_remove_attr(sw->inner, ATTR_LOWEST); - } else if (c_day == slctd_day.dd) { - /* This is the selected day, print it according to user's theme. */ - custom_apply_attr(sw->inner, ATTR_HIGHEST); - mvwprintw(sw->inner, ofs_y + 1, - ofs_x + day_1_sav + 4 * c_day + 1, "%2d", - c_day); - custom_remove_attr(sw->inner, ATTR_HIGHEST); - } else if (item_this_day == 1) { - custom_apply_attr(sw->inner, ATTR_LOW); - mvwprintw(sw->inner, ofs_y + 1, - ofs_x + day_1_sav + 4 * c_day + 1, "%2d", - c_day); - custom_remove_attr(sw->inner, ATTR_LOW); - } else if (item_this_day == 2) { - custom_apply_attr(sw->inner, ATTR_TRUE); - mvwprintw(sw->inner, ofs_y + 1, - ofs_x + day_1_sav + 4 * c_day + 1, "%2d", - c_day); - custom_remove_attr(sw->inner, ATTR_TRUE); - } else { - /* otherwise, print normal days in black */ - mvwprintw(sw->inner, ofs_y + 1, - ofs_x + day_1_sav + 4 * c_day + 1, "%2d", - c_day); - } + && current_day->dd != slctd_day.dd) + attr = ATTR_LOWEST; + else if (c_day == slctd_day.dd) + attr = ATTR_HIGHEST; + else if (item_this_day == 1) + attr = ATTR_LOW; + else if (item_this_day == 2) + attr = ATTR_TRUE; + else + attr = 0; + + WINS_CALENDAR_LOCK; + if (attr) + custom_apply_attr(sw->inner, attr); + mvwprintw(sw->inner, ofs_y + 1, + ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); + if (attr) + custom_remove_attr(sw->inner, attr); WINS_CALENDAR_UNLOCK; } @@ -534,9 +521,9 @@ draw_weekly_view(struct scrollwin *sw, struct date *current_day, && current_day->mm == slctd_day.mm && current_day->yyyy == slctd_day.yyyy && current_day->dd != slctd_day.dd) - attr = ATTR_LOWEST; /* today, but not selected */ + attr = ATTR_LOWEST; else if (t.tm_mday == slctd_day.dd) - attr = ATTR_HIGHEST; /* selected day */ + attr = ATTR_HIGHEST; else if (item_this_day == 1) attr = ATTR_LOW; else if (item_this_day == 2) |