This commit is contained in:
veeso
2023-02-09 17:20:48 +01:00
parent 62003308a7
commit 4d5f3a6b63
40 changed files with 139 additions and 147 deletions

View File

@@ -102,7 +102,7 @@ impl AuthActivity {
fn write_bookmarks(&mut self) {
if let Some(bookmarks_cli) = self.bookmarks_client() {
if let Err(err) = bookmarks_cli.write_bookmarks() {
self.mount_error(format!("Could not write bookmarks: {}", err).as_str());
self.mount_error(format!("Could not write bookmarks: {err}").as_str());
}
}
}

View File

@@ -107,7 +107,7 @@ impl AuthActivity {
// Report error
error!("Failed to get latest version: {}", err);
self.mount_error(
format!("Could not check for new updates: {}", err).as_str(),
format!("Could not check for new updates: {err}").as_str(),
);
}
}
@@ -136,13 +136,13 @@ impl AuthActivity {
if self.config().get_notifications() {
Notification::update_installed(ver.as_str());
}
self.mount_info(format!("termscp has been updated to version {}!", ver))
self.mount_info(format!("termscp has been updated to version {ver}!"))
}
Err(err) => {
if self.config().get_notifications() {
Notification::update_failed(err.to_string());
}
self.mount_error(format!("Could not install update: {}", err))
self.mount_error(format!("Could not install update: {err}"))
}
}
}

View File

@@ -275,7 +275,7 @@ impl Activity for AuthActivity {
}
}
Err(err) => {
self.mount_error(format!("Application error: {}", err));
self.mount_error(format!("Application error: {err}"));
}
}
// View

View File

@@ -881,7 +881,7 @@ impl AuthActivity {
/// Format bookmark to display on ui
fn fmt_bookmark(name: &str, b: FileTransferParams) -> String {
let addr: String = Self::fmt_recent(b);
format!("{} ({})", name, addr)
format!("{name} ({addr})")
}
/// Format recent connection to display on ui
@@ -890,7 +890,7 @@ impl AuthActivity {
match b.params {
ProtocolParams::AwsS3(s3) => {
let profile: String = match s3.profile {
Some(p) => format!("[{}]", p),
Some(p) => format!("[{p}]"),
None => String::default(),
};
format!(
@@ -905,7 +905,7 @@ impl AuthActivity {
ProtocolParams::Generic(params) => {
let username: String = match params.username {
None => String::default(),
Some(u) => format!("{}@", u),
Some(u) => format!("{u}@"),
};
format!(
"{}://{}{}:{}",

View File

@@ -159,8 +159,7 @@ impl FileTransferActivity {
self.log(
LogLevel::Warn,
format!(
"Refused to create '{}'; synchronized browsing disabled",
name
"Refused to create '{name}'; synchronized browsing disabled"
),
);
self.browser.toggle_sync_browsing();

View File

@@ -116,7 +116,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: could not create temporary directory: {}", err),
format!("Copy failed: could not create temporary directory: {err}"),
);
return Err(err.to_string());
}
@@ -130,7 +130,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: failed to download file: {}", err),
format!("Copy failed: failed to download file: {err}"),
);
return Err(err);
}
@@ -158,7 +158,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: failed to send file: {}", err),
format!("Copy failed: failed to send file: {err}"),
);
return Err(err);
}
@@ -170,7 +170,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: could not create temporary file: {}", err),
format!("Copy failed: could not create temporary file: {err}"),
);
return Err(String::from("Could not create temporary file"));
}
@@ -183,7 +183,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: could not download to temporary file: {}", err),
format!("Copy failed: could not download to temporary file: {err}"),
);
return Err(err);
}

View File

