modified: src/main_screen.rs

This commit is contained in:
Michael Wain 2025-02-10 03:06:51 +03:00
parent 0e7d9aa8d9
commit 34cf8c0a15

View File

@ -1,3 +1,4 @@
use color_eyre::owo_colors::OwoColorize;
use crossterm::event::{KeyCode, KeyEvent}; use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style, Stylize}, text::{Line, Span}, widgets::{Block, Borders, Paragraph, Tabs, Widget}, Frame}; use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style, Stylize}, text::{Line, Span}, widgets::{Block, Borders, Paragraph, Tabs, Widget}, Frame};
use soundcloud::sobjects::CloudPlaylists; use soundcloud::sobjects::CloudPlaylists;
@ -7,18 +8,18 @@ use crate::screen::AppScreen;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MainScreen { pub struct MainScreen {
selected_tab: u8, selected_tab: i8,
tab_titles: Vec<String>, tab_titles: Vec<String>,
pub soundcloud: Option<CloudPlaylists> pub soundcloud: Option<CloudPlaylists>
} }
impl AppScreen for MainScreen { impl AppScreen for MainScreen {
fn handle_key_event(&mut self, key_event: KeyEvent) { fn handle_key_event(&mut self, key_event: KeyEvent) {
/*match key_event.code { match key_event.code {
KeyCode::Char('l') | KeyCode::Right => self.next_tab(), KeyCode::Char('l') | KeyCode::Right => self.next_tab(),
KeyCode::Char('h') | KeyCode::Left => self.previous_tab(), KeyCode::Char('h') | KeyCode::Left => self.previous_tab(),
_ => {} _ => {}
}*/ }
} }
fn render(&self, frame: &mut Frame) { fn render(&self, frame: &mut Frame) {
@ -46,8 +47,12 @@ impl AppScreen for MainScreen {
frame.render_widget(main_content, chunks[1]); // Render into second chunk frame.render_widget(main_content, chunks[1]); // Render into second chunk
// Render Status Bar // Render Status Bar
let status_bar = Paragraph::new("Press 'q' to quit | Arrow keys to navigate") let status_bar = Paragraph::new(
.style(Style::default().fg(Color::Cyan)); Line::from(
vec!["◄ ► to change tab".bold(), " | ".dark_gray(), "<F5> SAVE FS".bold(), " | ".dark_gray(), "<F6> DL".bold(), " | ".dark_gray(), "<F8> DEL".bold(), " | ".dark_gray(), "<Q> QUIT".bold()]
)
)
.centered();
frame.render_widget(status_bar, chunks[2]); // Render into third chunk frame.render_widget(status_bar, chunks[2]); // Render into third chunk
} }
@ -61,13 +66,11 @@ impl MainScreen {
MainScreen { soundcloud: None, selected_tab: 0, tab_titles: vec!["YouTube".to_string(), "SoundCloud".to_string(), "Local Playlists".to_string(), "Settings".to_string()] } MainScreen { soundcloud: None, selected_tab: 0, tab_titles: vec!["YouTube".to_string(), "SoundCloud".to_string(), "Local Playlists".to_string(), "Settings".to_string()] }
} }
pub fn render_title(area: Rect, buf: &mut Buffer) { fn next_tab(&mut self) {
"Lyrica".bold().render(area, buf); self.selected_tab = std::cmp::min(self.selected_tab+1, (self.tab_titles.len()-1).try_into().unwrap())
} }
pub fn render_footer(area: Rect, buf: &mut Buffer) { fn previous_tab(&mut self) {
Line::raw("◄ ► to change tab | <Q> to quit") self.selected_tab = std::cmp::max(0, self.selected_tab-1);
.centered()
.render(area, buf);
} }
} }