molehole/src/components/hello_world.rs

34 lines
755 B
Rust
Raw Normal View History

2024-03-06 06:11:00 +00:00
use ratatui::prelude::*;
use ratatui::widgets::Paragraph;
2024-03-06 19:14:07 +00:00
use crate::app_action::AppAction;
2024-03-06 06:11:00 +00:00
use crate::component::Component;
2024-03-06 19:14:07 +00:00
use crate::keys::key_commands::*;
2024-03-06 06:11:00 +00:00
#[derive(Default, Clone)]
pub struct HelloWorld {
pub text: String,
}
impl Component for HelloWorld {
2024-03-06 16:45:18 +00:00
fn init(&mut self) -> eyre::Result<()> {
self.text = "Hello, world!".to_string();
Ok(())
}
2024-03-06 19:14:07 +00:00
fn handle_key_event(
&mut self,
key: crossterm::event::KeyEvent,
) -> eyre::Result<Option<AppAction>> {
self.text = serialize_key_event(key);
Ok(None)
}
2024-03-06 06:11:00 +00:00
fn render(&mut self, frame: &mut Frame, rect: Rect) -> eyre::Result<()> {
2024-03-06 19:14:07 +00:00
2024-03-06 06:11:00 +00:00
frame.render_widget(Paragraph::new(self.text.clone()), rect);
Ok(())
}
}