use color_eyre::Result; use ratatui::{ layout::{Alignment, Rect}, text::Line, widgets::{Block, Paragraph, Wrap}, Frame }; use super::{Component, CurrentTab, PartialComponent}; use crate::{ action::Action, config::Config, palette::StylePalette, }; pub struct LogExplorer { is_active: bool, maybe_log: Option, palette: StylePalette, } impl Default for LogExplorer { fn default() -> Self { Self::new() } } impl LogExplorer { pub fn new() -> Self { Self { is_active: false, maybe_log: None, palette: StylePalette::default(), } } } impl PartialComponent for LogExplorer { fn set_active(&mut self, _current_tab: CurrentTab) {} } impl Component for LogExplorer { fn register_config_handler(&mut self, config: Config) -> Result<()> { if let Some(style) = config.styles.get(&crate::app::Mode::Explorer) { self.palette.with_normal_style(style.get("normal_style").copied()); self.palette.with_normal_border_style(style.get("normal_border_style").copied()); self.palette.with_normal_title_style(style.get("normal_title_style").copied()); } Ok(()) } fn update(&mut self, action: Action) -> Result> { match action { Action::UsedExplorerLog(maybe_log) => self.maybe_log = maybe_log, _ => {}, }; Ok(None) } fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> { let [_, _, place] = super::explorer_layout(area); let (border_style, border_type) = self.palette.create_border_style(self.is_active); let line = match &self.maybe_log { Some(log) => Line::from(hex::encode(log)), None => Line::from(""), }; let paragraph = Paragraph::new(line) .block(Block::bordered() .border_style(border_style) .border_type(border_type) .title_alignment(Alignment::Right) .title_style(self.palette.create_title_style(false)) .title("Logs")) .alignment(Alignment::Center) .wrap(Wrap { trim: true }); frame.render_widget(paragraph, place); Ok(()) } }