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

47 lines
1,007 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(LogLine::new)
.map(Line::from)
.collect::<Vec<_>>(),
))
.render(area, buf);
}
}
struct LogLine {
raw: String,
}
impl LogLine {
fn new(raw: impl Into<String>) -> Self {
Self { raw: raw.into() }
}
}
impl From<LogLine> for Line<'_> {
fn from(value: LogLine) -> Self {
Line::from(value.raw)
}
}