deja-vu/deja_vu/src/line.rs
2025-01-15 19:17:05 -08:00

37 lines
1.2 KiB
Rust

// This file is part of Deja-vu.
//
// Deja-vu is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Deja-vu is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
//
use ratatui::{
style::{Color, Style},
text::{Line, Span},
};
use serde::{Deserialize, Serialize};
use std::iter::zip;
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DVLine {
pub line_parts: Vec<String>,
pub line_colors: Vec<Color>,
}
impl DVLine {
/// Convert to Line with colored span(s)
pub fn as_line(&self) -> Line {
let mut spans = Vec::new();
zip(self.line_parts.clone(), self.line_colors.clone())
.map(|(part, color)| spans.push(Span::styled(part, Style::default().fg(color))));
Line::from(spans)
}
}