Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 48 additions & 37 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ use tokio::sync::mpsc::UnboundedSender;

use tui_input::backend::crossterm::EventHandler;

fn forward_tab(app: &mut App) {
match app.focused_block {
FocusedBlock::Adapter => {
app.focused_block = FocusedBlock::PairedDevices;
app.reset_devices_state();
}
FocusedBlock::PairedDevices => {
if let Some(selected_controller) = app.controller_state.selected() {
let controller = &app.controllers[selected_controller];
if controller.new_devices.is_empty() {
app.focused_block = FocusedBlock::Adapter;
} else {
app.focused_block = FocusedBlock::NewDevices;
}
}
}
FocusedBlock::NewDevices => app.focused_block = FocusedBlock::Adapter,
_ => {}
}
}

fn backward_tab(app: &mut App) {
match app.focused_block {
FocusedBlock::Adapter => {
if let Some(selected_controller) = app.controller_state.selected() {
let controller = &app.controllers[selected_controller];
if controller.new_devices.is_empty() {
app.focused_block = FocusedBlock::PairedDevices;
} else {
app.focused_block = FocusedBlock::NewDevices;
}
}
}
FocusedBlock::PairedDevices => {
app.focused_block = FocusedBlock::Adapter;
}
FocusedBlock::NewDevices => {
app.focused_block = FocusedBlock::PairedDevices;
app.reset_devices_state();
}
_ => {}
}
}

pub async fn handle_key_events(
key_event: KeyEvent,
app: &mut App,
Expand Down Expand Up @@ -80,45 +124,12 @@ pub async fn handle_key_events(
}

// Switch focus
KeyCode::Tab => match app.focused_block {
FocusedBlock::Adapter => {
app.focused_block = FocusedBlock::PairedDevices;
app.reset_devices_state();
}
FocusedBlock::PairedDevices => {
if let Some(selected_controller) = app.controller_state.selected() {
let controller = &app.controllers[selected_controller];
if controller.new_devices.is_empty() {
app.focused_block = FocusedBlock::Adapter;
} else {
app.focused_block = FocusedBlock::NewDevices;
}
}
}
FocusedBlock::NewDevices => app.focused_block = FocusedBlock::Adapter,
_ => {}
KeyCode::Tab => match key_event.modifiers {
KeyModifiers::SHIFT => backward_tab(app),
_ => forward_tab(app),
},

KeyCode::BackTab => match app.focused_block {
FocusedBlock::Adapter => {
if let Some(selected_controller) = app.controller_state.selected() {
let controller = &app.controllers[selected_controller];
if controller.new_devices.is_empty() {
app.focused_block = FocusedBlock::PairedDevices;
} else {
app.focused_block = FocusedBlock::NewDevices;
}
}
}
FocusedBlock::PairedDevices => {
app.focused_block = FocusedBlock::Adapter;
}
FocusedBlock::NewDevices => {
app.focused_block = FocusedBlock::PairedDevices;
app.reset_devices_state();
}
_ => {}
},
KeyCode::BackTab => backward_tab(app),

KeyCode::Char('h') => match app.focused_block {
FocusedBlock::Adapter => {
Expand Down
Loading