aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/global_keys.rs24
-rw-r--r--src/components/hello_world.rs25
-rw-r--r--src/components/mod.rs1
3 files changed, 15 insertions, 35 deletions
diff --git a/src/components/global_keys.rs b/src/components/global_keys.rs
index 27adab0..6537339 100644
--- a/src/components/global_keys.rs
+++ b/src/components/global_keys.rs
@@ -24,11 +24,11 @@ pub struct GlobalKeys {
impl Component for GlobalKeys {
fn init(&mut self) -> eyre::Result<()> {
- self.key_commands.push(KeyCommand {
+ self.key_commands.append(&mut vec![KeyCommand {
key_code: "?".to_string(),
description: "Toggle help menu".to_string(),
action: None,
- });
+ }]);
self.scroll_state =
ScrollbarState::new(self.key_commands.len()).position(self.scroll);
@@ -45,26 +45,32 @@ impl Component for GlobalKeys {
let eat_input = match key_event.as_str() {
"?" => {
self.should_show = !self.should_show;
+ self.scroll = 0;
true
}
- "down" => {
+ "g" => {
+ self.scroll = 0;
+ true
+ }
+ "G" => {
+ self.scroll = self.key_commands.len() - 1;
+ true
+ }
+ "down" | "j" => {
if self.scroll < self.key_commands.len() - 1 {
self.scroll += 1;
- self.scroll_state =
- self.scroll_state.position(self.scroll);
}
true
}
- "up" => {
+ "up" | "k" => {
if self.scroll > 0 {
self.scroll -= 1;
- self.scroll_state =
- self.scroll_state.position(self.scroll);
}
true
}
_ => false,
};
+ self.scroll_state = self.scroll_state.position(self.scroll);
if eat_input && self.should_show {
return Ok(None);
}
@@ -119,7 +125,7 @@ impl Component for GlobalKeys {
.block(block)
.wrap(Wrap { trim: true })
.scroll((u16::try_from(self.scroll)?, 0))
- .style(Style::default().bg(Color::DarkGray).fg(Color::LightYellow));
+ .style(Style::default().bg(Color::DarkGray).fg(Color::White));
if self.should_show {
frame.render_widget(Clear, center);
diff --git a/src/components/hello_world.rs b/src/components/hello_world.rs
deleted file mode 100644
index ac9d02b..0000000
--- a/src/components/hello_world.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-use ratatui::prelude::{Frame, Rect};
-use ratatui::widgets::{Paragraph, Wrap};
-
-use crate::component::Component;
-
-#[derive(Default, Clone)]
-pub struct HelloWorld {
- pub text: String,
-}
-
-impl Component for HelloWorld {
- fn init(&mut self) -> eyre::Result<()> {
- self.text = "Hello, world!".to_string();
- Ok(())
- }
-
- fn render(&mut self, frame: &mut Frame, rect: Rect) -> eyre::Result<()> {
- frame.render_widget(
- Paragraph::new(self.text.clone()).wrap(Wrap { trim: true }),
- rect,
- );
-
- Ok(())
- }
-}
diff --git a/src/components/mod.rs b/src/components/mod.rs
index 78abbca..07fe4d8 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -1,2 +1 @@
-pub mod hello_world;
pub mod global_keys;