Reorganize widgets and render indent
This commit is contained in:
parent
327a524c86
commit
d23d7b155c
5 changed files with 83 additions and 8 deletions
|
|
@ -1,37 +0,0 @@
|
|||
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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue