start of self-implemented scrollbox.
This commit is contained in:
parent
92d3f7ba77
commit
fa786d931d
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -374,7 +374,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -936,8 +936,8 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||
|
||||
[[package]]
|
||||
name = "itunesdb"
|
||||
version = "0.1.19"
|
||||
source = "git+https://gitea.awain.net/alterwain/ITunesDB.git#e1e8d0a12ca2c3825191ff1d815645a704e1b646"
|
||||
version = "0.1.50"
|
||||
source = "git+https://gitea.awain.net/alterwain/ITunesDB.git#2c38d91cd89908b20a2b08da1b3202dacf5d1f9b"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"env_logger",
|
||||
@ -1488,7 +1488,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1831,7 +1831,7 @@ dependencies = [
|
||||
"getrandom 0.3.1",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2297,7 +2297,7 @@ version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -20,7 +20,7 @@ futures = "0.3"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tokio-util = { version = "0.7.12", features = ["codec"] }
|
||||
soundcloud = { version = "0.1.8", git = "https://gitea.awain.net/alterwain/soundcloud_api.git" }
|
||||
itunesdb = { version = "0.1.19", git = "https://gitea.awain.net/alterwain/ITunesDB.git" }
|
||||
itunesdb = { version = "0.1.50", git = "https://gitea.awain.net/alterwain/ITunesDB.git" }
|
||||
puremp3 = "0.1.0"
|
||||
mp3-duration = "0.1.10"
|
||||
rand = "0.8.5"
|
@ -1,11 +1,25 @@
|
||||
use crate::{screen::AppScreen, theme::Theme};
|
||||
use chrono::{DateTime, Utc};
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::prelude::{Color, Line, Style, Stylize};
|
||||
use ratatui::widgets::{Block, Borders, Paragraph, Row, Table};
|
||||
use ratatui::Frame;
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::DirEntry;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FileSystem {}
|
||||
pub struct FileSystem {
|
||||
dir: Vec<DirEntry>,
|
||||
}
|
||||
|
||||
impl Default for FileSystem {
|
||||
fn default() -> Self {
|
||||
let mut a = Self { dir: Vec::new() };
|
||||
a.get_path(dirs::document_dir().unwrap());
|
||||
a
|
||||
}
|
||||
}
|
||||
|
||||
impl AppScreen for FileSystem {
|
||||
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {}
|
||||
@ -43,15 +57,39 @@ impl AppScreen for FileSystem {
|
||||
}
|
||||
|
||||
impl FileSystem {
|
||||
fn get_path(&mut self, p: PathBuf) {
|
||||
let paths = std::fs::read_dir(p).unwrap();
|
||||
self.dir = paths
|
||||
.filter_map(|res| res.ok())
|
||||
.filter(|p| p.path().extension().map_or(false, |ext| ext == "mp3") || p.path().is_dir())
|
||||
.collect();
|
||||
self.dir.sort_by(|a, b| {
|
||||
if a.file_type().unwrap().is_dir() {
|
||||
Ordering::Less
|
||||
} else {
|
||||
Ordering::Greater
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn render_main(&self, frame: &mut Frame, area: Rect) {
|
||||
let mut v = vec![Row::new(vec!["Name", "Type", "Size", "Modified"])
|
||||
.style(Style::default().fg(Color::Gray))];
|
||||
|
||||
// move this out to make hdd not suffer
|
||||
let paths = std::fs::read_dir("~/Documents").unwrap();
|
||||
|
||||
for path in paths {
|
||||
v.push();
|
||||
for entry in self.dir.iter() {
|
||||
let datetime: DateTime<Utc> = entry.metadata().unwrap().modified().unwrap().into();
|
||||
let datetime = datetime.format("%d/%m/%Y %T").to_string();
|
||||
let size = entry.metadata().unwrap().size().to_string();
|
||||
let file_type = entry.file_type().unwrap().is_file().to_string();
|
||||
v.push(
|
||||
Row::new(vec![
|
||||
entry.file_name().to_str().unwrap().to_string(),
|
||||
file_type,
|
||||
size,
|
||||
datetime,
|
||||
])
|
||||
.style(Style::default()),
|
||||
);
|
||||
}
|
||||
|
||||
let table = Table::new(
|
||||
|
@ -293,7 +293,7 @@ impl MainScreen {
|
||||
|
||||
frame.render_widget(table, chunks[0]);
|
||||
|
||||
let rows = match self.selected_tab {
|
||||
let mut rows = match self.selected_tab {
|
||||
1 => {
|
||||
// sc
|
||||
let mut v = Vec::new();
|
||||
@ -352,6 +352,10 @@ impl MainScreen {
|
||||
_ => Vec::new(),
|
||||
};
|
||||
|
||||
if chunks[1].rows().count() <= self.selected_song as usize {
|
||||
rows = rows[self.selected_song as usize..].to_vec();
|
||||
}
|
||||
|
||||
// Create the table
|
||||
let table = Table::new(
|
||||
rows,
|
||||
|
Loading…
x
Reference in New Issue
Block a user