diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a7f84bf..64bfda6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Add strict clippy lints to improve code consistency and readability. - Expand workflow clippy task to lint all-features in workspace. - Add docs badge to readme. +- Add date select option to apply style to weekend days [#182](https://github.com/mikaelmello/inquire/pull/182). ### Fixes diff --git a/inquire/src/date_utils.rs b/inquire/src/date_utils.rs index 5be5b29b..7a4b7795 100644 --- a/inquire/src/date_utils.rs +++ b/inquire/src/date_utils.rs @@ -1,6 +1,6 @@ use core::panic; -use chrono::NaiveDate; +use chrono::{Datelike, NaiveDate, Weekday}; pub fn get_current_date() -> NaiveDate { chrono::Local::now().date_naive() @@ -27,3 +27,7 @@ pub fn get_month(month: u32) -> chrono::Month { _ => panic!("Invalid month"), } } + +pub fn is_weekend(date: NaiveDate) -> bool { + date.weekday() == Weekday::Sat || date.weekday() == Weekday::Sun +} diff --git a/inquire/src/ui/backend.rs b/inquire/src/ui/backend.rs index 7b950899..f64557d1 100644 --- a/inquire/src/ui/backend.rs +++ b/inquire/src/ui/backend.rs @@ -578,7 +578,9 @@ pub mod date { use chrono::{Datelike, Duration}; - use crate::{date_utils::get_start_date, terminal::Terminal, ui::Styled}; + use crate::{ + date_utils::get_start_date, date_utils::is_weekend, terminal::Terminal, ui::Styled, + }; use super::{Backend, CommonBackend}; @@ -695,6 +697,8 @@ pub mod date { } } else if date_it == today { style_sheet = self.render_config.calendar.today_date; + } else if is_weekend(date_it) { + style_sheet = self.render_config.calendar.weekend; } else if date_it.month() != month.number_from_month() { style_sheet = self.render_config.calendar.different_month_date; } diff --git a/inquire/src/ui/render_config.rs b/inquire/src/ui/render_config.rs index 30d72042..a6e345fe 100644 --- a/inquire/src/ui/render_config.rs +++ b/inquire/src/ui/render_config.rs @@ -467,6 +467,9 @@ pub mod calendar { /// Style sheet for dates that can not be selected due to the /// min/max settings. pub unavailable_date: StyleSheet, + + /// Style sheet for weekends + pub weekend: StyleSheet, } impl<'a> CalendarRenderConfig<'a> { @@ -480,6 +483,7 @@ pub mod calendar { today_date: StyleSheet::empty(), different_month_date: StyleSheet::empty(), unavailable_date: StyleSheet::empty(), + weekend: StyleSheet::empty(), } } @@ -497,6 +501,7 @@ pub mod calendar { today_date: StyleSheet::empty().with_fg(Color::LightGreen), different_month_date: StyleSheet::empty().with_fg(Color::DarkGrey), unavailable_date: StyleSheet::empty().with_fg(Color::DarkGrey), + weekend: StyleSheet::empty().with_fg(Color::DarkRed), } }