Warnings fix
modified: src/main.rs modified: src/main_screen.rs modified: src/screen.rs modified: src/sync.rs modified: src/util.rs modified: src/wait_screen.rs
This commit is contained in:
parent
adb52e01ac
commit
f337a6de1f
18
src/main.rs
18
src/main.rs
@ -1,15 +1,14 @@
|
||||
use std::{any::Any, cell::RefCell, collections::HashMap, error::Error, io, ops::Deref, path::{Path, PathBuf}};
|
||||
use std::{collections::HashMap, error::Error, io};
|
||||
|
||||
use color_eyre::Result;
|
||||
use crossterm::{event::{self, DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode, KeyEvent, KeyEventKind}, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}};
|
||||
use crossterm::{event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode, KeyEvent, KeyEventKind}, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}};
|
||||
use futures::StreamExt;
|
||||
use ratatui::{buffer::Buffer, layout::{Layout, Rect}, prelude::{Backend, CrosstermBackend}, style::{Color, Stylize}, symbols::border, text::{Line, Text}, widgets::{Block, Paragraph, Tabs, Widget}, DefaultTerminal, Frame, Terminal};
|
||||
use ratatui::{prelude::{Backend, CrosstermBackend}, widgets::Widget, Frame, Terminal};
|
||||
use main_screen::MainScreen;
|
||||
use screen::AppScreen;
|
||||
use sync::AppEvent;
|
||||
use tokio::{fs::File, io::AsyncReadExt, sync::mpsc::{self, Receiver, Sender, UnboundedReceiver, UnboundedSender}};
|
||||
use tokio::sync::mpsc::{self, Receiver, UnboundedSender};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use ratatui::prelude::Constraint::{Length, Min};
|
||||
use wait_screen::WaitScreen;
|
||||
|
||||
mod dlp;
|
||||
@ -36,8 +35,8 @@ pub struct App {
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
let (tx, mut rx) = mpsc::channel(10);
|
||||
let (jx, mut jr) = mpsc::unbounded_channel();
|
||||
let (tx, rx) = mpsc::channel(10);
|
||||
let (jx, jr) = mpsc::unbounded_channel();
|
||||
let token = CancellationToken::new();
|
||||
|
||||
sync::initialize_async_service(tx, jr, token.clone());
|
||||
@ -107,10 +106,7 @@ impl App {
|
||||
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
self.screens.get_mut(&self.state).unwrap().handle_key_event(key_event);
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') => self.exit(),
|
||||
_ => {}
|
||||
}
|
||||
if let KeyCode::Char('q') = key_event.code { self.exit() }
|
||||
}
|
||||
|
||||
fn exit(&mut self) {
|
||||
|
@ -1,8 +1,7 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use rascii_art::{charsets, render_image_to, render_to, RenderOptions};
|
||||
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style, Stylize}, text::{Line, Span, Text}, widgets::{Block, Borders, Gauge, List, ListItem, Paragraph, Row, Table, Tabs, Widget}, Frame};
|
||||
use rascii_art::{charsets, render_image_to, RenderOptions};
|
||||
use ratatui::{layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style, Stylize}, text::{Line, Span}, widgets::{Block, Borders, Gauge, Paragraph, Tabs}, Frame};
|
||||
use soundcloud::sobjects::CloudPlaylists;
|
||||
use strum::IntoEnumIterator;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
@ -122,18 +121,15 @@ impl MainScreen {
|
||||
}
|
||||
|
||||
fn download_row(&mut self) {
|
||||
match self.selected_tab {
|
||||
1 => {// SC
|
||||
let playlist_url = self.soundcloud.as_ref().unwrap().get(self.selected_row as usize).unwrap().link.clone();
|
||||
let _ = self.sender.send(AppEvent::DownloadPlaylist(playlist_url));
|
||||
},
|
||||
_ => {}
|
||||
if self.selected_tab == 1 {// SC
|
||||
let playlist_url = self.soundcloud.as_ref().unwrap().get(self.selected_row as usize).unwrap().link.clone();
|
||||
let _ = self.sender.send(AppEvent::DownloadPlaylist(playlist_url));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_soundcloud_playlists(&mut self, pl: CloudPlaylists) {
|
||||
self.soundcloud = Some(
|
||||
pl.collection.iter().map(|p| Playlist { name: p.title.clone(), thumbnail_url: p.artwork_url.as_deref().map_or(String::new(), |u| self.ascii_art_from_url(&u)), link: p.permalink_url.clone() }).collect()
|
||||
pl.collection.iter().map(|p| Playlist { name: p.title.clone(), thumbnail_url: p.artwork_url.as_deref().map_or(String::new(), |u| self.ascii_art_from_url(u)), link: p.permalink_url.clone() }).collect()
|
||||
);
|
||||
}
|
||||
|
||||
@ -179,62 +175,59 @@ impl MainScreen {
|
||||
}
|
||||
|
||||
fn render_tab(&self, frame: &mut Frame, area: Rect) /*-> Table<'_>*/ {
|
||||
let rows = match self.selected_tab {
|
||||
1 => { // SC
|
||||
/*let mut v = Vec::new();
|
||||
v.push(Row::new(vec!["Id", "Title", "Songs Count", "Date", "IS"]).style(Style::default().fg(Color::Gray)));
|
||||
if let Some(s) = &self.soundcloud {
|
||||
for (i, playlist) in (&s.collection).iter().enumerate() {
|
||||
let date: DateTime<Utc> = playlist.created_at.parse().unwrap();
|
||||
let mut row = Row::new(
|
||||
vec![
|
||||
playlist.id.to_string(),
|
||||
playlist.title.clone(),
|
||||
[playlist.track_count.to_string(), " songs".to_string()].concat(),
|
||||
format!("{}", date.format("%Y-%m-%d %H:%M")),
|
||||
"NO".to_string()
|
||||
]
|
||||
);
|
||||
if self.selected_row == i as i32 {
|
||||
row = row.style(Style::default().bg(Color::Yellow));
|
||||
}
|
||||
v.push(row);
|
||||
if self.selected_tab == 1 { // SC
|
||||
/*let mut v = Vec::new();
|
||||
v.push(Row::new(vec!["Id", "Title", "Songs Count", "Date", "IS"]).style(Style::default().fg(Color::Gray)));
|
||||
if let Some(s) = &self.soundcloud {
|
||||
for (i, playlist) in (&s.collection).iter().enumerate() {
|
||||
let date: DateTime<Utc> = playlist.created_at.parse().unwrap();
|
||||
let mut row = Row::new(
|
||||
vec![
|
||||
playlist.id.to_string(),
|
||||
playlist.title.clone(),
|
||||
[playlist.track_count.to_string(), " songs".to_string()].concat(),
|
||||
format!("{}", date.format("%Y-%m-%d %H:%M")),
|
||||
"NO".to_string()
|
||||
]
|
||||
);
|
||||
if self.selected_row == i as i32 {
|
||||
row = row.style(Style::default().bg(Color::Yellow));
|
||||
}
|
||||
v.push(row);
|
||||
}
|
||||
v*/
|
||||
let v = self.soundcloud.as_deref().unwrap_or(&[]);
|
||||
|
||||
|
||||
let rows = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(vec![Constraint::Percentage(100); math::round::ceil(v.len() as f64 / 3 as f64, 0) as usize]) // Two rows
|
||||
.split(area);
|
||||
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
let cols = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints(vec![Constraint::Length(16); 2]) // Three columns
|
||||
.split(*row);
|
||||
}
|
||||
v*/
|
||||
let v = self.soundcloud.as_deref().unwrap_or(&[]);
|
||||
|
||||
for (j, col) in cols.iter().enumerate() {
|
||||
let index = i * 3 + j;
|
||||
if index < v.len() {
|
||||
let p = &v[index];
|
||||
|
||||
let url_cl = p.thumbnail_url.clone();
|
||||
let mut s = url_cl.lines().map(|l| Line::from(l)).collect::<Vec<Line>>();
|
||||
let rows = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(vec![Constraint::Percentage(100); math::round::ceil(v.len() as f64 / 3_f64, 0) as usize]) // Two rows
|
||||
.split(area);
|
||||
|
||||
let paragraph = Paragraph::new(s)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
|
||||
|
||||
frame.render_widget(paragraph, *col);
|
||||
}
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
let cols = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints(vec![Constraint::Length(16); 2]) // Three columns
|
||||
.split(*row);
|
||||
|
||||
for (j, col) in cols.iter().enumerate() {
|
||||
let index = i * 3 + j;
|
||||
if index < v.len() {
|
||||
let p = &v[index];
|
||||
|
||||
let url_cl = p.thumbnail_url.clone();
|
||||
let s = url_cl.lines().map(Line::from).collect::<Vec<Line>>();
|
||||
|
||||
let paragraph = Paragraph::new(s)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
|
||||
|
||||
frame.render_widget(paragraph, *col);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {} // Vec::new()
|
||||
};
|
||||
|
||||
// Create the table
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::any::Any;
|
||||
|
||||
use crossterm::event::KeyEvent;
|
||||
use ratatui::{buffer::Buffer, layout::Rect, Frame};
|
||||
use ratatui::Frame;
|
||||
|
||||
pub trait AppScreen {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent);
|
||||
|
@ -40,7 +40,7 @@ pub fn initialize_async_service(sender: Sender<AppEvent>, receiver: UnboundedRec
|
||||
// todo: parse itunes
|
||||
let _ = std::fs::create_dir_all(get_configs_dir());
|
||||
let cd = get_temp_itunesdb();
|
||||
let mut p: PathBuf = Path::new(&path).into();
|
||||
let p: PathBuf = Path::new(&path).into();
|
||||
// p.push("iPod_Control");
|
||||
// p.push("iTunes");
|
||||
// p.set_file_name("iTunesDB");
|
||||
|
@ -91,9 +91,7 @@ fn get_ipod_path() -> Option<String> {
|
||||
match list() {
|
||||
Ok(l) => l.iter()
|
||||
.filter(|d| is_ipod(d))
|
||||
.map(|d| get_mount_point(d))
|
||||
.filter(|d| d.is_some())
|
||||
.map(|d| d.unwrap())
|
||||
.filter_map(|d| get_mount_point(d))
|
||||
.last(),
|
||||
Err(_e) => None
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use ratatui::{style::Stylize, symbols::border, text::{Line, Text}, widgets::{Block, Paragraph, Widget}, Frame};
|
||||
use ratatui::{style::Stylize, symbols::border, text::{Line, Text}, widgets::{Block, Paragraph}, Frame};
|
||||
|
||||
use crate::screen::AppScreen;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user