Cal updates (#1945)

* Clean up `use` statements

* Update cal code to be ready for future data coloring
This commit is contained in:
Joseph T. Lyons 2020-06-06 23:52:42 -04:00 committed by GitHub
parent bef9669b85
commit 160191e9f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,9 @@
use crate::commands::{command::EvaluatedWholeStreamCommandArgs, WholeStreamCommand};
use crate::prelude::*; use crate::prelude::*;
use chrono::{Datelike, Local, NaiveDate}; use chrono::{Datelike, Local, NaiveDate};
use nu_errors::ShellError;
use nu_protocol::Dictionary;
use crate::commands::{command::EvaluatedWholeStreamCommandArgs, WholeStreamCommand};
use indexmap::IndexMap; use indexmap::IndexMap;
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value}; use nu_errors::ShellError;
use nu_protocol::{Dictionary, Signature, SyntaxShape, UntaggedValue, Value};
pub struct Cal; pub struct Cal;
@ -250,7 +248,7 @@ fn add_month_to_table(
tag: &Tag, tag: &Tag,
selected_year: i32, selected_year: i32,
current_month: u32, current_month: u32,
_current_day_option: Option<u32>, // Can be used in the future to display current day current_day_option: Option<u32>,
) -> Result<(), ShellError> { ) -> Result<(), ShellError> {
let month_helper_result = MonthHelper::new(selected_year, current_month); let month_helper_result = MonthHelper::new(selected_year, current_month);
@ -316,14 +314,23 @@ fn add_month_to_table(
} }
for day in &days_of_the_week { for day in &days_of_the_week {
let value = if (day_count <= day_limit) let should_add_day_number_to_table =
&& (day_count > month_helper.day_number_month_starts_on) (day_count <= day_limit) && (day_count > month_helper.day_number_month_starts_on);
{
UntaggedValue::int(day_count - month_helper.day_number_month_starts_on) let mut value = UntaggedValue::nothing().into_value(tag);
.into_value(tag)
} else { if should_add_day_number_to_table {
UntaggedValue::nothing().into_value(tag) let day_count_with_offset = day_count - month_helper.day_number_month_starts_on;
};
value = UntaggedValue::int(day_count_with_offset).into_value(tag);
if let Some(current_day) = current_day_option {
if current_day == day_count_with_offset {
// TODO: Update the value here with a color when color support is added
// This colors the current day
}
}
}
indexmap.insert((*day).to_string(), value); indexmap.insert((*day).to_string(), value);