use key config in connections component

pull/33/head
Takayuki Maeda 3 years ago
parent f729793356
commit 46bfb9e7cf

@ -42,7 +42,7 @@ impl App {
Self {
focus: Focus::ConnectionList,
config: config.clone(),
connections: ConnectionsComponent::new(config.conn),
connections: ConnectionsComponent::new(config.key_config.clone(), config.conn),
record_table: RecordTableComponent::default(),
structure_table: TableComponent::default(),
tab: TabComponent::default(),

@ -1,6 +1,6 @@
use super::{Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::config::Connection;
use crate::config::{Connection, KeyConfig};
use crate::event::Key;
use anyhow::Result;
use tui::{
@ -15,22 +15,15 @@ use tui::{
pub struct ConnectionsComponent {
connections: Vec<Connection>,
state: ListState,
}
impl Default for ConnectionsComponent {
fn default() -> Self {
Self {
connections: Vec::new(),
state: ListState::default(),
}
}
key_config: KeyConfig,
}
impl ConnectionsComponent {
pub fn new(connections: Vec<Connection>) -> Self {
pub fn new(key_config: KeyConfig, connections: Vec<Connection>) -> Self {
Self {
connections,
..Self::default()
key_config,
state: ListState::default(),
}
}
@ -103,16 +96,12 @@ impl Component for ConnectionsComponent {
fn commands(&self, out: &mut Vec<CommandInfo>) {}
fn event(&mut self, key: Key) -> Result<EventState> {
match key {
Key::Char('j') => {
self.next_connection();
return Ok(EventState::Consumed);
}
Key::Char('k') => {
self.previous_connection();
return Ok(EventState::Consumed);
}
_ => (),
if key == self.key_config.move_down {
self.next_connection();
return Ok(EventState::Consumed);
} else if key == self.key_config.move_up {
self.previous_connection();
return Ok(EventState::Consumed);
}
Ok(EventState::NotConsumed)
}

Loading…
Cancel
Save