Reorganize widgets and render indent

This commit is contained in:
Joscha 2022-07-31 22:55:22 +02:00
parent 327a524c86
commit d23d7b155c
5 changed files with 83 additions and 8 deletions

View file

@ -0,0 +1,37 @@
use crossterm::style::{ContentStyle, Stylize};
use time::format_description::FormatItem;
use time::macros::format_description;
use time::OffsetDateTime;
use crate::ui::widgets::background::Background;
use crate::ui::widgets::text::Text;
use crate::ui::widgets::BoxedWidget;
const TIME_FORMAT: &[FormatItem<'_>] = format_description!("[year]-[month]-[day] [hour]:[minute]");
const TIME_EMPTY: &str = " ";
fn style() -> ContentStyle {
ContentStyle::default().grey()
}
fn style_inverted() -> ContentStyle {
ContentStyle::default().black().on_white()
}
pub fn widget(time: Option<OffsetDateTime>, highlighted: bool) -> BoxedWidget {
let text = if let Some(time) = time {
time.format(TIME_FORMAT).expect("could not format time")
} else {
TIME_EMPTY.to_string()
};
let style = if highlighted {
style_inverted()
} else {
style()
};
Background::new(Text::new((text, style)))
.style(style)
.into()
}