git-next/crates/cli/src/tui/components/history.rs

33 lines
766 B
Rust
Raw Normal View History

use git_next_core::git::graph::Log;
//
use ratatui::{
text::{Line, Text},
widgets::{Paragraph, Widget},
};
use super::HeightContraintLength;
pub struct CommitLog<'a> {
pub log: &'a Log,
}
impl<'a> HeightContraintLength for CommitLog<'a> {
fn height_constraint_length(&self) -> u16 {
u16::try_from(self.log.len()).unwrap_or(u16::MAX)
}
}
impl<'a> Widget for CommitLog<'a> {
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer)
where
Self: Sized,
{
Paragraph::new(Text::from(
self.log
.iter()
.map(ToString::to_string)
.map(Line::from)
.collect::<Vec<_>>(),
))
.render(area, buf);
}
}