feat: improve empty hint
This commit is contained in:
parent
c704dd1a47
commit
3ff7770471
68
src/lib.rs
68
src/lib.rs
@ -428,51 +428,47 @@ impl Widget for &mut App {
|
|||||||
Color::White
|
Color::White
|
||||||
};
|
};
|
||||||
|
|
||||||
let items: Vec<Row> = self
|
let items: Vec<Row> = if self.logs.is_empty() {
|
||||||
.logs
|
vec![Row::new(vec!["Nothing here yet"])]
|
||||||
.iter()
|
} else {
|
||||||
.enumerate()
|
self.logs
|
||||||
.map(|(i, item)| {
|
.iter()
|
||||||
[
|
.enumerate()
|
||||||
item.content().replace("\n", " "),
|
.map(|(i, item)| {
|
||||||
// item.modified().format("%Y-%m-%d %H:%M:%S").to_string(),
|
[
|
||||||
item.created().format("%Y-%m-%d %H:%M:%S").to_string(),
|
item.content().replace("\n", " "),
|
||||||
]
|
// item.modified().format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||||
.into_iter()
|
item.created().format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||||
.map(|c| {
|
]
|
||||||
Cell::from(Text::from(c).style({
|
.into_iter()
|
||||||
let s = Style::new();
|
.map(|c| {
|
||||||
|
Cell::from(Text::from(c).style({
|
||||||
|
let s = Style::new();
|
||||||
|
|
||||||
if let Some(index) = self.delete
|
if let Some(index) = self.delete
|
||||||
&& i == index
|
&& i == index
|
||||||
{
|
{
|
||||||
highlight_style = Style::new().fg(Color::LightRed).bold();
|
highlight_style = Style::new().fg(Color::LightRed).bold();
|
||||||
s.fg(Color::LightRed).bold()
|
s.fg(Color::LightRed).bold()
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
})
|
||||||
|
.collect::<Row>()
|
||||||
|
.style(Style::new().fg(row_text_color))
|
||||||
|
.height(2)
|
||||||
})
|
})
|
||||||
.collect::<Row>()
|
.collect()
|
||||||
.style(Style::new().fg(row_text_color))
|
};
|
||||||
.height(2)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let empty = items.is_empty();
|
let table = Table::new(items, [Constraint::Min(200), Constraint::Min(20)])
|
||||||
|
|
||||||
let mut table = Table::new(items, [Constraint::Min(200), Constraint::Min(20)])
|
|
||||||
.block(block)
|
.block(block)
|
||||||
.header(header)
|
.header(header)
|
||||||
.highlight_symbol("> ")
|
.highlight_symbol("> ")
|
||||||
.row_highlight_style(highlight_style)
|
.row_highlight_style(highlight_style)
|
||||||
.highlight_spacing(HighlightSpacing::Always);
|
.highlight_spacing(HighlightSpacing::Always);
|
||||||
|
|
||||||
if empty {
|
|
||||||
table = table.footer(
|
|
||||||
Row::new(vec!["Nothing here yet"]).style(Style::default().fg(COLOR_SECONDARY)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
StatefulWidget::render(table, area, buf, &mut self.state);
|
StatefulWidget::render(table, area, buf, &mut self.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user