mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 17:46:42 +01:00
fix all warns, remove moku, bind edit keys
This commit is contained in:
parent
41c5686d67
commit
2903d58b2d
6 changed files with 39 additions and 81 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
|
@ -249,15 +249,6 @@ version = "0.2.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2459fc9262a1aa204eb4b5764ad4f189caec88aea9634389c0a25f8be7f6265e"
|
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]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.4.2"
|
version = "1.4.2"
|
||||||
|
|
@ -626,28 +617,6 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"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]]
|
[[package]]
|
||||||
name = "normpath"
|
name = "normpath"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|
@ -1088,7 +1057,6 @@ dependencies = [
|
||||||
"file_type",
|
"file_type",
|
||||||
"hex",
|
"hex",
|
||||||
"id3",
|
"id3",
|
||||||
"moku",
|
|
||||||
"opener",
|
"opener",
|
||||||
"pad",
|
"pad",
|
||||||
"tek_tui",
|
"tek_tui",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ tek_tui = { git = "https://codeberg.org/unspeaker/tengri", rev = "6cd85ef" }
|
||||||
clap = { version = "4.5.4", features = [ "cargo" ] }
|
clap = { version = "4.5.4", features = [ "cargo" ] }
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
id3 = "1.16"
|
id3 = "1.16"
|
||||||
moku = "0.2"
|
#moku = "0.2"
|
||||||
file_type = "0.7"
|
file_type = "0.7"
|
||||||
pad = "0.1"
|
pad = "0.1"
|
||||||
#sha2 = "0.10"
|
#sha2 = "0.10"
|
||||||
|
|
|
||||||
38
src/keys.rs
38
src/keys.rs
|
|
@ -16,17 +16,26 @@ impl Handle<TuiIn> for Taggart {
|
||||||
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
||||||
let x_min = self.offset;
|
let x_min = self.offset;
|
||||||
let x_max = self.offset + self.size.h().saturating_sub(1);
|
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!(Up) => { self.cursor = self.cursor.saturating_sub(1); },
|
||||||
press!(Down) => { self.cursor = self.cursor + 1; },
|
press!(Down) => { self.cursor = self.cursor + 1; },
|
||||||
press!(PageUp) => { self.cursor = self.cursor.saturating_sub(PAGE_SIZE); },
|
press!(PageUp) => { self.cursor = self.cursor.saturating_sub(PAGE_SIZE); },
|
||||||
press!(PageDown) => { self.cursor += PAGE_SIZE; },
|
press!(PageDown) => { self.cursor += PAGE_SIZE; },
|
||||||
press!(Left) => { self.column = self.column.saturating_sub(1); },
|
press!(Left) => { self.column = self.column.saturating_sub(1); },
|
||||||
press!(Right) => { self.column = self.column + 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)?; }
|
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 {
|
if self.cursor < x_min {
|
||||||
self.offset = self.cursor;
|
self.offset = self.cursor;
|
||||||
|
|
@ -43,24 +52,3 @@ impl Handle<TuiIn> for Taggart {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[moku::state_machine]
|
|
||||||
mod taggart {
|
|
||||||
use moku::*;
|
|
||||||
#[machine_module] mod machine {}
|
|
||||||
use self::machine::{TaggartState, TopSuperstates};
|
|
||||||
struct Top;
|
|
||||||
impl TopState<TaggartState> for Top {}
|
|
||||||
struct Tree(usize);
|
|
||||||
#[superstate(Top)] impl State<TaggartState> for Tree {
|
|
||||||
fn enter (_: &mut TopSuperstates<'_>) -> StateEntry<Self, TaggartState> {
|
|
||||||
StateEntry::State(Self(0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
struct File(usize);
|
|
||||||
#[superstate(Top)] impl State<TaggartState> for File {
|
|
||||||
fn enter (_: &mut TopSuperstates<'_>) -> StateEntry<Self, TaggartState> {
|
|
||||||
StateEntry::State(Self(0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(stable_features)]
|
||||||
#![feature(os_str_display)]
|
#![feature(os_str_display)]
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
@ -36,7 +37,7 @@ fn main () -> Usually<()> {
|
||||||
} else {
|
} else {
|
||||||
current_dir()?
|
current_dir()?
|
||||||
};
|
};
|
||||||
set_current_dir(&path);
|
set_current_dir(&path)?;
|
||||||
let state = Arc::new(RwLock::new(Taggart::new(&path)?));
|
let state = Arc::new(RwLock::new(Taggart::new(&path)?));
|
||||||
Tui::new()?.run(&state)
|
Tui::new()?.run(&state)
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +46,7 @@ impl Taggart {
|
||||||
|
|
||||||
fn new (root: &impl AsRef<Path>) -> Usually<Self> {
|
fn new (root: &impl AsRef<Path>) -> Usually<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
root: root.as_ref().into(),
|
_root: root.as_ref().into(),
|
||||||
paths: Self::collect(root)?,
|
paths: Self::collect(root)?,
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use walkdir::DirEntry;
|
use walkdir::DirEntry;
|
||||||
use id3::{Tag, TagLike};
|
use id3::{Tag, TagLike};
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
pub struct Taggart {
|
pub struct Taggart {
|
||||||
pub root: PathBuf,
|
pub _root: PathBuf,
|
||||||
pub paths: Vec<Entry>,
|
pub paths: Vec<Entry>,
|
||||||
pub cursor: usize,
|
pub cursor: usize,
|
||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub column: usize,
|
pub column: usize,
|
||||||
pub columns: Columns<Entry>,
|
pub columns: Columns<Entry>,
|
||||||
pub size: Measure<TuiOut>,
|
pub size: Measure<TuiOut>,
|
||||||
pub editing: Option<(usize, usize)>,
|
pub editing: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Ord, Eq, PartialEq, PartialOrd)]
|
#[derive(Ord, Eq, PartialEq, PartialOrd)]
|
||||||
|
|
@ -120,9 +119,6 @@ impl Entry {
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
pub fn short_path (&self, root: &impl AsRef<Path>) -> Usually<&Path> {
|
|
||||||
Ok(self.path.strip_prefix(root.as_ref())?)
|
|
||||||
}
|
|
||||||
pub fn is_dir (&self) -> bool {
|
pub fn is_dir (&self) -> bool {
|
||||||
matches!(self.info, EntryInfo::Directory { .. })
|
matches!(self.info, EntryInfo::Directory { .. })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
src/view.rs
35
src/view.rs
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize};
|
use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize};
|
||||||
use pad::PadStr;
|
use pad::PadStr;
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
pub struct Column<T> {
|
pub struct Column<T> {
|
||||||
title: Arc<str>,
|
title: Arc<str>,
|
||||||
|
|
@ -37,7 +36,7 @@ impl Default for Columns<Entry> {
|
||||||
impl<T> Columns<T> {
|
impl<T> Columns<T> {
|
||||||
pub fn header (&self) -> Arc<str> {
|
pub fn header (&self) -> Arc<str> {
|
||||||
let mut output = String::new();
|
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);
|
let cell = title.pad_to_width(*width);
|
||||||
output = format!("{output}{cell}│");
|
output = format!("{output}{cell}│");
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +50,18 @@ impl<T> Columns<T> {
|
||||||
}
|
}
|
||||||
output.into()
|
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<TuiOut> for Taggart {
|
impl Content<TuiOut> for Taggart {
|
||||||
|
|
@ -69,28 +80,22 @@ impl<'a> Content<TuiOut> for TreeTable<'a> {
|
||||||
fn render (&self, to: &mut TuiOut) {
|
fn render (&self, to: &mut TuiOut) {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let Taggart { offset, paths, cursor, column, .. } = self.0;
|
let Taggart { offset, paths, cursor, column, .. } = self.0;
|
||||||
let mut x = 0;
|
let (x, w) = self.0.columns.xw(*column);
|
||||||
for (index, Column { width, .. }) in self.0.columns.0.iter().enumerate() {
|
to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i, y) in area.iter_y().enumerate() {
|
for (i, y) in area.iter_y().enumerate() {
|
||||||
let i_offset = i + offset;
|
let i_offset = i + offset;
|
||||||
let selected = *cursor == i_offset;
|
let selected = *cursor == i_offset;
|
||||||
if let Some(entry) = paths.get(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 {
|
if index == entry.depth - 1 {
|
||||||
let cursor = if selected { ">" } else { " " };
|
let _cursor = if selected { ">" } else { " " };
|
||||||
let label = self.0.columns.row(&entry);
|
let label = self.0.columns.row(&entry);
|
||||||
to.blit(&label, area.x(), y, entry.style());
|
to.blit(&label, area.x(), y, entry.style());
|
||||||
if selected {
|
if selected {
|
||||||
let fill = [area.x(), y, area.w(), 1];
|
let fill = [area.x(), y, area.w(), 1];
|
||||||
to.fill_fg(fill, Color::Rgb(0, 0, 0));
|
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));
|
to.fill_bg(fill, Color::Rgb(224, 192, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue