ghost-eye/src/components/explorer/log_explorer.rs
Uncle Stretch b3cebfa0a4
fixes for active screen and wallet screen draft added
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2024-12-02 14:16:39 +03:00

84 lines
2.3 KiB
Rust

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<String>,
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<Option<Action>> {
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(())
}
}