285 feature request multi host (#293)

This commit is contained in:
Christian Visintin
2024-10-07 16:27:45 +02:00
committed by GitHub
parent a4c9acb49f
commit aab266a661
59 changed files with 5522 additions and 2651 deletions
+56 -33
View File
@@ -1,8 +1,6 @@
// Locals
use std::env;
use std::path::{Path, PathBuf};
// Ext
use bytesize::ByteSize;
use tuirealm::props::{
Alignment, AttrValue, Attribute, Color, PropPayload, PropValue, TableBuilder, TextSpan,
@@ -11,7 +9,7 @@ use tuirealm::{PollStrategy, Update};
use super::browser::FileExplorerTab;
use super::{ConfigClient, FileTransferActivity, Id, LogLevel, LogRecord, TransferPayload};
use crate::filetransfer::ProtocolParams;
use crate::filetransfer::{HostBridgeParams, ProtocolParams};
use crate::system::environment;
use crate::system::notifications::Notification;
use crate::utils::fmt::{fmt_millis, fmt_path_elide_ex};
@@ -95,9 +93,9 @@ impl FileTransferActivity {
env::set_var("EDITOR", self.config().get_text_editor());
}
/// Convert a path to absolute according to local explorer
pub(super) fn local_to_abs_path(&self, path: &Path) -> PathBuf {
path::absolutize(self.local().wrkdir.as_path(), path)
/// Convert a path to absolute according to host explorer
pub(super) fn host_bridge_to_abs_path(&self, path: &Path) -> PathBuf {
path::absolutize(self.host_bridge().wrkdir.as_path(), path)
}
/// Convert a path to absolute according to remote explorer
@@ -107,8 +105,28 @@ impl FileTransferActivity {
/// Get remote hostname
pub(super) fn get_remote_hostname(&self) -> String {
let ft_params = self.context().ft_params().unwrap();
match &ft_params.params {
let ft_params = self.context().remote_params().unwrap();
self.get_hostname(&ft_params.params)
}
pub(super) fn get_hostbridge_hostname(&self) -> String {
let host_bridge_params = self.context().host_bridge_params().unwrap();
match host_bridge_params {
HostBridgeParams::Localhost(_) => {
let hostname = match hostname::get() {
Ok(h) => h,
Err(_) => return String::from("localhost"),
};
let hostname: String = hostname.as_os_str().to_string_lossy().to_string();
let tokens: Vec<&str> = hostname.split('.').collect();
String::from(*tokens.first().unwrap_or(&"localhost"))
}
HostBridgeParams::Remote(_, params) => self.get_hostname(params),
}
}
fn get_hostname(&self, params: &ProtocolParams) -> String {
match params {
ProtocolParams::Generic(params) => params.address.clone(),
ProtocolParams::AwsS3(params) => params.bucket_name.clone(),
ProtocolParams::Kube(params) => {
@@ -217,9 +235,9 @@ impl FileTransferActivity {
}
}
/// Update local file list
pub(super) fn update_local_filelist(&mut self) {
self.reload_local_dir();
/// Update host bridge file list
pub(super) fn update_host_bridge_filelist(&mut self) {
self.reload_host_bridge_dir();
// Get width
let width = self
.context_mut()
@@ -228,29 +246,26 @@ impl FileTransferActivity {
.size()
.map(|x| (x.width / 2) - 2)
.unwrap_or(0) as usize;
let hostname: String = match hostname::get() {
Ok(h) => {
let hostname: String = h.as_os_str().to_string_lossy().to_string();
let tokens: Vec<&str> = hostname.split('.').collect();
String::from(*tokens.first().unwrap_or(&"localhost"))
}
Err(_) => String::from("localhost"),
};
let hostname = self.get_hostbridge_hostname();
let hostname: String = format!(
"{}:{} ",
hostname,
fmt_path_elide_ex(self.local().wrkdir.as_path(), width, hostname.len() + 3) // 3 because of '/…/'
"{hostname}:{} ",
fmt_path_elide_ex(
self.host_bridge().wrkdir.as_path(),
width,
hostname.len() + 3
) // 3 because of '/…/'
);
let files: Vec<Vec<TextSpan>> = self
.local()
.host_bridge()
.iter_files()
.map(|x| vec![TextSpan::from(self.local().fmt_file(x))])
.map(|x| vec![TextSpan::from(self.host_bridge().fmt_file(x))])
.collect();
// Update content and title
assert!(self
.app
.attr(
&Id::ExplorerLocal,
&Id::ExplorerHostBridge,
Attribute::Content,
AttrValue::Table(files)
)
@@ -258,7 +273,7 @@ impl FileTransferActivity {
assert!(self
.app
.attr(
&Id::ExplorerLocal,
&Id::ExplorerHostBridge,
Attribute::Title,
AttrValue::Title((hostname, Alignment::Left))
)
@@ -409,17 +424,19 @@ impl FileTransferActivity {
self.browser.del_found();
// Restore tab
let new_tab = match self.browser.tab() {
FileExplorerTab::FindLocal => FileExplorerTab::Local,
FileExplorerTab::FindHostBridge => FileExplorerTab::HostBridge,
FileExplorerTab::FindRemote => FileExplorerTab::Remote,
_ => FileExplorerTab::Local,
_ => FileExplorerTab::HostBridge,
};
// Give focus to new tab
match new_tab {
FileExplorerTab::Local => assert!(self.app.active(&Id::ExplorerLocal).is_ok()),
FileExplorerTab::HostBridge => {
assert!(self.app.active(&Id::ExplorerHostBridge).is_ok())
}
FileExplorerTab::Remote => {
assert!(self.app.active(&Id::ExplorerRemote).is_ok())
}
FileExplorerTab::FindLocal | FileExplorerTab::FindRemote => {
FileExplorerTab::FindHostBridge | FileExplorerTab::FindRemote => {
assert!(self.app.active(&Id::ExplorerFind).is_ok())
}
}
@@ -445,15 +462,21 @@ impl FileTransferActivity {
pub(super) fn update_browser_file_list(&mut self) {
match self.browser.tab() {
FileExplorerTab::Local | FileExplorerTab::FindLocal => self.update_local_filelist(),
FileExplorerTab::HostBridge | FileExplorerTab::FindHostBridge => {
self.update_host_bridge_filelist()
}
FileExplorerTab::Remote | FileExplorerTab::FindRemote => self.update_remote_filelist(),
}
}
pub(super) fn update_browser_file_list_swapped(&mut self) {
match self.browser.tab() {
FileExplorerTab::Local | FileExplorerTab::FindLocal => self.update_remote_filelist(),
FileExplorerTab::Remote | FileExplorerTab::FindRemote => self.update_local_filelist(),
FileExplorerTab::HostBridge | FileExplorerTab::FindHostBridge => {
self.update_remote_filelist()
}
FileExplorerTab::Remote | FileExplorerTab::FindRemote => {
self.update_host_bridge_filelist()
}
}
}
}