From e579f7585512e177e9d48edfac14d591875325cb Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 24 Jul 2023 23:27:21 -0700 Subject: [PATCH] Done with following selection --- src/handlers/app.rs | 36 +++++++++++++++++----------------- src/ui/components/debug.rs | 14 ++++++++----- src/ui/components/following.rs | 32 ++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/handlers/app.rs b/src/handlers/app.rs index c705ccb..9613e43 100644 --- a/src/handlers/app.rs +++ b/src/handlers/app.rs @@ -143,25 +143,25 @@ impl App { pub fn event(&mut self, event: &Event) -> Option { if let Event::Input(key) = event { if self.components.debug.is_focused() { - self.components.debug.event(event); + return self.components.debug.event(event); } else if self.components.following.is_focused() { - self.components.following.event(event); - } else { - match key { - // Global keybinds - Key::Ctrl('d') => { - self.components.debug.toggle_focus(); - } - Key::Char('f') => { - self.components.following.toggle_focus(); - } - _ => { - return match self.state { - State::Dashboard => self.components.dashboard.event(event), - State::Normal => self.components.chat.event(event), - State::Help => self.components.help.event(event), - }; - } + return self.components.following.event(event); + } + + match key { + // Global keybinds + Key::Ctrl('d') => { + self.components.debug.toggle_focus(); + } + Key::Char('f') => { + self.components.following.toggle_focus(); + } + _ => { + return match self.state { + State::Dashboard => self.components.dashboard.event(event), + State::Normal => self.components.chat.event(event), + State::Help => self.components.help.event(event), + }; } } } diff --git a/src/ui/components/debug.rs b/src/ui/components/debug.rs index 07a0338..7e1f334 100644 --- a/src/ui/components/debug.rs +++ b/src/ui/components/debug.rs @@ -8,9 +8,13 @@ use tui::{ use crate::{ emotes::Emotes, - handlers::{config::SharedCompleteConfig, user_input::events::{Key, Event}}, + handlers::{ + config::SharedCompleteConfig, + user_input::events::{Event, Key}, + }, + terminal::TerminalAction, ui::components::Component, - utils::text::{title_line, TitleStyle}, terminal::TerminalAction, + utils::text::{title_line, TitleStyle}, }; #[derive(Debug, Clone)] @@ -61,15 +65,15 @@ impl Component for DebugWidget { f.render_widget(table, area); } - fn event(&mut self, event: &Event) -> Option { + fn event(&mut self, event: &Event) -> Option { if let Event::Input(key) = event { match key { Key::Char('q') => return Some(TerminalAction::Quit), Key::Esc => { self.toggle_focus(); - return Some(TerminalAction::BackOneLayer) - }, + return Some(TerminalAction::BackOneLayer); + } Key::Ctrl('p') => panic!("Manual panic triggered by user."), _ => {} } diff --git a/src/ui/components/following.rs b/src/ui/components/following.rs index 5bebc50..dda6748 100644 --- a/src/ui/components/following.rs +++ b/src/ui/components/following.rs @@ -1,3 +1,5 @@ +use std::ops::Index; + use tui::{ backend::Backend, layout::{Constraint, Rect}, @@ -13,7 +15,10 @@ use crate::{ user_input::events::{Event, Key}, }, terminal::TerminalAction, - twitch::oauth::{get_channel_id, get_twitch_client, get_user_following, FollowingList}, + twitch::{ + oauth::{get_channel_id, get_twitch_client, get_user_following, FollowingList}, + TwitchAction, + }, ui::{components::Component, statics::NAME_MAX_CHARACTERS}, utils::text::{title_line, TitleStyle}, }; @@ -110,10 +115,15 @@ impl Component for FollowingWidget { .borders(Borders::ALL) .border_type(self.config.borrow().frontend.border_type.clone().into()), ) + .highlight_style( + Style::default() + .bg(Color::LightGreen) + .add_modifier(Modifier::BOLD), + ) .widths(&constraint_binding); f.render_widget(Clear, area); - f.render_widget(table, area); + f.render_stateful_widget(table, area, &mut self.state); } fn event(&mut self, event: &Event) -> Option { @@ -121,11 +131,29 @@ impl Component for FollowingWidget { match key { Key::Char('q') => return Some(TerminalAction::Quit), Key::Esc => { + self.unselect(); self.toggle_focus(); return Some(TerminalAction::BackOneLayer); } Key::Ctrl('p') => panic!("Manual panic triggered by user."), + Key::ScrollDown => self.next(), + Key::ScrollUp => self.previous(), + Key::Enter => { + if let Some(i) = self.state.selected() { + self.toggle_focus(); + + self.unselect(); + + let selected_channel = &self.following.data.index(i).broadcaster_login; + + self.config.borrow_mut().twitch.channel = selected_channel.clone(); + + return Some(TerminalAction::Enter(TwitchAction::Join( + selected_channel.clone(), + ))); + } + } _ => {} } }