improved navigation, error messages
parent
d101367e34
commit
bec3e6b3be
|
@ -113,6 +113,26 @@ impl Directory {
|
|||
}
|
||||
}
|
||||
|
||||
fn delete_file(&mut self) -> Result<(), Error> {
|
||||
self.delete()?;
|
||||
if self.selected().is_file {
|
||||
self.dirs.remove(self.selection());
|
||||
} else {
|
||||
let target_depth = self.selected().depth;
|
||||
|
||||
let end = (self.selection()+1 .. self.dirs.len())
|
||||
.find(|&i| self.dirs[i].depth <= target_depth)
|
||||
.unwrap_or(self.dirs.len());
|
||||
|
||||
self.dirs.drain(self.selection() .. end);
|
||||
}
|
||||
if self.selection() >= self.dirs.len() {
|
||||
self.selection -= 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn subtree_indices(&self, index: usize) -> Range<usize> {
|
||||
let current_depth = self.selected().depth;
|
||||
|
||||
|
@ -148,6 +168,10 @@ impl Directory {
|
|||
/// (and any contained), making sure
|
||||
/// not to indent too low
|
||||
fn outdent(&mut self) {
|
||||
if !is_last_at_this_depth(&self.dirs[self.selection()+1..], self.selected().depth) {
|
||||
return
|
||||
};
|
||||
|
||||
let s = self.selected_mut();
|
||||
|
||||
if s.depth <= 1 {
|
||||
|
@ -226,8 +250,7 @@ impl Directory {
|
|||
let Some(index) = (0 .. self.selection())
|
||||
.rev()
|
||||
.take_while(|&i| self.dirs[i].depth >= current_depth)
|
||||
.filter(|&i| self.dirs[i].depth == current_depth)
|
||||
.next()
|
||||
.find(|&i| self.dirs[i].depth == current_depth)
|
||||
else {
|
||||
return
|
||||
};
|
||||
|
@ -290,26 +313,18 @@ impl Directory {
|
|||
},
|
||||
KeyCode::Esc => return Ok(Message::Exit),
|
||||
KeyCode::Backspace if self.selected().depth > 0 => {
|
||||
self.delete()?;
|
||||
if self.selected().is_file {
|
||||
self.dirs.remove(self.selection());
|
||||
} else {
|
||||
let target_depth = self.selected().depth;
|
||||
|
||||
let end = (self.selection()+1 .. self.dirs.len())
|
||||
.find(|&i| self.dirs[i].depth <= target_depth)
|
||||
.unwrap_or(self.dirs.len());
|
||||
|
||||
self.dirs.drain(self.selection() .. end);
|
||||
}
|
||||
if self.selection() >= self.dirs.len() {
|
||||
self.selection -= 1;
|
||||
}
|
||||
self.delete_file()?;
|
||||
},
|
||||
KeyCode::Home => {
|
||||
self.display_start = 0;
|
||||
self.selection = 0;
|
||||
},
|
||||
KeyCode::End => {
|
||||
self.selection = u16::try_from(self.dirs.len()-1).unwrap_or(u16::MAX);
|
||||
if self.selection > self.display_start + self.height {
|
||||
self.display_start = self.selection - self.height
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
@ -342,7 +357,7 @@ impl Directory {
|
|||
KeyCode::Left => {
|
||||
self.outdent();
|
||||
},
|
||||
KeyCode::Right | KeyCode::Tab => {
|
||||
KeyCode::Right => {
|
||||
self.indent();
|
||||
},
|
||||
KeyCode::Down => {
|
||||
|
|
|
@ -56,7 +56,9 @@ fn main() -> AnyResult<()> {
|
|||
|
||||
let _redirect = Redirect::stderr(target)?;
|
||||
|
||||
do_tui(args).map_err(Into::<AnyError>::into).unwrap();
|
||||
do_tui(args)
|
||||
.map_err(Into::<AnyError>::into)
|
||||
.expect("error");
|
||||
|
||||
remove_file(LOG_FILE)?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue