mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Dirstack implementation for local
This commit is contained in:
@@ -131,12 +131,12 @@ impl FileExplorer {
|
|||||||
FileExplorer {
|
FileExplorer {
|
||||||
index: 0,
|
index: 0,
|
||||||
files: Vec::new(),
|
files: Vec::new(),
|
||||||
dirstack: VecDeque::with_capacity(16)
|
dirstack: VecDeque::with_capacity(16),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### pushd
|
/// ### pushd
|
||||||
///
|
///
|
||||||
/// push directory to stack
|
/// push directory to stack
|
||||||
pub fn pushd(&mut self, dir: &Path) {
|
pub fn pushd(&mut self, dir: &Path) {
|
||||||
// Check if stack overflows the size
|
// Check if stack overflows the size
|
||||||
@@ -148,12 +148,11 @@ impl FileExplorer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// ### popd
|
/// ### popd
|
||||||
///
|
///
|
||||||
/// Pop directory from the stack and return the directory
|
/// Pop directory from the stack and return the directory
|
||||||
pub fn popd(&mut self) -> Option<PathBuf> {
|
pub fn popd(&mut self) -> Option<PathBuf> {
|
||||||
self.dirstack.pop_front()
|
self.dirstack.pop_front()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ## FileExplorerTab
|
/// ## FileExplorerTab
|
||||||
@@ -658,14 +657,18 @@ impl FileTransferActivity {
|
|||||||
// Match selected file
|
// Match selected file
|
||||||
if let Some(entry) = self.local.files.get(self.local.index) {
|
if let Some(entry) = self.local.files.get(self.local.index) {
|
||||||
if let FsEntry::Directory(dir) = entry {
|
if let FsEntry::Directory(dir) = entry {
|
||||||
|
// Get current directory
|
||||||
|
let prev_dir: PathBuf = context.local.pwd();
|
||||||
// Change directory
|
// Change directory
|
||||||
if let Err(err) = context.local.change_wrkdir(dir.abs_path.clone())
|
match context.local.change_wrkdir(dir.abs_path.clone()) {
|
||||||
{
|
Ok(_) => self.local.pushd(prev_dir.as_path()), // Push prev_dir to stack
|
||||||
// Report err
|
Err(err) => {
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
// Report err
|
||||||
Color::Red,
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
format!("Could not change working directory: {}", err),
|
Color::Red,
|
||||||
));
|
format!("Could not change working directory: {}", err),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Update files
|
// Update files
|
||||||
self.local.files = context.local.list_dir();
|
self.local.files = context.local.list_dir();
|
||||||
@@ -673,20 +676,32 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
// TODO: directory stack
|
// Go to previous directory
|
||||||
// Go previous directory
|
loop {
|
||||||
let wrkdir: PathBuf = context.local.pwd();
|
// Till a valid directory is found
|
||||||
if let Some(parent) = wrkdir.as_path().parent() {
|
match self.local.popd() {
|
||||||
// Change directory
|
Some(d) => {
|
||||||
if let Err(err) = context.local.change_wrkdir(PathBuf::from(parent)) {
|
match context.local.change_wrkdir(d) {
|
||||||
// Report err
|
Ok(_) => {
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
// Update files
|
||||||
Color::Red,
|
self.local.files = context.local.list_dir();
|
||||||
format!("Could not change working directory: {}", err),
|
// Break, directory has changed
|
||||||
));
|
break;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
// Report error
|
||||||
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!(
|
||||||
|
"Could not change working directory: {}",
|
||||||
|
err
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => break, // Break if stack is empty
|
||||||
}
|
}
|
||||||
// Update files
|
|
||||||
self.local.files = context.local.list_dir();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Delete => {
|
KeyCode::Delete => {
|
||||||
|
|||||||
Reference in New Issue
Block a user