diff --git a/Cargo.lock b/Cargo.lock index 38e84e2..65d59ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,15 +249,6 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2459fc9262a1aa204eb4b5764ad4f189caec88aea9634389c0a25f8be7f6265e" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "crc32fast" version = "1.4.2" @@ -626,28 +617,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "moku" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43515d765182666f322df04c4cba683b776626e98098cbcf11f09617aaada07d" -dependencies = [ - "log", - "moku-macros", -] - -[[package]] -name = "moku-macros" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe608ab81f295081536ea4cf4461773db33b049470fda69277c9ee799bdb34e5" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "normpath" version = "1.3.0" @@ -1088,7 +1057,6 @@ dependencies = [ "file_type", "hex", "id3", - "moku", "opener", "pad", "tek_tui", diff --git a/Cargo.toml b/Cargo.toml index 5dce631..31c8f25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ tek_tui = { git = "https://codeberg.org/unspeaker/tengri", rev = "6cd85ef" } clap = { version = "4.5.4", features = [ "cargo" ] } walkdir = "2" id3 = "1.16" -moku = "0.2" +#moku = "0.2" file_type = "0.7" pad = "0.1" #sha2 = "0.10" diff --git a/src/keys.rs b/src/keys.rs index 21ca82d..7dcd9cf 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -16,17 +16,26 @@ impl Handle for Taggart { fn handle (&mut self, input: &TuiIn) -> Perhaps { let x_min = self.offset; let x_max = self.offset + self.size.h().saturating_sub(1); - match &*input.event() { + let event = &*input.event(); + match event { press!(Up) => { self.cursor = self.cursor.saturating_sub(1); }, press!(Down) => { self.cursor = self.cursor + 1; }, press!(PageUp) => { self.cursor = self.cursor.saturating_sub(PAGE_SIZE); }, press!(PageDown) => { self.cursor += PAGE_SIZE; }, press!(Left) => { self.column = self.column.saturating_sub(1); }, press!(Right) => { self.column = self.column + 1; }, - press!(Enter) => { self.editing = Some((self.cursor, self.column)); }, - press!(Esc) => { self.editing = None; }, press!(Char(' ')) => { open(&self.paths[self.cursor].path)?; } - _ => {} + _ => match &self.editing { + Some(_value) => match event { + press!(Enter) => todo!(), + press!(Esc) => todo!(), + _ => {} + }, + None => match event { + press!(Enter) => todo!(), + _ => {} + } + } } if self.cursor < x_min { self.offset = self.cursor; @@ -43,24 +52,3 @@ impl Handle for Taggart { Ok(None) } } - -#[moku::state_machine] -mod taggart { - use moku::*; - #[machine_module] mod machine {} - use self::machine::{TaggartState, TopSuperstates}; - struct Top; - impl TopState for Top {} - struct Tree(usize); - #[superstate(Top)] impl State for Tree { - fn enter (_: &mut TopSuperstates<'_>) -> StateEntry { - StateEntry::State(Self(0)) - } - } - struct File(usize); - #[superstate(Top)] impl State for File { - fn enter (_: &mut TopSuperstates<'_>) -> StateEntry { - StateEntry::State(Self(0)) - } - } -} diff --git a/src/main.rs b/src/main.rs index 24f54f4..3a3ba7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(stable_features)] #![feature(os_str_display)] use std::sync::{Arc, RwLock}; @@ -36,7 +37,7 @@ fn main () -> Usually<()> { } else { current_dir()? }; - set_current_dir(&path); + set_current_dir(&path)?; let state = Arc::new(RwLock::new(Taggart::new(&path)?)); Tui::new()?.run(&state) } @@ -45,7 +46,7 @@ impl Taggart { fn new (root: &impl AsRef) -> Usually { Ok(Self { - root: root.as_ref().into(), + _root: root.as_ref().into(), paths: Self::collect(root)?, cursor: 0, offset: 0, diff --git a/src/model.rs b/src/model.rs index 3ad2212..38537bb 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,17 +1,16 @@ use crate::*; use walkdir::DirEntry; use id3::{Tag, TagLike}; -use std::io::Read; pub struct Taggart { - pub root: PathBuf, + pub _root: PathBuf, pub paths: Vec, pub cursor: usize, pub offset: usize, pub column: usize, pub columns: Columns, pub size: Measure, - pub editing: Option<(usize, usize)>, + pub editing: Option, } #[derive(Ord, Eq, PartialEq, PartialOrd)] @@ -120,9 +119,6 @@ impl Entry { }, })) } - pub fn short_path (&self, root: &impl AsRef) -> Usually<&Path> { - Ok(self.path.strip_prefix(root.as_ref())?) - } pub fn is_dir (&self) -> bool { matches!(self.info, EntryInfo::Directory { .. }) } diff --git a/src/view.rs b/src/view.rs index 96cf6d5..6c9bf48 100644 --- a/src/view.rs +++ b/src/view.rs @@ -1,7 +1,6 @@ use crate::*; use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize}; use pad::PadStr; -use std::fmt::Display; pub struct Column { title: Arc, @@ -37,7 +36,7 @@ impl Default for Columns { impl Columns { pub fn header (&self) -> Arc { let mut output = String::new(); - for Column { width, value, title } in self.0.iter() { + for Column { width, title, .. } in self.0.iter() { let cell = title.pad_to_width(*width); output = format!("{output}{cell}│"); } @@ -51,6 +50,18 @@ impl Columns { } output.into() } + pub fn xw (&self, column: usize) -> (u16, u16) { + let mut x: u16 = 0; + for (index, Column { width, .. }) in self.0.iter().enumerate() { + let w = *width as u16 + 1; + if index == column { + return (x.saturating_sub(1), w + 1) + } else { + x += w; + } + } + (0, 0) + } } impl Content for Taggart { @@ -69,28 +80,22 @@ impl<'a> Content for TreeTable<'a> { fn render (&self, to: &mut TuiOut) { let area = to.area(); let Taggart { offset, paths, cursor, column, .. } = self.0; - let mut x = 0; - for (index, Column { width, .. }) in self.0.columns.0.iter().enumerate() { - let w = *width as u16 + 1; - if index == *column { - to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0)); - break - } else { - x += w; - } - } + let (x, w) = self.0.columns.xw(*column); + to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0)); for (i, y) in area.iter_y().enumerate() { let i_offset = i + offset; let selected = *cursor == i_offset; if let Some(entry) = paths.get(i_offset) { - for (index, fragment) in entry.path.iter().enumerate() { + for (index, _fragment) in entry.path.iter().enumerate() { if index == entry.depth - 1 { - let cursor = if selected { ">" } else { " " }; - let label = self.0.columns.row(&entry); + let _cursor = if selected { ">" } else { " " }; + let label = self.0.columns.row(&entry); to.blit(&label, area.x(), y, entry.style()); if selected { let fill = [area.x(), y, area.w(), 1]; to.fill_fg(fill, Color::Rgb(0, 0, 0)); + to.fill_bg(fill, Color::Rgb(192, 128, 0)); + let fill = [area.x() + x as u16, y, w, 1]; to.fill_bg(fill, Color::Rgb(224, 192, 0)); } }