@@ -71,12 +71,12 @@ impl FileTransferActivity {
}
}
Err(err) => {
return Err(format!("Could not read file: {}", err));
return Err(format!("Could not read file: {err}"));
}
}
}
Err(err) => {
return Err(format!("Could not read file: {}", err));
return Err(format!("Could not read file: {err}"));
}
}
// Put input mode back to normal
@@ -98,7 +98,7 @@ impl FileTransferActivity {
path.display()
),
),
Err(err) => return Err(format!("Could not open editor: {}", err)),
Err(err) => return Err(format!("Could not open editor: {err}")),
}
if let Some(ctx) = self.context.as_mut() {
// Enter alternate mode
@@ -134,7 +134,7 @@ impl FileTransferActivity {
tmpfile.as_path(),
Some(file_name.clone()),
) {
return Err(format!("Could not open file {}: {}", file_name, err));
return Err(format!("Could not open file {file_name}: {err}"));
}
// Get current file modification time
let prev_mtime: SystemTime = match self.host.stat(tmpfile.as_path()) {

View File

@@ -10,13 +10,13 @@ impl FileTransferActivity {
match self.host.exec(input.as_str()) {
Ok(output) => {
// Reload files
self.log(LogLevel::Info, format!("\"{}\": {}", input, output));
self.log(LogLevel::Info, format!("\"{input}\": {output}"));
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not execute command \"{}\": {}", input, err),
format!("Could not execute command \"{input}\": {err}"),
);
}
}
@@ -28,14 +28,14 @@ impl FileTransferActivity {
// Reload files
self.log(
LogLevel::Info,
format!("\"{}\" (exitcode: {}): {}", input, rc, output),
format!("\"{input}\" (exitcode: {rc}): {output}"),
);
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not execute command \"{}\": {}", input, err),
format!("Could not execute command \"{input}\": {err}"),
);
}
}

View File

@@ -12,14 +12,14 @@ impl FileTransferActivity {
pub(crate) fn action_local_find(&mut self, input: String) -> Result<Vec<File>, String> {
match self.host.find(input.as_str()) {
Ok(entries) => Ok(entries),
Err(err) => Err(format!("Could not search for files: {}", err)),
Err(err) => Err(format!("Could not search for files: {err}")),
}
}
pub(crate) fn action_remote_find(&mut self, input: String) -> Result<Vec<File>, String> {
match self.client.as_mut().find(input.as_str()) {
Ok(entries) => Ok(entries),
Err(err) => Err(format!("Could not search for files: {}", err)),
Err(err) => Err(format!("Could not search for files: {err}")),
}
}
@@ -72,7 +72,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -94,7 +94,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}
@@ -133,7 +133,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -163,7 +163,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}

View File

@@ -12,13 +12,13 @@ impl FileTransferActivity {
match self.host.mkdir(PathBuf::from(input.as_str()).as_path()) {
Ok(_) => {
// Reload files
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
self.log(LogLevel::Info, format!("Created directory \"{input}\""));
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not create directory \"{}\": {}", input, err),
format!("Could not create directory \"{input}\": {err}"),
);
}
}
@@ -30,13 +30,13 @@ impl FileTransferActivity {
) {
Ok(_) => {
// Reload files
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
self.log(LogLevel::Info, format!("Created directory \"{input}\""));
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not create directory \"{}\": {}", input, err),
format!("Could not create directory \"{input}\": {err}"),
);
}
}

View File

@@ -19,7 +19,7 @@ impl FileTransferActivity {
if file_exists {
self.log_and_alert(
LogLevel::Warn,
format!("File \"{}\" already exists", input,),
format!("File \"{input}\" already exists",),
);
return;
}
@@ -49,7 +49,7 @@ impl FileTransferActivity {
if file_exists {
self.log_and_alert(
LogLevel::Warn,
format!("File \"{}\" already exists", input,),
format!("File \"{input}\" already exists",),
);
return;
}
@@ -59,7 +59,7 @@ impl FileTransferActivity {
match tempfile::NamedTempFile::new() {
Err(err) => self.log_and_alert(
LogLevel::Error,
format!("Could not create tempfile: {}", err),
format!("Could not create tempfile: {err}"),
),
Ok(tfile) => {
// Stat tempfile
@@ -67,7 +67,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not stat tempfile: {}", err),
format!("Could not stat tempfile: {err}"),
);
return;
}
@@ -80,7 +80,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not open tempfile: {}", err),
format!("Could not open tempfile: {err}"),
);
return;
}

View File

@@ -71,7 +71,7 @@ impl FileTransferActivity {
Err(err) => {
self.log(
LogLevel::Error,
format!("Failed to download remote entry: {}", err),
format!("Failed to download remote entry: {err}"),
);
}
}

View File

@@ -47,7 +47,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -82,7 +82,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -111,7 +111,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}
@@ -146,7 +146,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}

View File

@@ -29,7 +29,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not create symlink: {}", err),
format!("Could not create symlink: {err}"),
);
}
}

View File

