2024-08-12 21:25:24 +01:00
|
|
|
//
|
2024-08-31 13:33:45 +01:00
|
|
|
use git_next_core::git::graph::Log;
|
2024-08-12 21:25:24 +01:00
|
|
|
use ratatui::{
|
|
|
|
text::{Line, Text},
|
|
|
|
widgets::{Paragraph, Widget},
|
|
|
|
};
|
|
|
|
|
2024-08-28 09:14:02 +01:00
|
|
|
use super::HeightContraintLength;
|
2024-08-28 07:53:56 +01:00
|
|
|
|
2024-08-12 21:25:24 +01:00
|
|
|
pub struct CommitLog<'a> {
|
|
|
|
pub log: &'a Log,
|
|
|
|
}
|
2024-08-28 09:14:02 +01:00
|
|
|
impl<'a> HeightContraintLength for CommitLog<'a> {
|
|
|
|
fn height_constraint_length(&self) -> u16 {
|
|
|
|
u16::try_from(self.log.len()).unwrap_or(u16::MAX)
|
2024-08-28 07:53:56 +01:00
|
|
|
}
|
|
|
|
}
|
2024-08-12 21:25:24 +01:00
|
|
|
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()
|
2024-08-31 13:33:45 +01:00
|
|
|
.map(LogLine::new)
|
2024-08-12 21:25:24 +01:00
|
|
|
.map(Line::from)
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
))
|
|
|
|
.render(area, buf);
|
|
|
|
}
|
|
|
|
}
|
2024-08-31 13:33:45 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|