diff --git a/src/Spectre.Console/Extensions/CalendarExtensions.cs b/src/Spectre.Console/Extensions/CalendarExtensions.cs index 8662626..7ea9358 100644 --- a/src/Spectre.Console/Extensions/CalendarExtensions.cs +++ b/src/Spectre.Console/Extensions/CalendarExtensions.cs @@ -10,10 +10,11 @@ public static class CalendarExtensions /// /// The calendar to add the calendar event to. /// The calendar event date. + /// The calendar event custom highlight style. /// The same instance so that multiple calls can be chained. - public static Calendar AddCalendarEvent(this Calendar calendar, DateTime date) + public static Calendar AddCalendarEvent(this Calendar calendar, DateTime date, Style? customEventHighlightStyle = null) { - return AddCalendarEvent(calendar, string.Empty, date.Year, date.Month, date.Day); + return AddCalendarEvent(calendar, string.Empty, date.Year, date.Month, date.Day, customEventHighlightStyle); } /// @@ -22,10 +23,11 @@ public static class CalendarExtensions /// The calendar to add the calendar event to. /// The calendar event description. /// The calendar event date. + /// The calendar event custom highlight style. /// The same instance so that multiple calls can be chained. - public static Calendar AddCalendarEvent(this Calendar calendar, string description, DateTime date) + public static Calendar AddCalendarEvent(this Calendar calendar, string description, DateTime date, Style? customEventHighlightStyle = null) { - return AddCalendarEvent(calendar, description, date.Year, date.Month, date.Day); + return AddCalendarEvent(calendar, description, date.Year, date.Month, date.Day, customEventHighlightStyle); } /// @@ -35,10 +37,11 @@ public static class CalendarExtensions /// The year of the calendar event. /// The month of the calendar event. /// The day of the calendar event. + /// The calendar event custom highlight style. /// The same instance so that multiple calls can be chained. - public static Calendar AddCalendarEvent(this Calendar calendar, int year, int month, int day) + public static Calendar AddCalendarEvent(this Calendar calendar, int year, int month, int day, Style? customEventHighlightStyle = null) { - return AddCalendarEvent(calendar, string.Empty, year, month, day); + return AddCalendarEvent(calendar, string.Empty, year, month, day, customEventHighlightStyle); } /// @@ -49,15 +52,16 @@ public static class CalendarExtensions /// The year of the calendar event. /// The month of the calendar event. /// The day of the calendar event. + /// The calendar event custom highlight style. /// The same instance so that multiple calls can be chained. - public static Calendar AddCalendarEvent(this Calendar calendar, string description, int year, int month, int day) + public static Calendar AddCalendarEvent(this Calendar calendar, string description, int year, int month, int day, Style? customEventHighlightStyle = null) { if (calendar is null) { throw new ArgumentNullException(nameof(calendar)); } - calendar.CalendarEvents.Add(new CalendarEvent(description, year, month, day)); + calendar.CalendarEvents.Add(new CalendarEvent(description, year, month, day, customEventHighlightStyle)); return calendar; } @@ -65,7 +69,7 @@ public static class CalendarExtensions /// Sets the calendar's highlight . /// /// The calendar. - /// The highlight style. + /// The default highlight style. /// The same instance so that multiple calls can be chained. public static Calendar HighlightStyle(this Calendar calendar, Style? style) { diff --git a/src/Spectre.Console/Widgets/Calendar.cs b/src/Spectre.Console/Widgets/Calendar.cs index 18f1589..0448cdd 100644 --- a/src/Spectre.Console/Widgets/Calendar.cs +++ b/src/Spectre.Console/Widgets/Calendar.cs @@ -195,10 +195,11 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde while (currentDay <= daysInMonth) { if (weekdays[currentDay - 1] == weekday) - { - if (_calendarEvents.Any(e => e.Month == Month && e.Day == currentDay)) + { + var todayEvent = _calendarEvents.LastOrDefault(e => e.Month == Month && e.Day == currentDay); + if (todayEvent != null) { - row.Add(new Markup(currentDay.ToString(CultureInfo.InvariantCulture) + "*", _highlightStyle)); + row.Add(new Markup(currentDay.ToString(CultureInfo.InvariantCulture) + "*", todayEvent.CustomHighlightStyle ?? _highlightStyle)); } else { diff --git a/src/Spectre.Console/Widgets/CalendarEvent.cs b/src/Spectre.Console/Widgets/CalendarEvent.cs index 68f3dc7..588e720 100644 --- a/src/Spectre.Console/Widgets/CalendarEvent.cs +++ b/src/Spectre.Console/Widgets/CalendarEvent.cs @@ -25,29 +25,38 @@ public sealed class CalendarEvent /// public int Day { get; } + /// + /// Gets the custom highlight style of the calendar event. + /// + public Style? CustomHighlightStyle { get; } + /// /// Initializes a new instance of the class. /// /// The year of the calendar event. /// The month of the calendar event. - /// The day of the calendar event. - public CalendarEvent(int year, int month, int day) - : this(string.Empty, year, month, day) + /// The day of the calendar event. + /// The custom highlight style of the calendar event. + public CalendarEvent(int year, int month, int day, Style? customHighlightStyle = null) + : this(string.Empty, year, month, day, customHighlightStyle) { - } - + } + /// /// Initializes a new instance of the class. /// /// The calendar event description. /// The year of the calendar event. /// The month of the calendar event. - /// The day of the calendar event. - public CalendarEvent(string description, int year, int month, int day) + /// The day of the calendar event. + /// The custom highlight style of the calendar event. + public CalendarEvent(string description, int year, int month, int day, Style? customHighlightStyle = null) { Description = description ?? string.Empty; Year = year; Month = month; - Day = day; + Day = day; + CustomHighlightStyle = customHighlightStyle; + } } \ No newline at end of file