mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 17:46:42 +01:00
wip: basic editing
This commit is contained in:
parent
b13ce4f0d0
commit
5336ee358a
4 changed files with 90 additions and 57 deletions
55
src/model.rs
55
src/model.rs
|
|
@ -10,7 +10,60 @@ pub struct Taggart {
|
|||
pub column: usize,
|
||||
pub columns: Columns<Entry>,
|
||||
pub size: Measure<TuiOut>,
|
||||
pub editing: Option<String>,
|
||||
pub editing: Option<(usize, String)>,
|
||||
}
|
||||
|
||||
impl Taggart {
|
||||
pub fn new (root: &impl AsRef<Path>) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
_root: root.as_ref().into(),
|
||||
paths: Self::collect(root)?,
|
||||
cursor: 0,
|
||||
offset: 0,
|
||||
column: 0,
|
||||
size: Measure::new(),
|
||||
editing: None,
|
||||
columns: Columns::default(),
|
||||
})
|
||||
}
|
||||
pub fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
|
||||
let mut paths = vec![];
|
||||
for entry in WalkDir::new(&root).into_iter()
|
||||
.filter_entry(|e|!e.file_name().to_str().map(|s|s.starts_with(".")).unwrap_or(false))
|
||||
{
|
||||
let entry = entry?;
|
||||
if entry.depth() == 0 {
|
||||
continue
|
||||
}
|
||||
if let Some(entry) = Entry::new(root, &entry)? {
|
||||
paths.push(entry);
|
||||
}
|
||||
}
|
||||
paths.sort();
|
||||
Ok(paths)
|
||||
}
|
||||
pub fn edit_begin (&mut self) {
|
||||
let value = (self.columns.0[self.column].value)(&self.paths[self.cursor]);
|
||||
let value = format!("{}", value.unwrap_or_default());
|
||||
self.editing = Some((value.len(), value));
|
||||
}
|
||||
pub fn edit_cancel (&mut self) {
|
||||
self.editing = None;
|
||||
}
|
||||
pub fn edit_confirm (&mut self) {
|
||||
self.editing = None;
|
||||
}
|
||||
pub fn edit_insert (&mut self, c: char) {
|
||||
if let Some((index, value)) = &mut self.editing {
|
||||
self.editing = Some((*index, format!("{value}{c}")));
|
||||
}
|
||||
}
|
||||
pub fn edit_backspace (&mut self) {
|
||||
todo!()
|
||||
}
|
||||
pub fn edit_delete (&mut self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Ord, Eq, PartialEq, PartialOrd)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue