Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add weekend styling option #182

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add date select option to apply style to weekend days [#182](https://github.com/mikaelmello/inquire/pull/182).
- **Breaking**. Enabled by default, added date select option to apply style to weekend days [#182](https://github.com/mikaelmello/inquire/pull/182).


### Fixes

Expand Down
6 changes: 5 additions & 1 deletion inquire/src/date_utils.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
}
6 changes: 5 additions & 1 deletion inquire/src/ui/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't make a difference when both colors are the same, but in the case they're different, I think the (day in the prev/next month) style should have precedence over the (day is weekend) style.

Like in this example:
image

image

I feel the second screenshot represents a better UX when parsing the calendar

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;
}
Expand Down
5 changes: 5 additions & 0 deletions inquire/src/ui/render_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -480,6 +483,7 @@ pub mod calendar {
today_date: StyleSheet::empty(),
different_month_date: StyleSheet::empty(),
unavailable_date: StyleSheet::empty(),
weekend: StyleSheet::empty(),
}
}

Expand All @@ -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),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
weekend: StyleSheet::empty().with_fg(Color::DarkRed),
weekend: StyleSheet::empty().with_fg(Color::DarkGrey),
image image

It's not that I necessarily defend grey as being the ultimate UX choice, but I think the red implies some information in a way, as if it's an unavailable date.

}
}

Expand Down
Loading