Done with following selection

This commit is contained in:
Xithrius 2023-07-24 23:27:21 -07:00
parent 20a6500632
commit e579f75855
No known key found for this signature in database
GPG Key ID: DF6738B80C155B71
3 changed files with 57 additions and 25 deletions

View File

@ -143,25 +143,25 @@ impl App {
pub fn event(&mut self, event: &Event) -> Option<TerminalAction> {
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),
};
}
}
}

View File

@ -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<TerminalAction> {
fn event(&mut self, event: &Event) -> Option<TerminalAction> {
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."),
_ => {}
}

View File

@ -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<TerminalAction> {
@ -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(),
)));
}
}
_ => {}
}
}