mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Files found from search are now displayed with their relative path from working directory
This commit is contained in:
committed by
Christian Visintin
parent
3927fb2a39
commit
bc6b7b582e
@@ -28,9 +28,11 @@
|
||||
// Locals
|
||||
use super::FsEntry;
|
||||
use crate::utils::fmt::{fmt_path_elide, fmt_pex, fmt_time};
|
||||
use crate::utils::path::diff_paths;
|
||||
// Ext
|
||||
use bytesize::ByteSize;
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
#[cfg(target_family = "unix")]
|
||||
use users::{get_group_by_gid, get_user_by_uid};
|
||||
// Types
|
||||
@@ -346,15 +348,23 @@ impl Formatter {
|
||||
cur_str: &str,
|
||||
prefix: &str,
|
||||
fmt_len: Option<&usize>,
|
||||
_fmt_extra: Option<&String>,
|
||||
fmt_extra: Option<&String>,
|
||||
) -> String {
|
||||
let p = match fmt_extra {
|
||||
None => fsentry.get_abs_path(),
|
||||
Some(rel) => diff_paths(
|
||||
fsentry.get_abs_path().as_path(),
|
||||
PathBuf::from(rel.as_str()).as_path(),
|
||||
)
|
||||
.unwrap_or_else(|| fsentry.get_abs_path()),
|
||||
};
|
||||
format!(
|
||||
"{}{}{}",
|
||||
cur_str,
|
||||
prefix,
|
||||
match fmt_len {
|
||||
None => fsentry.get_abs_path().display().to_string(),
|
||||
Some(len) => fmt_path_elide(fsentry.get_abs_path().as_path(), *len),
|
||||
None => p.display().to_string(),
|
||||
Some(len) => fmt_path_elide(p.as_path(), *len),
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -935,6 +945,8 @@ mod tests {
|
||||
formatter.fmt(&entry).as_str(),
|
||||
"File path: /tmp/…/c/bar.txt"
|
||||
);
|
||||
let formatter: Formatter = Formatter::new("File path: {PATH:128:/tmp/a/b}");
|
||||
assert_eq!(formatter.fmt(&entry).as_str(), "File path: c/bar.txt");
|
||||
}
|
||||
|
||||
/// ### dummy_fmt
|
||||
|
||||
@@ -29,6 +29,8 @@ use crate::fs::explorer::{builder::FileExplorerBuilder, FileExplorer, FileSortin
|
||||
use crate::fs::FsEntry;
|
||||
use crate::system::config_client::ConfigClient;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
/// ## FileExplorerTab
|
||||
///
|
||||
/// File explorer tab
|
||||
@@ -98,8 +100,8 @@ impl Browser {
|
||||
self.found.as_mut().map(|x| &mut x.1)
|
||||
}
|
||||
|
||||
pub fn set_found(&mut self, tab: FoundExplorerTab, files: Vec<FsEntry>) {
|
||||
let mut explorer = Self::build_found_explorer();
|
||||
pub fn set_found(&mut self, tab: FoundExplorerTab, files: Vec<FsEntry>, wrkdir: &Path) {
|
||||
let mut explorer = Self::build_found_explorer(wrkdir);
|
||||
explorer.set_files(files);
|
||||
self.found = Some((tab, explorer));
|
||||
}
|
||||
@@ -168,13 +170,15 @@ impl Browser {
|
||||
/// ### build_found_explorer
|
||||
///
|
||||
/// Build explorer reading from `ConfigClient`, for found result (has some differences)
|
||||
fn build_found_explorer() -> FileExplorer {
|
||||
fn build_found_explorer(wrkdir: &Path) -> FileExplorer {
|
||||
FileExplorerBuilder::new()
|
||||
.with_file_sorting(FileSorting::Name)
|
||||
.with_group_dirs(Some(GroupDirs::First))
|
||||
.with_hidden_files(true)
|
||||
.with_stack_size(0)
|
||||
.with_formatter(Some("{PATH:36} {SYMLINK}"))
|
||||
.with_formatter(Some(
|
||||
format!("{{PATH:36:{}}} {{SYMLINK}}", wrkdir.display()).as_str(),
|
||||
))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,6 +494,11 @@ impl Update for FileTransferActivity {
|
||||
);
|
||||
}
|
||||
Ok(files) => {
|
||||
// Get wrkdir
|
||||
let wrkdir = match self.browser.tab() {
|
||||
FileExplorerTab::Local => self.local().wrkdir.clone(),
|
||||
_ => self.remote().wrkdir.clone(),
|
||||
};
|
||||
// Create explorer and load files
|
||||
self.browser.set_found(
|
||||
match self.browser.tab() {
|
||||
@@ -501,6 +506,7 @@ impl Update for FileTransferActivity {
|
||||
_ => FoundExplorerTab::Remote,
|
||||
},
|
||||
files,
|
||||
wrkdir.as_path(),
|
||||
);
|
||||
// Mount result widget
|
||||
self.mount_find(input);
|
||||
|
||||
Reference in New Issue
Block a user