@@ -111,7 +111,7 @@ impl FileTransferActivity {
);
}
Some(Err(err)) => {
self.log_and_alert(LogLevel::Error, format!("could not unwatch path: {}", err));
self.log_and_alert(LogLevel::Error, format!("could not unwatch path: {err}"));
}
None => {}
}

View File

@@ -415,7 +415,7 @@ impl FileInfoPopup {
texts
.add_row()
.add_col(TextSpan::from("Size: "))
.add_col(TextSpan::new(format!("{} ({})", bsize, size).as_str()).fg(Color::Cyan));
.add_col(TextSpan::new(format!("{bsize} ({size})").as_str()).fg(Color::Cyan));
let atime: String = fmt_time(
file.metadata().accessed.unwrap_or(UNIX_EPOCH),
"%b %d %Y %H:%M:%S",
@@ -1330,7 +1330,7 @@ pub struct ReplacePopup {
impl ReplacePopup {
pub fn new(filename: Option<&str>, color: Color) -> Self {
let text = match filename {
Some(f) => format!(r#"File "{}" already exists. Overwrite file?"#, f),
Some(f) => format!(r#"File "{f}" already exists. Overwrite file?"#),
None => "Overwrite files?".to_string(),
};
Self {
@@ -1795,8 +1795,7 @@ impl SyncBrowsingMkdirPopup {
.choices(&["Yes", "No"])
.title(
format!(
r#"Sync browsing: directory "{}" doesn't exist. Do you want to create it?"#,
dir_name
r#"Sync browsing: directory "{dir_name}" doesn't exist. Do you want to create it?"#
),
Alignment::Center,
),
@@ -1974,8 +1973,8 @@ pub struct WatcherPopup {
impl WatcherPopup {
pub fn new(watched: bool, local: &str, remote: &str, color: Color) -> Self {
let text = match watched {
false => format!(r#"Synchronize changes from "{}" to "{}"?"#, local, remote),
true => format!(r#"Stop synchronizing changes at "{}"?"#, local),
false => format!(r#"Synchronize changes from "{local}" to "{remote}"?"#),
true => format!(r#"Stop synchronizing changes at "{local}"?"#),
};
Self {
component: Radio::default()

View File

@@ -38,7 +38,7 @@ impl FileTransferActivity {
Err(err) => {
self.log(
LogLevel::Error,
format!("error while polling file watcher: {}", err),
format!("error while polling file watcher: {err}"),
);
}
}

View File

@@ -35,7 +35,7 @@ impl FileTransferActivity {
}
}
Err(err) => {
self.mount_error(format!("Application error: {}", err));
self.mount_error(format!("Application error: {err}"));
}
}
}

View File

@@ -287,7 +287,7 @@ impl FileTransferActivity {
);
match file_type {
None => base,
Some(file_type) => format!("{}.{}", base, file_type),
Some(file_type) => format!("{base}.{file_type}"),
}
})
}

View File

@@ -134,7 +134,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
format!("Could not scan current directory: {err}"),
);
}
}
@@ -150,7 +150,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
format!("Could not scan current directory: {err}"),
);
}
}
@@ -435,7 +435,7 @@ impl FileTransferActivity {
// Init transfer
self.transfer.partial.init(file_size);
// rewind
if let Err(err) = reader.seek(std::io::SeekFrom::Start(0)) {
if let Err(err) = reader.rewind() {
return Err(TransferErrorReason::CouldNotRewind(err));
}
// Write remote file
@@ -491,7 +491,7 @@ impl FileTransferActivity {
// Draw only if a significant progress has been made (performance improvement)
if last_progress_val < self.transfer.partial.calc_progress() - 0.01 {
// Draw
self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.update_progress_bar(format!("Uploading \"{file_name}\""));
self.view();
last_progress_val = self.transfer.partial.calc_progress();
}
@@ -500,7 +500,7 @@ impl FileTransferActivity {
if let Err(err) = self.client.on_written(writer) {
self.log(
LogLevel::Warn,
format!("Could not finalize remote stream: \"{}\"", err),
format!("Could not finalize remote stream: \"{err}\""),
);
}
// if upload was abrupted, return error
@@ -539,11 +539,11 @@ impl FileTransferActivity {
// Init transfer
self.transfer.partial.init(file_size);
// rewind
if let Err(err) = reader.seek(std::io::SeekFrom::Start(0)) {
if let Err(err) = reader.rewind() {
return Err(TransferErrorReason::CouldNotRewind(err));
}
// Draw before
self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.update_progress_bar(format!("Uploading \"{file_name}\""));
self.view();
// Send file
if let Err(err) = self.client.create_file(remote, &metadata, Box::new(reader)) {
@@ -553,7 +553,7 @@ impl FileTransferActivity {
self.transfer.partial.update_progress(file_size);
self.transfer.full.update_progress(file_size);
// Draw again after
self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.update_progress_bar(format!("Uploading \"{file_name}\""));
self.view();
// log and return Ok
self.log(
@@ -892,7 +892,7 @@ impl FileTransferActivity {
// Draw only if a significant progress has been made (performance improvement)
if last_progress_val < self.transfer.partial.calc_progress() - 0.01 {
// Draw
self.update_progress_bar(format!("Downloading \"{}\"", file_name));
self.update_progress_bar(format!("Downloading \"{file_name}\""));
self.view();
last_progress_val = self.transfer.partial.calc_progress();
}
@@ -901,7 +901,7 @@ impl FileTransferActivity {
if let Err(err) = self.client.on_read(reader) {
self.log(
LogLevel::Warn,
format!("Could not finalize remote stream: \"{}\"", err),
format!("Could not finalize remote stream: \"{err}\""),
);
}
// If download was abrupted, return Error
@@ -953,7 +953,7 @@ impl FileTransferActivity {
// Init transfer
self.transfer.partial.init(remote.metadata.size as usize);
// Draw before transfer
self.update_progress_bar(format!("Downloading \"{}\"", file_name));
self.update_progress_bar(format!("Downloading \"{file_name}\""));
self.view();
// recv wno stream
if let Err(err) = self.client.open_file(remote.path.as_path(), reader) {
@@ -967,7 +967,7 @@ impl FileTransferActivity {
.full
.update_progress(remote.metadata.size as usize);
// Draw after transfer
self.update_progress_bar(format!("Downloading \"{}\"", file_name));
self.update_progress_bar(format!("Downloading \"{file_name}\""));
self.view();
// Apply file mode to file
#[cfg(target_family = "unix")]
@@ -1018,7 +1018,7 @@ impl FileTransferActivity {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not change working directory: {}", err),
format!("Could not change working directory: {err}"),
);
}
}
@@ -1045,7 +1045,7 @@ impl FileTransferActivity {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not change working directory: {}", err),
format!("Could not change working directory: {err}"),
);
}
}

View File

@@ -131,7 +131,7 @@ impl FileTransferActivity {
TransferMsg::ExecuteCmd(cmd) => {
// Exex command
self.umount_exec();
self.mount_blocking_wait(format!("Executing '{}'…", cmd).as_str());
self.mount_blocking_wait(format!("Executing '{cmd}'…").as_str());
match self.browser.tab() {
FileExplorerTab::Local => self.action_local_exec(cmd),
FileExplorerTab::Remote => self.action_remote_exec(cmd),
@@ -271,7 +271,7 @@ impl FileTransferActivity {
TransferMsg::SearchFile(search) => {
self.umount_find_input();
// Mount wait
self.mount_blocking_wait(format!(r#"Searching for "{}"…"#, search).as_str());
self.mount_blocking_wait(format!(r#"Searching for "{search}"…"#).as_str());
// Find
let res: Result<Vec<File>, String> = match self.browser.tab() {
FileExplorerTab::Local => self.action_local_find(search.clone()),
@@ -289,7 +289,7 @@ impl FileTransferActivity {
Ok(files) if files.is_empty() => {
// If no file has been found notify user
self.mount_info(
format!(r#"Could not find any file matching "{}""#, search).as_str(),
format!(r#"Could not find any file matching "{search}""#).as_str(),
);
}
Ok(files) => {

View File

@@ -490,7 +490,7 @@ impl FileTransferActivity {
.remount(
Id::ExplorerFind,
Box::new(components::ExplorerFind::new(
format!(r#"Search results for "{}""#, search),
format!(r#"Search results for "{search}""#),
&[],
bg,
fg,

View File

@@ -46,7 +46,7 @@ impl SetupActivity {
// Collect input values if in theme form
if self.layout == ViewLayout::Theme {
self.collect_styles()
.map_err(|e| format!("'{:?}' has an invalid color", e))?;
.map_err(|e| format!("'{e:?}' has an invalid color"))?;
}
// save theme
self.save_theme()
@@ -59,7 +59,7 @@ impl SetupActivity {
ViewLayout::SetupForm => self.collect_input_values(),
ViewLayout::Theme => self
.collect_styles()
.map_err(|e| format!("'{:?}' has an invalid color", e))?,
.map_err(|e| format!("'{e:?}' has an invalid color"))?,
_ => {}
}
// Update view
@@ -113,7 +113,7 @@ impl SetupActivity {
Err(err) => {
// Report error
self.mount_error(
format!("Could not get ssh key \"{}\": {}", key, err).as_str(),
format!("Could not get ssh key \"{key}\": {err}").as_str(),
);
}
}
@@ -134,7 +134,7 @@ impl SetupActivity {
};
// Prepare text editor
env::set_var("EDITOR", self.config().get_text_editor());
let placeholder: String = format!("# Type private SSH key for {}@{}\n", username, host);
let placeholder: String = format!("# Type private SSH key for {username}@{host}\n");
// Put input mode back to normal
if let Err(err) = self.context_mut().terminal().disable_raw_mode() {
error!("Could not disable raw mode: {}", err);
@@ -159,14 +159,14 @@ impl SetupActivity {
self.add_ssh_key(host.as_str(), username.as_str(), rsa_key.as_str())
{
self.mount_error(
format!("Could not create new private key: {}", err).as_str(),
format!("Could not create new private key: {err}").as_str(),
);
}
}
}
Err(err) => {
// Report error
self.mount_error(format!("Could not write private key to file: {}", err).as_str());
self.mount_error(format!("Could not write private key to file: {err}").as_str());
}
}
// Restore terminal

View File

@@ -15,7 +15,7 @@ impl SetupActivity {
Ok(_) => Ok(()),
Err(err) => {
error!("Could not save configuration: {}", err);
Err(format!("Could not save configuration: {}", err))
Err(format!("Could not save configuration: {err}"))
}
}
}
@@ -25,21 +25,21 @@ impl SetupActivity {
pub(super) fn reset_config_changes(&mut self) -> Result<(), String> {
self.config_mut()
.read_config()
.map_err(|e| format!("Could not reload configuration: {}", e))
.map_err(|e| format!("Could not reload configuration: {e}"))
}
/// Save theme to file
pub(super) fn save_theme(&mut self) -> Result<(), String> {
self.theme_provider()
.save()
.map_err(|e| format!("Could not save theme: {}", e))
.map_err(|e| format!("Could not save theme: {e}"))
}
/// Reset changes committed to theme
pub(super) fn reset_theme_changes(&mut self) -> Result<(), String> {
self.theme_provider()
.load()
.map_err(|e| format!("Could not restore theme: {}", e))
.map_err(|e| format!("Could not restore theme: {e}"))
}
/// Delete ssh key from config cli
@@ -47,8 +47,7 @@ impl SetupActivity {
match self.config_mut().del_ssh_key(host, username) {
Ok(_) => Ok(()),
Err(err) => Err(format!(
"Could not delete ssh key \"{}@{}\": {}",
host, username, err
"Could not delete ssh key \"{host}@{username}\": {err}"
)),
}
}
@@ -80,11 +79,11 @@ impl SetupActivity {
Some((_, _, key_path)) => {
match edit::edit_file(key_path.as_path()) {
Ok(_) => Ok(()),
Err(err) => Err(format!("Could not edit ssh key: {}", err)),
Err(err) => Err(format!("Could not edit ssh key: {err}")),
}
}
},
Err(err) => Err(format!("Could not read ssh key: {}", err)),
Err(err) => Err(format!("Could not read ssh key: {err}")),
}
}
None => Ok(()),
@@ -119,6 +118,6 @@ impl SetupActivity {
) -> Result<(), String> {
self.config_mut()
.add_ssh_key(host, username, rsa_key)
.map_err(|e| format!("Could not add SSH key: {}", e))
.map_err(|e| format!("Could not add SSH key: {e}"))
}
}

View File

@@ -352,7 +352,7 @@ impl Activity for SetupActivity {
}
}
Err(err) => {
self.mount_error(format!("Application error: {}", err));
self.mount_error(format!("Application error: {err}"));
}
}
// View

View File

@@ -124,7 +124,7 @@ impl SetupActivity {
.iter_ssh_keys()
.map(|x| {
let (addr, username, _) = self.config().get_ssh_key(x).ok().unwrap().unwrap();
format!("{} at {}", username, addr)
format!("{username} at {addr}")
})
.collect();
assert!(self