mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Removed docs headers
This commit is contained in:
committed by
Christian Visintin
parent
2e0322bc0e
commit
027545f14c
@@ -60,8 +60,6 @@ pub struct ActivityManager {
|
||||
}
|
||||
|
||||
impl ActivityManager {
|
||||
/// ### new
|
||||
///
|
||||
/// Initializes a new Activity Manager
|
||||
pub fn new(local_dir: &Path, ticks: Duration) -> Result<ActivityManager, HostError> {
|
||||
// Prepare Context
|
||||
@@ -83,16 +81,12 @@ impl ActivityManager {
|
||||
})
|
||||
}
|
||||
|
||||
/// ### set_filetransfer_params
|
||||
///
|
||||
/// Set file transfer params
|
||||
pub fn set_filetransfer_params(&mut self, params: FileTransferParams) {
|
||||
// Put params into the context
|
||||
self.context.as_mut().unwrap().set_ftparams(params);
|
||||
}
|
||||
|
||||
/// ### run
|
||||
///
|
||||
///
|
||||
/// Loop for activity manager. You need to provide the activity to start with
|
||||
/// Returns the exitcode
|
||||
@@ -114,8 +108,6 @@ impl ActivityManager {
|
||||
|
||||
// -- Activity Loops
|
||||
|
||||
/// ### run_authentication
|
||||
///
|
||||
/// Loop for Authentication activity.
|
||||
/// Returns when activity terminates.
|
||||
/// Returns the next activity to run
|
||||
@@ -168,8 +160,6 @@ impl ActivityManager {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### run_filetransfer
|
||||
///
|
||||
/// Loop for FileTransfer activity.
|
||||
/// Returns when activity terminates.
|
||||
/// Returns the next activity to run
|
||||
@@ -233,8 +223,6 @@ impl ActivityManager {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### run_setup
|
||||
///
|
||||
/// `SetupActivity` run loop.
|
||||
/// Returns when activity terminates.
|
||||
/// Returns the next activity to run
|
||||
@@ -268,8 +256,6 @@ impl ActivityManager {
|
||||
|
||||
// -- misc
|
||||
|
||||
/// ### init_config_client
|
||||
///
|
||||
/// Initialize configuration client
|
||||
fn init_config_client() -> Result<ConfigClient, String> {
|
||||
// Get config dir
|
||||
|
||||
@@ -32,8 +32,6 @@ use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializ
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// ## UserHosts
|
||||
///
|
||||
/// UserHosts contains all the hosts saved by the user in the data storage
|
||||
/// It contains both `Bookmark`
|
||||
#[derive(Deserialize, Serialize, Debug, Default)]
|
||||
@@ -42,8 +40,6 @@ pub struct UserHosts {
|
||||
pub recents: HashMap<String, Bookmark>,
|
||||
}
|
||||
|
||||
/// ## Bookmark
|
||||
///
|
||||
/// Bookmark describes a single bookmark entry in the user hosts storage
|
||||
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
|
||||
pub struct Bookmark {
|
||||
@@ -64,8 +60,6 @@ pub struct Bookmark {
|
||||
pub s3: Option<S3Params>,
|
||||
}
|
||||
|
||||
/// ## S3Params
|
||||
///
|
||||
/// Connection parameters for Aws s3 protocol
|
||||
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Default)]
|
||||
pub struct S3Params {
|
||||
|
||||
@@ -36,8 +36,6 @@ use std::path::PathBuf;
|
||||
pub const DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD: u64 = 536870912; // 512MB
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Default)]
|
||||
/// ## UserConfig
|
||||
///
|
||||
/// UserConfig contains all the configurations for the user,
|
||||
/// supported by termscp
|
||||
pub struct UserConfig {
|
||||
@@ -46,8 +44,6 @@ pub struct UserConfig {
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
/// ## UserInterfaceConfig
|
||||
///
|
||||
/// UserInterfaceConfig provides all the keys to configure the user interface
|
||||
pub struct UserInterfaceConfig {
|
||||
pub text_editor: PathBuf,
|
||||
@@ -63,8 +59,6 @@ pub struct UserInterfaceConfig {
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Default)]
|
||||
/// ## RemoteConfig
|
||||
///
|
||||
/// Contains configuratio related to remote hosts
|
||||
pub struct RemoteConfig {
|
||||
pub ssh_keys: HashMap<String, PathBuf>, // Association between host name and path to private key
|
||||
|
||||
@@ -29,8 +29,6 @@ use serde::{de::DeserializeOwned, Serialize};
|
||||
use std::io::{Read, Write};
|
||||
use thiserror::Error;
|
||||
|
||||
/// ## SerializerError
|
||||
///
|
||||
/// Contains the error for serializer/deserializer
|
||||
#[derive(std::fmt::Debug)]
|
||||
pub struct SerializerError {
|
||||
@@ -38,8 +36,6 @@ pub struct SerializerError {
|
||||
msg: Option<String>,
|
||||
}
|
||||
|
||||
/// ## SerializerErrorKind
|
||||
///
|
||||
/// Describes the kind of error for the serializer/deserializer
|
||||
#[derive(Error, Debug)]
|
||||
pub enum SerializerErrorKind {
|
||||
@@ -54,15 +50,11 @@ pub enum SerializerErrorKind {
|
||||
}
|
||||
|
||||
impl SerializerError {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiate a new `SerializerError`
|
||||
pub fn new(kind: SerializerErrorKind) -> SerializerError {
|
||||
SerializerError { kind, msg: None }
|
||||
}
|
||||
|
||||
/// ### new_ex
|
||||
///
|
||||
/// Instantiates a new `SerializerError` with description message
|
||||
pub fn new_ex(kind: SerializerErrorKind, msg: String) -> SerializerError {
|
||||
let mut err: SerializerError = SerializerError::new(kind);
|
||||
|
||||
@@ -31,16 +31,12 @@ use super::{ExplorerOpts, FileExplorer, FileSorting, GroupDirs};
|
||||
// Ext
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// ## FileExplorerBuilder
|
||||
///
|
||||
/// Struct used to create a `FileExplorer`
|
||||
pub struct FileExplorerBuilder {
|
||||
explorer: Option<FileExplorer>,
|
||||
}
|
||||
|
||||
impl FileExplorerBuilder {
|
||||
/// ### new
|
||||
///
|
||||
/// Build a new `FileExplorerBuilder`
|
||||
pub fn new() -> Self {
|
||||
FileExplorerBuilder {
|
||||
@@ -48,15 +44,11 @@ impl FileExplorerBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### build
|
||||
///
|
||||
/// Take FileExplorer out of builder
|
||||
pub fn build(&mut self) -> FileExplorer {
|
||||
self.explorer.take().unwrap()
|
||||
}
|
||||
|
||||
/// ### with_hidden_files
|
||||
///
|
||||
/// Enable HIDDEN_FILES option
|
||||
pub fn with_hidden_files(&mut self, val: bool) -> &mut FileExplorerBuilder {
|
||||
if let Some(e) = self.explorer.as_mut() {
|
||||
@@ -68,8 +60,6 @@ impl FileExplorerBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// ### with_file_sorting
|
||||
///
|
||||
/// Set sorting method
|
||||
pub fn with_file_sorting(&mut self, sorting: FileSorting) -> &mut FileExplorerBuilder {
|
||||
if let Some(e) = self.explorer.as_mut() {
|
||||
@@ -78,8 +68,6 @@ impl FileExplorerBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// ### with_dirs_first
|
||||
///
|
||||
/// Enable DIRS_FIRST option
|
||||
pub fn with_group_dirs(&mut self, group_dirs: Option<GroupDirs>) -> &mut FileExplorerBuilder {
|
||||
if let Some(e) = self.explorer.as_mut() {
|
||||
@@ -88,8 +76,6 @@ impl FileExplorerBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// ### with_stack_size
|
||||
///
|
||||
/// Set stack size for FileExplorer
|
||||
pub fn with_stack_size(&mut self, sz: usize) -> &mut FileExplorerBuilder {
|
||||
if let Some(e) = self.explorer.as_mut() {
|
||||
@@ -99,8 +85,6 @@ impl FileExplorerBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// ### with_formatter
|
||||
///
|
||||
/// Set formatter for FileExplorer
|
||||
pub fn with_formatter(&mut self, fmt_str: Option<&str>) -> &mut FileExplorerBuilder {
|
||||
if let Some(e) = self.explorer.as_mut() {
|
||||
|
||||
@@ -64,8 +64,6 @@ lazy_static! {
|
||||
static ref FMT_ATTR_REGEX: Regex = Regex::new(r"(?:([A-Z]+))(:?([0-9]+))?(:?(.+))?").ok().unwrap();
|
||||
}
|
||||
|
||||
/// ## CallChainBlock
|
||||
///
|
||||
/// Call Chain block is a block in a chain of functions which are called in order to format the Entry.
|
||||
/// A callChain is instantiated starting from the Formatter syntax and the regex, once the groups are found
|
||||
/// a chain of function is made using the Formatters method.
|
||||
@@ -84,8 +82,6 @@ struct CallChainBlock {
|
||||
}
|
||||
|
||||
impl CallChainBlock {
|
||||
/// ### new
|
||||
///
|
||||
/// Create a new `CallChainBlock`
|
||||
pub fn new(
|
||||
func: FmtCallback,
|
||||
@@ -102,8 +98,6 @@ impl CallChainBlock {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### next
|
||||
///
|
||||
/// Call next callback in the CallChain
|
||||
pub fn next(&self, fmt: &Formatter, fsentry: &Entry, cur_str: &str) -> String {
|
||||
// Call func
|
||||
@@ -122,8 +116,6 @@ impl CallChainBlock {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### push
|
||||
///
|
||||
/// Push func to the last element in the Call chain
|
||||
pub fn push(
|
||||
&mut self,
|
||||
@@ -144,8 +136,6 @@ impl CallChainBlock {
|
||||
}
|
||||
}
|
||||
|
||||
/// ## Formatter
|
||||
///
|
||||
/// Formatter takes care of formatting FsEntries according to the provided keys.
|
||||
/// Formatting is performed using the `CallChainBlock`, which composed makes a Call Chain. This method is extremely fast compared to match the format groups
|
||||
/// at each fmt call.
|
||||
@@ -154,8 +144,6 @@ pub struct Formatter {
|
||||
}
|
||||
|
||||
impl Default for Formatter {
|
||||
/// ### default
|
||||
///
|
||||
/// Instantiates a Formatter with the default fmt syntax
|
||||
fn default() -> Self {
|
||||
Formatter {
|
||||
@@ -165,8 +153,6 @@ impl Default for Formatter {
|
||||
}
|
||||
|
||||
impl Formatter {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new `Formatter` with the provided format string
|
||||
pub fn new(fmt_str: &str) -> Self {
|
||||
Formatter {
|
||||
@@ -174,8 +160,6 @@ impl Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### fmt
|
||||
///
|
||||
/// Format fsentry
|
||||
pub fn fmt(&self, fsentry: &Entry) -> String {
|
||||
// Execute callchain blocks
|
||||
@@ -184,8 +168,6 @@ impl Formatter {
|
||||
|
||||
// Fmt methods
|
||||
|
||||
/// ### fmt_atime
|
||||
///
|
||||
/// Format last access time
|
||||
fn fmt_atime(
|
||||
&self,
|
||||
@@ -213,8 +195,6 @@ impl Formatter {
|
||||
)
|
||||
}
|
||||
|
||||
/// ### fmt_ctime
|
||||
///
|
||||
/// Format creation time
|
||||
fn fmt_ctime(
|
||||
&self,
|
||||
@@ -242,8 +222,6 @@ impl Formatter {
|
||||
)
|
||||
}
|
||||
|
||||
/// ### fmt_group
|
||||
///
|
||||
/// Format owner group
|
||||
fn fmt_group(
|
||||
&self,
|
||||
@@ -277,8 +255,6 @@ impl Formatter {
|
||||
)
|
||||
}
|
||||
|
||||
/// ### fmt_mtime
|
||||
///
|
||||
/// Format last change time
|
||||
fn fmt_mtime(
|
||||
&self,
|
||||
@@ -306,8 +282,6 @@ impl Formatter {
|
||||
)
|
||||
}
|
||||
|
||||
/// ### fmt_name
|
||||
///
|
||||
/// Format file name
|
||||
fn fmt_name(
|
||||
&self,
|
||||
@@ -339,8 +313,6 @@ impl Formatter {
|
||||
format!("{}{}{:0width$}", cur_str, prefix, name, width = file_len)
|
||||
}
|
||||
|
||||
/// ### fmt_path
|
||||
///
|
||||
/// Format path
|
||||
fn fmt_path(
|
||||
&self,
|
||||
@@ -366,8 +338,6 @@ impl Formatter {
|
||||
)
|
||||
}
|
||||
|
||||
/// ### fmt_pex
|
||||
///
|
||||
/// Format file permissions
|
||||
fn fmt_pex(
|
||||
&self,
|
||||
@@ -403,8 +373,6 @@ impl Formatter {
|
||||
format!("{}{}{:10}", cur_str, prefix, pex)
|
||||
}
|
||||
|
||||
/// ### fmt_size
|
||||
///
|
||||
/// Format file size
|
||||
fn fmt_size(
|
||||
&self,
|
||||
@@ -425,8 +393,6 @@ impl Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### fmt_symlink
|
||||
///
|
||||
/// Format file symlink (if any)
|
||||
fn fmt_symlink(
|
||||
&self,
|
||||
@@ -454,8 +420,6 @@ impl Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### fmt_user
|
||||
///
|
||||
/// Format owner user
|
||||
fn fmt_user(
|
||||
&self,
|
||||
@@ -483,8 +447,6 @@ impl Formatter {
|
||||
format!("{}{}{:12}", cur_str, prefix, username)
|
||||
}
|
||||
|
||||
/// ### fmt_fallback
|
||||
///
|
||||
/// Fallback function in case the format key is unknown
|
||||
/// It does nothing, just returns cur_str
|
||||
fn fmt_fallback(
|
||||
@@ -501,8 +463,6 @@ impl Formatter {
|
||||
|
||||
// Static
|
||||
|
||||
/// ### make_callchain
|
||||
///
|
||||
/// Make a callchain starting from the fmt str
|
||||
fn make_callchain(fmt_str: &str) -> CallChainBlock {
|
||||
// Init chain block
|
||||
@@ -952,8 +912,6 @@ mod tests {
|
||||
assert_eq!(formatter.fmt(&entry).as_str(), "File path: c/bar.txt");
|
||||
}
|
||||
|
||||
/// ### dummy_fmt
|
||||
///
|
||||
/// Dummy formatter, just yelds an 'A' at the end of the current string
|
||||
fn dummy_fmt(
|
||||
_fmt: &Formatter,
|
||||
|
||||
@@ -47,8 +47,6 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
/// ## FileSorting
|
||||
///
|
||||
/// FileSorting defines the criteria for sorting files
|
||||
#[derive(Copy, Clone, PartialEq, std::fmt::Debug)]
|
||||
pub enum FileSorting {
|
||||
@@ -58,8 +56,6 @@ pub enum FileSorting {
|
||||
Size,
|
||||
}
|
||||
|
||||
/// ## GroupDirs
|
||||
///
|
||||
/// GroupDirs defines how directories should be grouped in sorting files
|
||||
#[derive(PartialEq, std::fmt::Debug)]
|
||||
pub enum GroupDirs {
|
||||
@@ -67,8 +63,6 @@ pub enum GroupDirs {
|
||||
Last,
|
||||
}
|
||||
|
||||
/// ## FileExplorer
|
||||
///
|
||||
/// File explorer states
|
||||
pub struct FileExplorer {
|
||||
pub wrkdir: PathBuf, // Current directory
|
||||
@@ -97,8 +91,6 @@ impl Default for FileExplorer {
|
||||
}
|
||||
|
||||
impl FileExplorer {
|
||||
/// ### pushd
|
||||
///
|
||||
/// push directory to stack
|
||||
pub fn pushd(&mut self, dir: &Path) {
|
||||
// Check if stack would overflow the size
|
||||
@@ -109,15 +101,11 @@ impl FileExplorer {
|
||||
self.dirstack.push_back(PathBuf::from(dir));
|
||||
}
|
||||
|
||||
/// ### popd
|
||||
///
|
||||
/// Pop directory from the stack and return the directory
|
||||
pub fn popd(&mut self) -> Option<PathBuf> {
|
||||
self.dirstack.pop_back()
|
||||
}
|
||||
|
||||
/// ### set_files
|
||||
///
|
||||
/// Set Explorer files
|
||||
/// This method will also sort entries based on current options
|
||||
/// Once all sorting have been performed, index is moved to first valid entry.
|
||||
@@ -127,8 +115,6 @@ impl FileExplorer {
|
||||
self.sort();
|
||||
}
|
||||
|
||||
/// ### del_entry
|
||||
///
|
||||
/// Delete file at provided index
|
||||
pub fn del_entry(&mut self, idx: usize) {
|
||||
if self.files.len() > idx {
|
||||
@@ -137,16 +123,12 @@ impl FileExplorer {
|
||||
}
|
||||
|
||||
/*
|
||||
/// ### count
|
||||
///
|
||||
/// Return amount of files
|
||||
pub fn count(&self) -> usize {
|
||||
self.files.len()
|
||||
}
|
||||
*/
|
||||
|
||||
/// ### iter_files
|
||||
///
|
||||
/// Iterate over files
|
||||
/// Filters are applied based on current options (e.g. hidden files not returned)
|
||||
pub fn iter_files(&self) -> impl Iterator<Item = &Entry> + '_ {
|
||||
@@ -163,15 +145,11 @@ impl FileExplorer {
|
||||
}))
|
||||
}
|
||||
|
||||
/// ### iter_files_all
|
||||
///
|
||||
/// Iterate all files; doesn't care about options
|
||||
pub fn iter_files_all(&self) -> impl Iterator<Item = &Entry> + '_ {
|
||||
Box::new(self.files.iter())
|
||||
}
|
||||
|
||||
/// ### get
|
||||
///
|
||||
/// Get file at relative index
|
||||
pub fn get(&self, idx: usize) -> Option<&Entry> {
|
||||
let opts: ExplorerOpts = self.opts;
|
||||
@@ -193,8 +171,6 @@ impl FileExplorer {
|
||||
|
||||
// Formatting
|
||||
|
||||
/// ### fmt_file
|
||||
///
|
||||
/// Format a file entry
|
||||
pub fn fmt_file(&self, entry: &Entry) -> String {
|
||||
self.fmt.fmt(entry)
|
||||
@@ -202,8 +178,6 @@ impl FileExplorer {
|
||||
|
||||
// Sorting
|
||||
|
||||
/// ### sort_by
|
||||
///
|
||||
/// Choose sorting method; then sort files
|
||||
pub fn sort_by(&mut self, sorting: FileSorting) {
|
||||
// If method HAS ACTUALLY CHANGED, sort (performance!)
|
||||
@@ -213,15 +187,11 @@ impl FileExplorer {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_file_sorting
|
||||
///
|
||||
/// Get current file sorting method
|
||||
pub fn get_file_sorting(&self) -> FileSorting {
|
||||
self.file_sorting
|
||||
}
|
||||
|
||||
/// ### group_dirs_by
|
||||
///
|
||||
/// Choose group dirs method; then sort files
|
||||
pub fn group_dirs_by(&mut self, group_dirs: Option<GroupDirs>) {
|
||||
// If method HAS ACTUALLY CHANGED, sort (performance!)
|
||||
@@ -231,8 +201,6 @@ impl FileExplorer {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### sort
|
||||
///
|
||||
/// Sort files based on Explorer options.
|
||||
fn sort(&mut self) {
|
||||
// Choose sorting method
|
||||
@@ -252,60 +220,44 @@ impl FileExplorer {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### sort_files_by_name
|
||||
///
|
||||
/// Sort explorer files by their name. All names are converted to lowercase
|
||||
fn sort_files_by_name(&mut self) {
|
||||
self.files.sort_by_key(|x: &Entry| x.name().to_lowercase());
|
||||
}
|
||||
|
||||
/// ### sort_files_by_mtime
|
||||
///
|
||||
/// Sort files by mtime; the newest comes first
|
||||
fn sort_files_by_mtime(&mut self) {
|
||||
self.files
|
||||
.sort_by(|a: &Entry, b: &Entry| b.metadata().mtime.cmp(&a.metadata().mtime));
|
||||
}
|
||||
|
||||
/// ### sort_files_by_creation_time
|
||||
///
|
||||
/// Sort files by creation time; the newest comes first
|
||||
fn sort_files_by_creation_time(&mut self) {
|
||||
self.files
|
||||
.sort_by_key(|b: &Entry| Reverse(b.metadata().ctime));
|
||||
}
|
||||
|
||||
/// ### sort_files_by_size
|
||||
///
|
||||
/// Sort files by size
|
||||
fn sort_files_by_size(&mut self) {
|
||||
self.files
|
||||
.sort_by_key(|b: &Entry| Reverse(b.metadata().size));
|
||||
}
|
||||
|
||||
/// ### sort_files_directories_first
|
||||
///
|
||||
/// Sort files; directories come first
|
||||
fn sort_files_directories_first(&mut self) {
|
||||
self.files.sort_by_key(|x: &Entry| x.is_file());
|
||||
}
|
||||
|
||||
/// ### sort_files_directories_last
|
||||
///
|
||||
/// Sort files; directories come last
|
||||
fn sort_files_directories_last(&mut self) {
|
||||
self.files.sort_by_key(|x: &Entry| x.is_dir());
|
||||
}
|
||||
|
||||
/// ### toggle_hidden_files
|
||||
///
|
||||
/// Enable/disable hidden files
|
||||
pub fn toggle_hidden_files(&mut self) {
|
||||
self.opts.toggle(ExplorerOpts::SHOW_HIDDEN_FILES);
|
||||
}
|
||||
|
||||
/// ### hidden_files_visible
|
||||
///
|
||||
/// Returns whether hidden files are visible
|
||||
pub fn hidden_files_visible(&self) -> bool {
|
||||
self.opts.intersects(ExplorerOpts::SHOW_HIDDEN_FILES)
|
||||
|
||||
@@ -32,8 +32,6 @@ pub mod params;
|
||||
pub use builder::Builder;
|
||||
pub use params::{FileTransferParams, ProtocolParams};
|
||||
|
||||
/// ## FileTransferProtocol
|
||||
///
|
||||
/// This enum defines the different transfer protocol available in termscp
|
||||
|
||||
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||
|
||||
@@ -39,8 +39,6 @@ pub struct FileTransferParams {
|
||||
pub entry_directory: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// ## ProtocolParams
|
||||
///
|
||||
/// Container for protocol params
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ProtocolParams {
|
||||
@@ -48,8 +46,6 @@ pub enum ProtocolParams {
|
||||
AwsS3(AwsS3Params),
|
||||
}
|
||||
|
||||
/// ## GenericProtocolParams
|
||||
///
|
||||
/// Protocol params used by most common protocols
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GenericProtocolParams {
|
||||
@@ -59,8 +55,6 @@ pub struct GenericProtocolParams {
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
/// ## AwsS3Params
|
||||
///
|
||||
/// Connection parameters for AWS S3 protocol
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AwsS3Params {
|
||||
@@ -70,8 +64,6 @@ pub struct AwsS3Params {
|
||||
}
|
||||
|
||||
impl FileTransferParams {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new `FileTransferParams`
|
||||
pub fn new(protocol: FileTransferProtocol, params: ProtocolParams) -> Self {
|
||||
Self {
|
||||
@@ -81,8 +73,6 @@ impl FileTransferParams {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### entry_directory
|
||||
///
|
||||
/// Set entry directory
|
||||
pub fn entry_directory<P: AsRef<Path>>(mut self, dir: Option<P>) -> Self {
|
||||
self.entry_directory = dir.map(|x| x.as_ref().to_path_buf());
|
||||
@@ -143,32 +133,24 @@ impl Default for GenericProtocolParams {
|
||||
}
|
||||
|
||||
impl GenericProtocolParams {
|
||||
/// ### address
|
||||
///
|
||||
/// Set address to params
|
||||
pub fn address<S: AsRef<str>>(mut self, address: S) -> Self {
|
||||
self.address = address.as_ref().to_string();
|
||||
self
|
||||
}
|
||||
|
||||
/// ### port
|
||||
///
|
||||
/// Set port to params
|
||||
pub fn port(mut self, port: u16) -> Self {
|
||||
self.port = port;
|
||||
self
|
||||
}
|
||||
|
||||
/// ### username
|
||||
///
|
||||
/// Set username for params
|
||||
pub fn username<S: AsRef<str>>(mut self, username: Option<S>) -> Self {
|
||||
self.username = username.map(|x| x.as_ref().to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// ### password
|
||||
///
|
||||
/// Set password for params
|
||||
pub fn password<S: AsRef<str>>(mut self, password: Option<S>) -> Self {
|
||||
self.password = password.map(|x| x.as_ref().to_string());
|
||||
@@ -179,8 +161,6 @@ impl GenericProtocolParams {
|
||||
// -- S3 params
|
||||
|
||||
impl AwsS3Params {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new `AwsS3Params` struct
|
||||
pub fn new<S: AsRef<str>>(bucket: S, region: S, profile: Option<S>) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -43,8 +43,6 @@ use std::os::unix::fs::{MetadataExt, PermissionsExt};
|
||||
// Locals
|
||||
use crate::utils::path;
|
||||
|
||||
/// ## HostErrorType
|
||||
///
|
||||
/// HostErrorType provides an overview of the specific host error
|
||||
#[derive(Error, Debug)]
|
||||
pub enum HostErrorType {
|
||||
@@ -77,8 +75,6 @@ pub struct HostError {
|
||||
}
|
||||
|
||||
impl HostError {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new HostError
|
||||
pub(crate) fn new(error: HostErrorType, errno: Option<std::io::Error>, p: &Path) -> Self {
|
||||
HostError {
|
||||
@@ -112,8 +108,6 @@ impl std::fmt::Display for HostError {
|
||||
}
|
||||
}
|
||||
|
||||
/// ## Localhost
|
||||
///
|
||||
/// Localhost is the entity which holds the information about the current directory and host.
|
||||
/// It provides functions to navigate across the local host file system
|
||||
pub struct Localhost {
|
||||
@@ -122,8 +116,6 @@ pub struct Localhost {
|
||||
}
|
||||
|
||||
impl Localhost {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new Localhost struct
|
||||
pub fn new(wrkdir: PathBuf) -> Result<Localhost, HostError> {
|
||||
debug!("Initializing localhost at {}", wrkdir.display());
|
||||
@@ -158,23 +150,17 @@ impl Localhost {
|
||||
Ok(host)
|
||||
}
|
||||
|
||||
/// ### pwd
|
||||
///
|
||||
/// Print working directory
|
||||
pub fn pwd(&self) -> PathBuf {
|
||||
self.wrkdir.clone()
|
||||
}
|
||||
|
||||
/// ### list_dir
|
||||
///
|
||||
/// List files in current directory
|
||||
#[allow(dead_code)]
|
||||
pub fn list_dir(&self) -> Vec<Entry> {
|
||||
self.files.clone()
|
||||
}
|
||||
|
||||
/// ### change_wrkdir
|
||||
///
|
||||
/// Change working directory with the new provided directory
|
||||
pub fn change_wrkdir(&mut self, new_dir: &Path) -> Result<PathBuf, HostError> {
|
||||
let new_dir: PathBuf = self.to_path(new_dir);
|
||||
@@ -215,15 +201,11 @@ impl Localhost {
|
||||
Ok(self.wrkdir.clone())
|
||||
}
|
||||
|
||||
/// ### mkdir
|
||||
///
|
||||
/// Make a directory at path and update the file list (only if relative)
|
||||
pub fn mkdir(&mut self, dir_name: &Path) -> Result<(), HostError> {
|
||||
self.mkdir_ex(dir_name, false)
|
||||
}
|
||||
|
||||
/// ### mkdir_ex
|
||||
///
|
||||
/// Extended option version of makedir.
|
||||
/// ignex: don't report error if directory already exists
|
||||
pub fn mkdir_ex(&mut self, dir_name: &Path, ignex: bool) -> Result<(), HostError> {
|
||||
@@ -262,8 +244,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### remove
|
||||
///
|
||||
/// Remove file entry
|
||||
pub fn remove(&mut self, entry: &Entry) -> Result<(), HostError> {
|
||||
match entry {
|
||||
@@ -328,8 +308,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### rename
|
||||
///
|
||||
/// Rename file or directory to new name
|
||||
pub fn rename(&mut self, entry: &Entry, dst_path: &Path) -> Result<(), HostError> {
|
||||
match std::fs::rename(entry.path(), dst_path) {
|
||||
@@ -359,8 +337,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### copy
|
||||
///
|
||||
/// Copy file to destination path
|
||||
pub fn copy(&mut self, entry: &Entry, dst: &Path) -> Result<(), HostError> {
|
||||
// Get absolute path of dest
|
||||
@@ -436,8 +412,6 @@ impl Localhost {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### stat
|
||||
///
|
||||
/// Stat file and create a Entry
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn stat(&self, path: &Path) -> Result<Entry, HostError> {
|
||||
@@ -491,8 +465,6 @@ impl Localhost {
|
||||
})
|
||||
}
|
||||
|
||||
/// ### stat
|
||||
///
|
||||
/// Stat file and create a Entry
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn stat(&self, path: &Path) -> Result<Entry, HostError> {
|
||||
@@ -542,8 +514,6 @@ impl Localhost {
|
||||
})
|
||||
}
|
||||
|
||||
/// ### exec
|
||||
///
|
||||
/// Execute a command on localhost
|
||||
pub fn exec(&self, cmd: &str) -> Result<String, HostError> {
|
||||
// Make command
|
||||
@@ -570,8 +540,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### chmod
|
||||
///
|
||||
/// Change file mode to file, according to UNIX permissions
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn chmod(&self, path: &Path, pex: UnixPex) -> Result<(), HostError> {
|
||||
@@ -611,8 +579,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### open_file_read
|
||||
///
|
||||
/// Open file for read
|
||||
pub fn open_file_read(&self, file: &Path) -> Result<StdFile, HostError> {
|
||||
let file: PathBuf = self.to_path(file);
|
||||
@@ -643,8 +609,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### open_file_write
|
||||
///
|
||||
/// Open file for write
|
||||
pub fn open_file_write(&self, file: &Path) -> Result<StdFile, HostError> {
|
||||
let file: PathBuf = self.to_path(file);
|
||||
@@ -674,15 +638,11 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### file_exists
|
||||
///
|
||||
/// Returns whether provided file path exists
|
||||
pub fn file_exists(&self, path: &Path) -> bool {
|
||||
path.exists()
|
||||
}
|
||||
|
||||
/// ### scan_dir
|
||||
///
|
||||
/// Get content of the current directory as a list of fs entry
|
||||
pub fn scan_dir(&self, dir: &Path) -> Result<Vec<Entry>, HostError> {
|
||||
info!("Reading directory {}", dir.display());
|
||||
@@ -706,8 +666,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### find
|
||||
///
|
||||
/// Find files matching `search` on localhost starting from current directory. Search supports recursive search of course.
|
||||
/// The `search` argument supports wilcards ('*', '?')
|
||||
pub fn find(&self, search: &str) -> Result<Vec<Entry>, HostError> {
|
||||
@@ -716,8 +674,6 @@ impl Localhost {
|
||||
|
||||
// -- privates
|
||||
|
||||
/// ### iter_search
|
||||
///
|
||||
/// Recursive call for `find` method.
|
||||
/// Search in current directory for files which match `filter`.
|
||||
/// If a directory is found in current directory, `iter_search` will be called using that dir as argument.
|
||||
@@ -755,8 +711,6 @@ impl Localhost {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### to_path
|
||||
///
|
||||
/// Convert path to absolute path
|
||||
fn to_path(&self, p: &Path) -> PathBuf {
|
||||
path::absolutize(self.wrkdir.as_path(), p)
|
||||
|
||||
@@ -44,8 +44,6 @@ pub enum UpdateStatus {
|
||||
UpdateInstalled(String),
|
||||
}
|
||||
|
||||
/// ## Release
|
||||
///
|
||||
/// Info related to a github release
|
||||
#[derive(Debug)]
|
||||
pub struct Release {
|
||||
@@ -53,8 +51,6 @@ pub struct Release {
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
/// ## Update
|
||||
///
|
||||
/// The update structure defines the options used to install the update.
|
||||
/// Once you're fine with the options, just call the `upgrade()` method to upgrade termscp.
|
||||
#[derive(Debug, Default)]
|
||||
@@ -64,16 +60,12 @@ pub struct Update {
|
||||
}
|
||||
|
||||
impl Update {
|
||||
/// ### show_progress
|
||||
///
|
||||
/// Set whether to show or not the progress bar
|
||||
pub fn show_progress(mut self, opt: bool) -> Self {
|
||||
self.progress = opt;
|
||||
self
|
||||
}
|
||||
|
||||
/// ### ask_confirm
|
||||
///
|
||||
/// Set whether to ask for confirm when updating
|
||||
pub fn ask_confirm(mut self, opt: bool) -> Self {
|
||||
self.ask_confirm = opt;
|
||||
@@ -96,8 +88,6 @@ impl Update {
|
||||
.map(UpdateStatus::from)
|
||||
}
|
||||
|
||||
/// ### is_new_version_available
|
||||
///
|
||||
/// Returns whether a new version of termscp is available
|
||||
/// In case of success returns Ok(Option<Release>), where the Option is Some(new_version);
|
||||
/// otherwise if no version is available, return None
|
||||
@@ -119,8 +109,6 @@ impl Update {
|
||||
.map(Self::check_version)
|
||||
}
|
||||
|
||||
/// ### check_version
|
||||
///
|
||||
/// In case received version is newer than current one, version as Some is returned; otherwise None
|
||||
fn check_version(r: Release) -> Option<Release> {
|
||||
match parse_semver(r.version.as_str()) {
|
||||
|
||||
@@ -44,8 +44,6 @@ use std::path::{Path, PathBuf};
|
||||
use std::string::ToString;
|
||||
use std::time::SystemTime;
|
||||
|
||||
/// ## BookmarksClient
|
||||
///
|
||||
/// BookmarksClient provides a layer between the host system and the bookmarks module
|
||||
pub struct BookmarksClient {
|
||||
hosts: UserHosts,
|
||||
@@ -55,8 +53,6 @@ pub struct BookmarksClient {
|
||||
}
|
||||
|
||||
impl BookmarksClient {
|
||||
/// ### BookmarksClient
|
||||
///
|
||||
/// Instantiates a new BookmarksClient
|
||||
/// Bookmarks file path must be provided
|
||||
/// Storage path for file provider must be provided
|
||||
@@ -155,15 +151,11 @@ impl BookmarksClient {
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
/// ### iter_bookmarks
|
||||
///
|
||||
/// Iterate over bookmarks keys
|
||||
pub fn iter_bookmarks(&self) -> impl Iterator<Item = &String> + '_ {
|
||||
Box::new(self.hosts.bookmarks.keys())
|
||||
}
|
||||
|
||||
/// ### get_bookmark
|
||||
///
|
||||
/// Get bookmark associated to key
|
||||
pub fn get_bookmark(&self, key: &str) -> Option<FileTransferParams> {
|
||||
debug!("Getting bookmark {}", key);
|
||||
@@ -183,8 +175,6 @@ impl BookmarksClient {
|
||||
Some(FileTransferParams::from(entry))
|
||||
}
|
||||
|
||||
/// ### add_recent
|
||||
///
|
||||
/// Add a new recent to bookmarks
|
||||
pub fn add_bookmark<S: AsRef<str>>(
|
||||
&mut self,
|
||||
@@ -207,22 +197,16 @@ impl BookmarksClient {
|
||||
self.hosts.bookmarks.insert(name, host);
|
||||
}
|
||||
|
||||
/// ### del_bookmark
|
||||
///
|
||||
/// Delete entry from bookmarks
|
||||
pub fn del_bookmark(&mut self, name: &str) {
|
||||
let _ = self.hosts.bookmarks.remove(name);
|
||||
info!("Removed bookmark {}", name);
|
||||
}
|
||||
/// ### iter_recents
|
||||
///
|
||||
/// Iterate over recents keys
|
||||
pub fn iter_recents(&self) -> impl Iterator<Item = &String> + '_ {
|
||||
Box::new(self.hosts.recents.keys())
|
||||
}
|
||||
|
||||
/// ### get_recent
|
||||
///
|
||||
/// Get recent associated to key
|
||||
pub fn get_recent(&self, key: &str) -> Option<FileTransferParams> {
|
||||
// NOTE: password is not decrypted; recents will never have password
|
||||
@@ -231,8 +215,6 @@ impl BookmarksClient {
|
||||
Some(FileTransferParams::from(entry))
|
||||
}
|
||||
|
||||
/// ### add_recent
|
||||
///
|
||||
/// Add a new recent to bookmarks
|
||||
pub fn add_recent(&mut self, params: FileTransferParams) {
|
||||
// Make bookmark
|
||||
@@ -271,16 +253,12 @@ impl BookmarksClient {
|
||||
self.hosts.recents.insert(name, host);
|
||||
}
|
||||
|
||||
/// ### del_recent
|
||||
///
|
||||
/// Delete entry from recents
|
||||
pub fn del_recent(&mut self, name: &str) {
|
||||
let _ = self.hosts.recents.remove(name);
|
||||
info!("Removed recent host {}", name);
|
||||
}
|
||||
|
||||
/// ### write_bookmarks
|
||||
///
|
||||
/// Write bookmarks to file
|
||||
pub fn write_bookmarks(&self) -> Result<(), SerializerError> {
|
||||
// Open file
|
||||
@@ -302,8 +280,6 @@ impl BookmarksClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### read_bookmarks
|
||||
///
|
||||
/// Read bookmarks from file
|
||||
fn read_bookmarks(&mut self) -> Result<(), SerializerError> {
|
||||
// Open bookmarks file for read
|
||||
@@ -332,16 +308,12 @@ impl BookmarksClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### generate_key
|
||||
///
|
||||
/// Generate a new AES key
|
||||
fn generate_key() -> String {
|
||||
// Generate 256 bytes (2048 bits) key
|
||||
random_alphanumeric_with_len(256)
|
||||
}
|
||||
|
||||
/// ### make_bookmark
|
||||
///
|
||||
/// Make bookmark from credentials
|
||||
fn make_bookmark(&self, params: FileTransferParams) -> Bookmark {
|
||||
let mut bookmark: Bookmark = Bookmark::from(params);
|
||||
@@ -352,15 +324,11 @@ impl BookmarksClient {
|
||||
bookmark
|
||||
}
|
||||
|
||||
/// ### encrypt_str
|
||||
///
|
||||
/// Encrypt provided string using AES-128. Encrypted buffer is then converted to BASE64
|
||||
fn encrypt_str(&self, txt: &str) -> String {
|
||||
crypto::aes128_b64_crypt(self.key.as_str(), txt)
|
||||
}
|
||||
|
||||
/// ### decrypt_str
|
||||
///
|
||||
/// Decrypt provided string using AES-128
|
||||
fn decrypt_str(&self, secret: &str) -> Result<String, SerializerError> {
|
||||
match crypto::aes128_b64_decrypt(self.key.as_str(), secret) {
|
||||
@@ -741,8 +709,6 @@ mod tests {
|
||||
assert!(client.decrypt_str("bidoof").is_err());
|
||||
}
|
||||
|
||||
/// ### get_paths
|
||||
///
|
||||
/// Get paths for configuration and key for bookmarks
|
||||
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
|
||||
let k: PathBuf = PathBuf::from(dir);
|
||||
|
||||
@@ -42,8 +42,6 @@ use std::string::ToString;
|
||||
// Types
|
||||
pub type SshHost = (String, String, PathBuf); // 0: host, 1: username, 2: RSA key path
|
||||
|
||||
/// ## ConfigClient
|
||||
///
|
||||
/// ConfigClient provides a high level API to communicate with the termscp configuration
|
||||
pub struct ConfigClient {
|
||||
config: UserConfig, // Configuration loaded
|
||||
@@ -53,8 +51,6 @@ pub struct ConfigClient {
|
||||
}
|
||||
|
||||
impl ConfigClient {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiate a new `ConfigClient` with provided path
|
||||
pub fn new(config_path: &Path, ssh_key_dir: &Path) -> Result<Self, SerializerError> {
|
||||
// Initialize a default configuration
|
||||
@@ -104,8 +100,6 @@ impl ConfigClient {
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
/// ### degraded
|
||||
///
|
||||
/// Instantiate a ConfigClient in degraded mode.
|
||||
/// When in degraded mode, the configuration in use will be the default configuration
|
||||
/// and the IO operation on configuration won't be available
|
||||
@@ -120,15 +114,11 @@ impl ConfigClient {
|
||||
|
||||
// Text editor
|
||||
|
||||
/// ### get_text_editor
|
||||
///
|
||||
/// Get text editor from configuration
|
||||
pub fn get_text_editor(&self) -> PathBuf {
|
||||
self.config.user_interface.text_editor.clone()
|
||||
}
|
||||
|
||||
/// ### set_text_editor
|
||||
///
|
||||
/// Set text editor path
|
||||
pub fn set_text_editor(&mut self, path: PathBuf) {
|
||||
self.config.user_interface.text_editor = path;
|
||||
@@ -136,8 +126,6 @@ impl ConfigClient {
|
||||
|
||||
// Default protocol
|
||||
|
||||
/// ### get_default_protocol
|
||||
///
|
||||
/// Get default protocol from configuration
|
||||
pub fn get_default_protocol(&self) -> FileTransferProtocol {
|
||||
match FileTransferProtocol::from_str(self.config.user_interface.default_protocol.as_str()) {
|
||||
@@ -146,43 +134,31 @@ impl ConfigClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### set_default_protocol
|
||||
///
|
||||
/// Set default protocol to configuration
|
||||
pub fn set_default_protocol(&mut self, proto: FileTransferProtocol) {
|
||||
self.config.user_interface.default_protocol = proto.to_string();
|
||||
}
|
||||
|
||||
/// ### get_show_hidden_files
|
||||
///
|
||||
/// Get value of `show_hidden_files`
|
||||
pub fn get_show_hidden_files(&self) -> bool {
|
||||
self.config.user_interface.show_hidden_files
|
||||
}
|
||||
|
||||
/// ### set_show_hidden_files
|
||||
///
|
||||
/// Set new value for `show_hidden_files`
|
||||
pub fn set_show_hidden_files(&mut self, value: bool) {
|
||||
self.config.user_interface.show_hidden_files = value;
|
||||
}
|
||||
|
||||
/// ### get_check_for_updates
|
||||
///
|
||||
/// Get value of `check_for_updates`
|
||||
pub fn get_check_for_updates(&self) -> bool {
|
||||
self.config.user_interface.check_for_updates.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// ### set_check_for_updates
|
||||
///
|
||||
/// Set new value for `check_for_updates`
|
||||
pub fn set_check_for_updates(&mut self, value: bool) {
|
||||
self.config.user_interface.check_for_updates = Some(value);
|
||||
}
|
||||
|
||||
/// ### get_prompt_on_file_replace
|
||||
///
|
||||
/// Get value of `prompt_on_file_replace`
|
||||
pub fn get_prompt_on_file_replace(&self) -> bool {
|
||||
self.config
|
||||
@@ -191,15 +167,11 @@ impl ConfigClient {
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// ### set_prompt_on_file_replace
|
||||
///
|
||||
/// Set new value for `prompt_on_file_replace`
|
||||
pub fn set_prompt_on_file_replace(&mut self, value: bool) {
|
||||
self.config.user_interface.prompt_on_file_replace = Some(value);
|
||||
}
|
||||
|
||||
/// ### get_group_dirs
|
||||
///
|
||||
/// Get GroupDirs value from configuration (will be converted from string)
|
||||
pub fn get_group_dirs(&self) -> Option<GroupDirs> {
|
||||
// Convert string to `GroupDirs`
|
||||
@@ -212,23 +184,17 @@ impl ConfigClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### set_group_dirs
|
||||
///
|
||||
/// Set value for group_dir in configuration.
|
||||
/// Provided value, if `Some` will be converted to `GroupDirs`
|
||||
pub fn set_group_dirs(&mut self, val: Option<GroupDirs>) {
|
||||
self.config.user_interface.group_dirs = val.map(|val| val.to_string());
|
||||
}
|
||||
|
||||
/// ### get_local_file_fmt
|
||||
///
|
||||
/// Get current file fmt for local host
|
||||
pub fn get_local_file_fmt(&self) -> Option<String> {
|
||||
self.config.user_interface.file_fmt.clone()
|
||||
}
|
||||
|
||||
/// ### set_local_file_fmt
|
||||
///
|
||||
/// Set file fmt parameter for local host
|
||||
pub fn set_local_file_fmt(&mut self, s: String) {
|
||||
self.config.user_interface.file_fmt = match s.is_empty() {
|
||||
@@ -237,15 +203,11 @@ impl ConfigClient {
|
||||
};
|
||||
}
|
||||
|
||||
/// ### get_remote_file_fmt
|
||||
///
|
||||
/// Get current file fmt for remote host
|
||||
pub fn get_remote_file_fmt(&self) -> Option<String> {
|
||||
self.config.user_interface.remote_file_fmt.clone()
|
||||
}
|
||||
|
||||
/// ### set_remote_file_fmt
|
||||
///
|
||||
/// Set file fmt parameter for remote host
|
||||
pub fn set_remote_file_fmt(&mut self, s: String) {
|
||||
self.config.user_interface.remote_file_fmt = match s.is_empty() {
|
||||
@@ -254,22 +216,16 @@ impl ConfigClient {
|
||||
};
|
||||
}
|
||||
|
||||
/// ### get_notifications
|
||||
///
|
||||
/// Get value of `notifications`
|
||||
pub fn get_notifications(&self) -> bool {
|
||||
self.config.user_interface.notifications.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// ### set_notifications
|
||||
///
|
||||
/// Set new value for `notifications`
|
||||
pub fn set_notifications(&mut self, value: bool) {
|
||||
self.config.user_interface.notifications = Some(value);
|
||||
}
|
||||
|
||||
/// ### get_notification_threshold
|
||||
///
|
||||
/// Get value of `notification_threshold`
|
||||
pub fn get_notification_threshold(&self) -> u64 {
|
||||
self.config
|
||||
@@ -278,8 +234,6 @@ impl ConfigClient {
|
||||
.unwrap_or(DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD)
|
||||
}
|
||||
|
||||
/// ### set_notification_threshold
|
||||
///
|
||||
/// Set new value for `notification_threshold`
|
||||
pub fn set_notification_threshold(&mut self, value: u64) {
|
||||
self.config.user_interface.notification_threshold = Some(value);
|
||||
@@ -287,8 +241,6 @@ impl ConfigClient {
|
||||
|
||||
// SSH Keys
|
||||
|
||||
/// ### save_ssh_key
|
||||
///
|
||||
/// Save a SSH key into configuration.
|
||||
/// This operation also creates the key file in `ssh_key_dir`
|
||||
/// and also commits changes to configuration, to prevent incoerent data
|
||||
@@ -331,8 +283,6 @@ impl ConfigClient {
|
||||
self.write_config()
|
||||
}
|
||||
|
||||
/// ### del_ssh_key
|
||||
///
|
||||
/// Delete a ssh key from configuration, using host as key.
|
||||
/// This operation also unlinks the key file in `ssh_key_dir`
|
||||
/// and also commits changes to configuration, to prevent incoerent data
|
||||
@@ -363,8 +313,6 @@ impl ConfigClient {
|
||||
self.write_config()
|
||||
}
|
||||
|
||||
/// ### get_ssh_key
|
||||
///
|
||||
/// Get ssh key from host.
|
||||
/// None is returned if key doesn't exist
|
||||
/// `std::io::Error` is returned in case it was not possible to read the key file
|
||||
@@ -384,8 +332,6 @@ impl ConfigClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### iter_ssh_keys
|
||||
///
|
||||
/// Get an iterator through hosts in the ssh key storage
|
||||
pub fn iter_ssh_keys(&self) -> impl Iterator<Item = &String> + '_ {
|
||||
Box::new(self.config.remote.ssh_keys.keys())
|
||||
@@ -393,8 +339,6 @@ impl ConfigClient {
|
||||
|
||||
// I/O
|
||||
|
||||
/// ### write_config
|
||||
///
|
||||
/// Write configuration to file
|
||||
pub fn write_config(&self) -> Result<(), SerializerError> {
|
||||
if self.degraded {
|
||||
@@ -421,8 +365,6 @@ impl ConfigClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### read_config
|
||||
///
|
||||
/// Read configuration from file (or reload it if already read)
|
||||
pub fn read_config(&mut self) -> Result<(), SerializerError> {
|
||||
if self.degraded {
|
||||
@@ -456,16 +398,12 @@ impl ConfigClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### make_ssh_host_key
|
||||
///
|
||||
/// Hosts are saved as `username@host` into configuration.
|
||||
/// This method creates the key name, starting from host and username
|
||||
fn make_ssh_host_key(host: &str, username: &str) -> String {
|
||||
format!("{}@{}", username, host)
|
||||
}
|
||||
|
||||
/// ### get_ssh_tokens
|
||||
///
|
||||
/// Get ssh tokens starting from ssh host key
|
||||
/// Panics if key has invalid syntax
|
||||
/// Returns: (host, username)
|
||||
@@ -475,8 +413,6 @@ impl ConfigClient {
|
||||
(String::from(tokens[1]), String::from(tokens[0]))
|
||||
}
|
||||
|
||||
/// ### make_io_err
|
||||
///
|
||||
/// Make serializer error from `std::io::Error`
|
||||
fn make_io_err(err: std::io::Error) -> Result<(), SerializerError> {
|
||||
Err(SerializerError::new_ex(
|
||||
@@ -774,8 +710,6 @@ mod tests {
|
||||
assert_eq!(err.to_string(), "IO error (permission denied)");
|
||||
}
|
||||
|
||||
/// ### get_paths
|
||||
///
|
||||
/// Get paths for configuration and keys directory
|
||||
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
|
||||
let mut k: PathBuf = PathBuf::from(dir);
|
||||
|
||||
@@ -32,16 +32,12 @@ use std::fs::{OpenOptions, Permissions};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// ## FileStorage
|
||||
///
|
||||
/// File storage is an implementation o the `KeyStorage` which uses a file to store the key
|
||||
pub struct FileStorage {
|
||||
dir_path: PathBuf,
|
||||
}
|
||||
|
||||
impl FileStorage {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new `FileStorage`
|
||||
pub fn new(dir_path: &Path) -> Self {
|
||||
FileStorage {
|
||||
@@ -49,8 +45,6 @@ impl FileStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### make_file_path
|
||||
///
|
||||
/// Make file path for key file from `dir_path` and the application id
|
||||
fn make_file_path(&self, storage_id: &str) -> PathBuf {
|
||||
let mut p: PathBuf = self.dir_path.clone();
|
||||
@@ -61,8 +55,6 @@ impl FileStorage {
|
||||
}
|
||||
|
||||
impl KeyStorage for FileStorage {
|
||||
/// ### get_key
|
||||
///
|
||||
/// Retrieve key from the key storage.
|
||||
/// The key might be acccess through an identifier, which identifies
|
||||
/// the key in the storage
|
||||
@@ -85,8 +77,6 @@ impl KeyStorage for FileStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### set_key
|
||||
///
|
||||
/// Set the key into the key storage
|
||||
fn set_key(&self, storage_id: &str, key: &str) -> Result<(), KeyStorageError> {
|
||||
let key_file: PathBuf = self.make_file_path(storage_id);
|
||||
|
||||
@@ -30,16 +30,12 @@ use super::{KeyStorage, KeyStorageError};
|
||||
// Ext
|
||||
use keyring::{Keyring, KeyringError};
|
||||
|
||||
/// ## KeyringStorage
|
||||
///
|
||||
/// provides a `KeyStorage` implementation using the keyring crate
|
||||
pub struct KeyringStorage {
|
||||
username: String,
|
||||
}
|
||||
|
||||
impl KeyringStorage {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new KeyringStorage
|
||||
pub fn new(username: &str) -> Self {
|
||||
KeyringStorage {
|
||||
@@ -49,8 +45,6 @@ impl KeyringStorage {
|
||||
}
|
||||
|
||||
impl KeyStorage for KeyringStorage {
|
||||
/// ### get_key
|
||||
///
|
||||
/// Retrieve key from the key storage.
|
||||
/// The key might be acccess through an identifier, which identifies
|
||||
/// the key in the storage
|
||||
@@ -72,8 +66,6 @@ impl KeyStorage for KeyringStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### set_key
|
||||
///
|
||||
/// Set the key into the key storage
|
||||
fn set_key(&self, storage_id: &str, key: &str) -> Result<(), KeyStorageError> {
|
||||
let storage: Keyring = Keyring::new(storage_id, self.username.as_str());
|
||||
|
||||
@@ -32,8 +32,6 @@ pub mod keyringstorage;
|
||||
// ext
|
||||
use thiserror::Error;
|
||||
|
||||
/// ## KeyStorageError
|
||||
///
|
||||
/// defines the error type for the `KeyStorage`
|
||||
#[derive(Debug, Error, PartialEq)]
|
||||
pub enum KeyStorageError {
|
||||
@@ -46,19 +44,13 @@ pub enum KeyStorageError {
|
||||
NoSuchKey,
|
||||
}
|
||||
|
||||
/// ## KeyStorage
|
||||
///
|
||||
/// this traits provides the methods to communicate and interact with the key storage.
|
||||
pub trait KeyStorage {
|
||||
/// ### get_key
|
||||
///
|
||||
/// Retrieve key from the key storage.
|
||||
/// The key might be acccess through an identifier, which identifies
|
||||
/// the key in the storage
|
||||
fn get_key(&self, storage_id: &str) -> Result<String, KeyStorageError>;
|
||||
|
||||
/// ### set_key
|
||||
///
|
||||
/// Set the key into the key storage
|
||||
fn set_key(&self, storage_id: &str, key: &str) -> Result<(), KeyStorageError>;
|
||||
|
||||
|
||||
@@ -6,14 +6,10 @@
|
||||
use notify_rust::Hint;
|
||||
use notify_rust::{Notification as OsNotification, Timeout};
|
||||
|
||||
/// ## Notification
|
||||
///
|
||||
/// A notification helper which provides all the functions to send the available notifications for termscp
|
||||
pub struct Notification;
|
||||
|
||||
impl Notification {
|
||||
/// ### transfer_completed
|
||||
///
|
||||
/// Notify a transfer has been completed with success
|
||||
pub fn transfer_completed<S: AsRef<str>>(body: S) {
|
||||
Self::notify(
|
||||
@@ -23,15 +19,11 @@ impl Notification {
|
||||
);
|
||||
}
|
||||
|
||||
/// ### transfer_error
|
||||
///
|
||||
/// Notify a transfer has failed
|
||||
pub fn transfer_error<S: AsRef<str>>(body: S) {
|
||||
Self::notify("Transfer failed ❌", body.as_ref(), Some("transfer.error"));
|
||||
}
|
||||
|
||||
/// ### update_available
|
||||
///
|
||||
/// Notify a new version of termscp is available for download
|
||||
pub fn update_available<S: AsRef<str>>(version: S) {
|
||||
Self::notify(
|
||||
@@ -41,8 +33,6 @@ impl Notification {
|
||||
);
|
||||
}
|
||||
|
||||
/// ### update_installed
|
||||
///
|
||||
/// Notify the update has been correctly installed
|
||||
pub fn update_installed<S: AsRef<str>>(version: S) {
|
||||
Self::notify(
|
||||
@@ -52,15 +42,11 @@ impl Notification {
|
||||
);
|
||||
}
|
||||
|
||||
/// ### update_failed
|
||||
///
|
||||
/// Notify the update installation has failed
|
||||
pub fn update_failed<S: AsRef<str>>(err: S) {
|
||||
Self::notify("Update installation failed ❌", err.as_ref(), None);
|
||||
}
|
||||
|
||||
/// ### notify
|
||||
///
|
||||
/// Notify guest OS with provided Summary, body and optional category
|
||||
/// e.g. Category is supported on FreeBSD/Linux only
|
||||
#[allow(unused_variables)]
|
||||
|
||||
@@ -37,8 +37,6 @@ pub struct SshKeyStorage {
|
||||
}
|
||||
|
||||
impl SshKeyStorage {
|
||||
/// ### storage_from_config
|
||||
///
|
||||
/// Create a `SshKeyStorage` starting from a `ConfigClient`
|
||||
pub fn storage_from_config(cfg_client: &ConfigClient) -> Self {
|
||||
let mut hosts: HashMap<String, PathBuf> =
|
||||
@@ -65,8 +63,6 @@ impl SshKeyStorage {
|
||||
SshKeyStorage { hosts }
|
||||
}
|
||||
|
||||
/// ### empty
|
||||
///
|
||||
/// Create an empty ssh key storage; used in case `ConfigClient` is not available
|
||||
#[cfg(test)]
|
||||
pub fn empty() -> Self {
|
||||
@@ -75,16 +71,12 @@ impl SshKeyStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### make_mapkey
|
||||
///
|
||||
/// Make mapkey from host and username
|
||||
fn make_mapkey(host: &str, username: &str) -> String {
|
||||
format!("{}@{}", username, host)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// ### add_key
|
||||
///
|
||||
/// Add a key to storage
|
||||
/// NOTE: available only for tests
|
||||
pub fn add_key(&mut self, host: &str, username: &str, p: PathBuf) {
|
||||
@@ -149,8 +141,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// ### get_paths
|
||||
///
|
||||
/// Get paths for configuration and keys directory
|
||||
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
|
||||
let mut k: PathBuf = PathBuf::from(dir);
|
||||
|
||||
@@ -35,8 +35,6 @@ use std::fs::OpenOptions;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::string::ToString;
|
||||
|
||||
/// ## ThemeProvider
|
||||
///
|
||||
/// ThemeProvider provides a high level API to communicate with the termscp theme
|
||||
pub struct ThemeProvider {
|
||||
theme: Theme, // Theme loaded
|
||||
@@ -45,8 +43,6 @@ pub struct ThemeProvider {
|
||||
}
|
||||
|
||||
impl ThemeProvider {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new `ThemeProvider`
|
||||
pub fn new(theme_path: &Path) -> Result<Self, SerializerError> {
|
||||
let default_theme: Theme = Theme::default();
|
||||
@@ -78,8 +74,6 @@ impl ThemeProvider {
|
||||
Ok(provider)
|
||||
}
|
||||
|
||||
/// ### degraded
|
||||
///
|
||||
/// Create a new theme provider which won't work with file system.
|
||||
/// This is done in order to prevent a lot of `unwrap_or` on Ui
|
||||
pub fn degraded() -> Self {
|
||||
@@ -92,15 +86,11 @@ impl ThemeProvider {
|
||||
|
||||
// -- getters
|
||||
|
||||
/// ### theme
|
||||
///
|
||||
/// Returns theme as reference
|
||||
pub fn theme(&self) -> &Theme {
|
||||
&self.theme
|
||||
}
|
||||
|
||||
/// ### theme_mut
|
||||
///
|
||||
/// Returns a mutable reference to the theme
|
||||
pub fn theme_mut(&mut self) -> &mut Theme {
|
||||
&mut self.theme
|
||||
@@ -108,8 +98,6 @@ impl ThemeProvider {
|
||||
|
||||
// -- io
|
||||
|
||||
/// ### load
|
||||
///
|
||||
/// Load theme from file
|
||||
pub fn load(&mut self) -> Result<(), SerializerError> {
|
||||
if self.degraded {
|
||||
@@ -146,8 +134,6 @@ impl ThemeProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### save
|
||||
///
|
||||
/// Save theme to file
|
||||
pub fn save(&self) -> Result<(), SerializerError> {
|
||||
if self.degraded {
|
||||
@@ -235,8 +221,6 @@ mod test {
|
||||
assert!(ThemeProvider::new(Path::new("/tmp/oifoif/omar")).is_err());
|
||||
}
|
||||
|
||||
/// ### get_theme_path
|
||||
///
|
||||
/// Get paths for theme file
|
||||
fn get_theme_path(dir: &Path) -> PathBuf {
|
||||
let mut p: PathBuf = PathBuf::from(dir);
|
||||
|
||||
@@ -35,8 +35,6 @@ use crate::system::environment;
|
||||
use std::path::PathBuf;
|
||||
|
||||
impl AuthActivity {
|
||||
/// ### del_bookmark
|
||||
///
|
||||
/// Delete bookmark
|
||||
pub(super) fn del_bookmark(&mut self, idx: usize) {
|
||||
if let Some(bookmarks_cli) = self.bookmarks_client.as_mut() {
|
||||
@@ -52,8 +50,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### load_bookmark
|
||||
///
|
||||
/// Load selected bookmark (at index) to input fields
|
||||
pub(super) fn load_bookmark(&mut self, idx: usize) {
|
||||
if let Some(bookmarks_cli) = self.bookmarks_client.as_ref() {
|
||||
@@ -67,8 +63,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### save_bookmark
|
||||
///
|
||||
/// Save current input fields as a bookmark
|
||||
pub(super) fn save_bookmark(&mut self, name: String, save_password: bool) {
|
||||
let params = match self.collect_host_params() {
|
||||
@@ -89,8 +83,6 @@ impl AuthActivity {
|
||||
self.sort_bookmarks();
|
||||
}
|
||||
}
|
||||
/// ### del_recent
|
||||
///
|
||||
/// Delete recent
|
||||
pub(super) fn del_recent(&mut self, idx: usize) {
|
||||
if let Some(client) = self.bookmarks_client.as_mut() {
|
||||
@@ -105,8 +97,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### load_recent
|
||||
///
|
||||
/// Load selected recent (at index) to input fields
|
||||
pub(super) fn load_recent(&mut self, idx: usize) {
|
||||
if let Some(client) = self.bookmarks_client.as_ref() {
|
||||
@@ -120,8 +110,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### save_recent
|
||||
///
|
||||
/// Save current input fields as a "recent"
|
||||
pub(super) fn save_recent(&mut self) {
|
||||
let params = match self.collect_host_params() {
|
||||
@@ -138,8 +126,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### write_bookmarks
|
||||
///
|
||||
/// Write bookmarks to file
|
||||
fn write_bookmarks(&mut self) {
|
||||
if let Some(bookmarks_cli) = self.bookmarks_client.as_ref() {
|
||||
@@ -149,8 +135,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### init_bookmarks_client
|
||||
///
|
||||
/// Initialize bookmarks client
|
||||
pub(super) fn init_bookmarks_client(&mut self) {
|
||||
// Get config dir
|
||||
@@ -210,8 +194,6 @@ impl AuthActivity {
|
||||
|
||||
// -- privates
|
||||
|
||||
/// ### sort_bookmarks
|
||||
///
|
||||
/// Sort bookmarks in list
|
||||
fn sort_bookmarks(&mut self) {
|
||||
// Conver to lowercase when sorting
|
||||
@@ -219,16 +201,12 @@ impl AuthActivity {
|
||||
.sort_by(|a, b| a.to_lowercase().as_str().cmp(b.to_lowercase().as_str()));
|
||||
}
|
||||
|
||||
/// ### sort_recents
|
||||
///
|
||||
/// Sort recents in list
|
||||
fn sort_recents(&mut self) {
|
||||
// Reverse order
|
||||
self.recents_list.sort_by(|a, b| b.cmp(a));
|
||||
}
|
||||
|
||||
/// ### load_bookmark_into_gui
|
||||
///
|
||||
/// Load bookmark data into the gui components
|
||||
fn load_bookmark_into_gui(&mut self, bookmark: FileTransferParams) {
|
||||
// Load parameters into components
|
||||
|
||||
@@ -57,8 +57,6 @@ impl ProtocolRadio {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### protocol_opt_to_enum
|
||||
///
|
||||
/// Convert radio index for protocol into a `FileTransferProtocol`
|
||||
fn protocol_opt_to_enum(protocol: usize) -> FileTransferProtocol {
|
||||
match protocol {
|
||||
@@ -70,8 +68,6 @@ impl ProtocolRadio {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### protocol_enum_to_opt
|
||||
///
|
||||
/// Convert `FileTransferProtocol` enum into radio group index
|
||||
fn protocol_enum_to_opt(protocol: FileTransferProtocol) -> usize {
|
||||
match protocol {
|
||||
|
||||
@@ -31,8 +31,6 @@ use crate::system::auto_update::{Release, Update, UpdateStatus};
|
||||
use crate::system::notifications::Notification;
|
||||
|
||||
impl AuthActivity {
|
||||
/// ### get_default_port_for_protocol
|
||||
///
|
||||
/// Get the default port for protocol
|
||||
pub(super) fn get_default_port_for_protocol(protocol: FileTransferProtocol) -> u16 {
|
||||
match protocol {
|
||||
@@ -42,15 +40,11 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### is_port_standard
|
||||
///
|
||||
/// Returns whether the port is standard or not
|
||||
pub(super) fn is_port_standard(port: u16) -> bool {
|
||||
port < 1024
|
||||
}
|
||||
|
||||
/// ### check_minimum_window_size
|
||||
///
|
||||
/// Check minimum window size window
|
||||
pub(super) fn check_minimum_window_size(&mut self, height: u16) {
|
||||
if height < 25 {
|
||||
@@ -61,8 +55,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### collect_host_params
|
||||
///
|
||||
/// Collect host params as `FileTransferParams`
|
||||
pub(super) fn collect_host_params(&self) -> Result<FileTransferParams, &'static str> {
|
||||
match self.protocol {
|
||||
@@ -71,8 +63,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### collect_generic_host_params
|
||||
///
|
||||
/// Get input values from fields or return an error if fields are invalid to work as generic
|
||||
pub(super) fn collect_generic_host_params(
|
||||
&self,
|
||||
@@ -105,8 +95,6 @@ impl AuthActivity {
|
||||
})
|
||||
}
|
||||
|
||||
/// ### collect_s3_host_params
|
||||
///
|
||||
/// Get input values from fields or return an error if fields are invalid to work as aws s3
|
||||
pub(super) fn collect_s3_host_params(&self) -> Result<FileTransferParams, &'static str> {
|
||||
let (bucket, region, profile): (String, String, Option<String>) =
|
||||
@@ -126,8 +114,6 @@ impl AuthActivity {
|
||||
|
||||
// -- update install
|
||||
|
||||
/// ### check_for_updates
|
||||
///
|
||||
/// If enabled in configuration, check for updates from Github
|
||||
pub(super) fn check_for_updates(&mut self) {
|
||||
debug!("Check for updates...");
|
||||
@@ -171,8 +157,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### install_update
|
||||
///
|
||||
/// Install latest termscp version via GUI
|
||||
pub(super) fn install_update(&mut self) {
|
||||
// Umount release notes
|
||||
|
||||
@@ -127,8 +127,6 @@ pub enum Msg {
|
||||
None,
|
||||
}
|
||||
|
||||
/// ## InputMask
|
||||
///
|
||||
/// Auth form input mask
|
||||
#[derive(Eq, PartialEq)]
|
||||
enum InputMask {
|
||||
@@ -160,8 +158,6 @@ pub struct AuthActivity {
|
||||
}
|
||||
|
||||
impl AuthActivity {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new AuthActivity
|
||||
pub fn new(ticks: Duration) -> AuthActivity {
|
||||
AuthActivity {
|
||||
@@ -180,36 +176,26 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### context
|
||||
///
|
||||
/// Returns a reference to context
|
||||
fn context(&self) -> &Context {
|
||||
self.context.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// ### context_mut
|
||||
///
|
||||
/// Returns a mutable reference to context
|
||||
fn context_mut(&mut self) -> &mut Context {
|
||||
self.context.as_mut().unwrap()
|
||||
}
|
||||
|
||||
/// ### config
|
||||
///
|
||||
/// Returns config client reference
|
||||
fn config(&self) -> &ConfigClient {
|
||||
self.context().config()
|
||||
}
|
||||
|
||||
/// ### theme
|
||||
///
|
||||
/// Returns a reference to theme
|
||||
fn theme(&self) -> &Theme {
|
||||
self.context().theme_provider().theme()
|
||||
}
|
||||
|
||||
/// ### input_mask
|
||||
///
|
||||
/// Get current input mask to show
|
||||
fn input_mask(&self) -> InputMask {
|
||||
match self.protocol {
|
||||
@@ -222,8 +208,6 @@ impl AuthActivity {
|
||||
}
|
||||
|
||||
impl Activity for AuthActivity {
|
||||
/// ### on_create
|
||||
///
|
||||
/// `on_create` is the function which must be called to initialize the activity.
|
||||
/// `on_create` must initialize all the data structures used by the activity
|
||||
/// Context is taken from activity manager and will be released only when activity is destroyed
|
||||
@@ -259,8 +243,6 @@ impl Activity for AuthActivity {
|
||||
info!("Activity initialized");
|
||||
}
|
||||
|
||||
/// ### on_draw
|
||||
///
|
||||
/// `on_draw` is the function which draws the graphical interface.
|
||||
/// This function must be called at each tick to refresh the interface
|
||||
fn on_draw(&mut self) {
|
||||
@@ -288,8 +270,6 @@ impl Activity for AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### will_umount
|
||||
///
|
||||
/// `will_umount` is the method which must be able to report to the activity manager, whether
|
||||
/// the activity should be terminated or not.
|
||||
/// If not, the call will return `None`, otherwise return`Some(ExitReason)`
|
||||
@@ -297,8 +277,6 @@ impl Activity for AuthActivity {
|
||||
self.exit_reason.as_ref()
|
||||
}
|
||||
|
||||
/// ### on_destroy
|
||||
///
|
||||
/// `on_destroy` is the function which cleans up runtime variables and data before terminating the activity.
|
||||
/// This function must be called once before terminating the activity.
|
||||
/// This function finally releases the context
|
||||
|
||||
@@ -37,8 +37,6 @@ use tuirealm::tui::widgets::Clear;
|
||||
use tuirealm::{State, StateValue, Sub, SubClause, SubEventClause};
|
||||
|
||||
impl AuthActivity {
|
||||
/// ### init
|
||||
///
|
||||
/// Initialize view, mounting all startup components inside the view
|
||||
pub(super) fn init(&mut self) {
|
||||
let key_color = self.theme().misc_keys;
|
||||
@@ -104,8 +102,6 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::Protocol).is_ok());
|
||||
}
|
||||
|
||||
/// ### view
|
||||
///
|
||||
/// Display view on canvas
|
||||
pub(super) fn view(&mut self) {
|
||||
self.redraw = false;
|
||||
@@ -276,8 +272,6 @@ impl AuthActivity {
|
||||
|
||||
// -- partials
|
||||
|
||||
/// ### view_bookmarks
|
||||
///
|
||||
/// Make text span from bookmarks
|
||||
pub(super) fn view_bookmarks(&mut self) {
|
||||
let bookmarks: Vec<String> = self
|
||||
@@ -305,8 +299,6 @@ impl AuthActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### view_recent_connections
|
||||
///
|
||||
/// View recent connections
|
||||
pub(super) fn view_recent_connections(&mut self) {
|
||||
let bookmarks: Vec<String> = self
|
||||
@@ -335,8 +327,6 @@ impl AuthActivity {
|
||||
|
||||
// -- mount
|
||||
|
||||
/// ### mount_error
|
||||
///
|
||||
/// Mount error box
|
||||
pub(super) fn mount_error<S: AsRef<str>>(&mut self, text: S) {
|
||||
let err_color = self.theme().misc_error_dialog;
|
||||
@@ -351,15 +341,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::ErrorPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_error
|
||||
///
|
||||
/// Umount error message
|
||||
pub(super) fn umount_error(&mut self) {
|
||||
let _ = self.app.umount(&Id::ErrorPopup);
|
||||
}
|
||||
|
||||
/// ### mount_info
|
||||
///
|
||||
/// Mount info box
|
||||
pub(super) fn mount_info<S: AsRef<str>>(&mut self, text: S) {
|
||||
let color = self.theme().misc_info_dialog;
|
||||
@@ -374,15 +360,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::InfoPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_info
|
||||
///
|
||||
/// Umount info message
|
||||
pub(super) fn umount_info(&mut self) {
|
||||
let _ = self.app.umount(&Id::InfoPopup);
|
||||
}
|
||||
|
||||
/// ### mount_error
|
||||
///
|
||||
/// Mount wait box
|
||||
pub(super) fn mount_wait(&mut self, text: &str) {
|
||||
let wait_color = self.theme().misc_info_dialog;
|
||||
@@ -397,15 +379,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::WaitPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_wait
|
||||
///
|
||||
/// Umount wait message
|
||||
pub(super) fn umount_wait(&mut self) {
|
||||
let _ = self.app.umount(&Id::WaitPopup);
|
||||
}
|
||||
|
||||
/// ### mount_size_err
|
||||
///
|
||||
/// Mount size error
|
||||
pub(super) fn mount_size_err(&mut self) {
|
||||
// Mount
|
||||
@@ -421,15 +399,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::WindowSizeError).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_size_err
|
||||
///
|
||||
/// Umount error size error
|
||||
pub(super) fn umount_size_err(&mut self) {
|
||||
let _ = self.app.umount(&Id::WindowSizeError);
|
||||
}
|
||||
|
||||
/// ### mount_quit
|
||||
///
|
||||
/// Mount quit popup
|
||||
pub(super) fn mount_quit(&mut self) {
|
||||
// Protocol
|
||||
@@ -445,15 +419,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::QuitPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_quit
|
||||
///
|
||||
/// Umount quit popup
|
||||
pub(super) fn umount_quit(&mut self) {
|
||||
let _ = self.app.umount(&Id::QuitPopup);
|
||||
}
|
||||
|
||||
/// ### mount_bookmark_del_dialog
|
||||
///
|
||||
/// Mount bookmark delete dialog
|
||||
pub(super) fn mount_bookmark_del_dialog(&mut self) {
|
||||
let warn_color = self.theme().misc_warn_dialog;
|
||||
@@ -468,15 +438,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::DeleteBookmarkPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_bookmark_del_dialog
|
||||
///
|
||||
/// umount delete bookmark dialog
|
||||
pub(super) fn umount_bookmark_del_dialog(&mut self) {
|
||||
let _ = self.app.umount(&Id::DeleteBookmarkPopup);
|
||||
}
|
||||
|
||||
/// ### mount_bookmark_del_dialog
|
||||
///
|
||||
/// Mount recent delete dialog
|
||||
pub(super) fn mount_recent_del_dialog(&mut self) {
|
||||
let warn_color = self.theme().misc_warn_dialog;
|
||||
@@ -491,15 +457,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::DeleteRecentPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_recent_del_dialog
|
||||
///
|
||||
/// umount delete recent dialog
|
||||
pub(super) fn umount_recent_del_dialog(&mut self) {
|
||||
let _ = self.app.umount(&Id::DeleteRecentPopup);
|
||||
}
|
||||
|
||||
/// ### mount_bookmark_save_dialog
|
||||
///
|
||||
/// Mount bookmark save dialog
|
||||
pub(super) fn mount_bookmark_save_dialog(&mut self) {
|
||||
let save_color = self.theme().misc_save_dialog;
|
||||
@@ -524,16 +486,12 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::BookmarkName).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_bookmark_save_dialog
|
||||
///
|
||||
/// Umount bookmark save dialog
|
||||
pub(super) fn umount_bookmark_save_dialog(&mut self) {
|
||||
let _ = self.app.umount(&Id::BookmarkName);
|
||||
let _ = self.app.umount(&Id::BookmarkSavePassword);
|
||||
}
|
||||
|
||||
/// ### mount_keybindings
|
||||
///
|
||||
/// Mount keybindings
|
||||
pub(super) fn mount_keybindings(&mut self) {
|
||||
let key_color = self.theme().misc_keys;
|
||||
@@ -549,15 +507,11 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::Keybindings).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_help
|
||||
///
|
||||
/// Umount help
|
||||
pub(super) fn umount_help(&mut self) {
|
||||
let _ = self.app.umount(&Id::Keybindings);
|
||||
}
|
||||
|
||||
/// ### mount_release_notes
|
||||
///
|
||||
/// mount release notes text area
|
||||
pub(super) fn mount_release_notes(&mut self) {
|
||||
if let Some(ctx) = self.context.as_ref() {
|
||||
@@ -585,8 +539,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### umount_release_notes
|
||||
///
|
||||
/// Umount release notes text area
|
||||
pub(super) fn umount_release_notes(&mut self) {
|
||||
let _ = self.app.umount(&Id::NewVersionChangelog);
|
||||
@@ -691,8 +643,6 @@ impl AuthActivity {
|
||||
|
||||
// -- query
|
||||
|
||||
/// ### get_generic_params
|
||||
///
|
||||
/// Collect input values from view
|
||||
pub(super) fn get_generic_params_input(&self) -> (String, u16, String, String) {
|
||||
let addr: String = self.get_input_addr();
|
||||
@@ -702,8 +652,6 @@ impl AuthActivity {
|
||||
(addr, port, username, password)
|
||||
}
|
||||
|
||||
/// ### get_s3_params_input
|
||||
///
|
||||
/// Collect s3 input values from view
|
||||
pub(super) fn get_s3_params_input(&self) -> (String, String, Option<String>) {
|
||||
let bucket: String = self.get_input_s3_bucket();
|
||||
@@ -764,8 +712,6 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_new_bookmark
|
||||
///
|
||||
/// Get new bookmark params
|
||||
pub(super) fn get_new_bookmark(&self) -> (String, bool) {
|
||||
let name = match self.app.state(&Id::BookmarkName) {
|
||||
@@ -784,8 +730,6 @@ impl AuthActivity {
|
||||
|
||||
// -- len
|
||||
|
||||
/// ### input_mask_size
|
||||
///
|
||||
/// Returns the input mask size based on current input mask
|
||||
pub(super) fn input_mask_size(&self) -> u16 {
|
||||
match self.input_mask() {
|
||||
@@ -796,16 +740,12 @@ impl AuthActivity {
|
||||
|
||||
// -- fmt
|
||||
|
||||
/// ### fmt_bookmark
|
||||
///
|
||||
/// Format bookmark to display on ui
|
||||
fn fmt_bookmark(name: &str, b: FileTransferParams) -> String {
|
||||
let addr: String = Self::fmt_recent(b);
|
||||
format!("{} ({})", name, addr)
|
||||
}
|
||||
|
||||
/// ### fmt_recent
|
||||
///
|
||||
/// Format recent connection to display on ui
|
||||
fn fmt_recent(b: FileTransferParams) -> String {
|
||||
let protocol: String = b.protocol.to_string().to_lowercase();
|
||||
@@ -881,8 +821,6 @@ impl AuthActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### no_popup_mounted_clause
|
||||
///
|
||||
/// Returns a sub clause which requires that no popup is mounted in order to be satisfied
|
||||
fn no_popup_mounted_clause() -> SubClause<Id> {
|
||||
SubClause::And(
|
||||
|
||||
@@ -32,8 +32,6 @@ use remotefs::Directory;
|
||||
use std::path::PathBuf;
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### action_enter_local_dir
|
||||
///
|
||||
/// Enter a directory on local host from entry
|
||||
/// Return true whether the directory changed
|
||||
pub(crate) fn action_enter_local_dir(&mut self, dir: Directory, block_sync: bool) -> bool {
|
||||
@@ -44,8 +42,6 @@ impl FileTransferActivity {
|
||||
true
|
||||
}
|
||||
|
||||
/// ### action_enter_remote_dir
|
||||
///
|
||||
/// Enter a directory on local host from entry
|
||||
/// Return true whether the directory changed
|
||||
pub(crate) fn action_enter_remote_dir(&mut self, dir: Directory, block_sync: bool) -> bool {
|
||||
@@ -56,8 +52,6 @@ impl FileTransferActivity {
|
||||
true
|
||||
}
|
||||
|
||||
/// ### action_change_local_dir
|
||||
///
|
||||
/// Change local directory reading value from input
|
||||
pub(crate) fn action_change_local_dir(&mut self, input: String, block_sync: bool) {
|
||||
let dir_path: PathBuf = self.local_to_abs_path(PathBuf::from(input.as_str()).as_path());
|
||||
@@ -68,8 +62,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_change_remote_dir
|
||||
///
|
||||
/// Change remote directory reading value from input
|
||||
pub(crate) fn action_change_remote_dir(&mut self, input: String, block_sync: bool) {
|
||||
let dir_path: PathBuf = self.remote_to_abs_path(PathBuf::from(input.as_str()).as_path());
|
||||
@@ -80,8 +72,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_go_to_previous_local_dir
|
||||
///
|
||||
/// Go to previous directory from localhost
|
||||
pub(crate) fn action_go_to_previous_local_dir(&mut self, block_sync: bool) {
|
||||
if let Some(d) = self.local_mut().popd() {
|
||||
@@ -93,8 +83,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_go_to_previous_remote_dir
|
||||
///
|
||||
/// Go to previous directory from remote host
|
||||
pub(crate) fn action_go_to_previous_remote_dir(&mut self, block_sync: bool) {
|
||||
if let Some(d) = self.remote_mut().popd() {
|
||||
@@ -106,8 +94,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_go_to_local_upper_dir
|
||||
///
|
||||
/// Go to upper directory on local host
|
||||
pub(crate) fn action_go_to_local_upper_dir(&mut self, block_sync: bool) {
|
||||
// Get pwd
|
||||
|
||||
@@ -32,8 +32,6 @@ use remotefs::{Entry, RemoteErrorType};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### action_local_copy
|
||||
///
|
||||
/// Copy file on local
|
||||
pub(crate) fn action_local_copy(&mut self, input: String) {
|
||||
match self.get_local_selected_entries() {
|
||||
@@ -59,8 +57,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_remote_copy
|
||||
///
|
||||
/// Copy file on remote
|
||||
pub(crate) fn action_remote_copy(&mut self, input: String) {
|
||||
match self.get_remote_selected_entries() {
|
||||
@@ -140,8 +136,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### tricky_copy
|
||||
///
|
||||
/// Tricky copy will be used whenever copy command is not available on remote host
|
||||
pub(super) fn tricky_copy(&mut self, entry: Entry, dest: &Path) -> Result<(), String> {
|
||||
// NOTE: VERY IMPORTANT; wait block must be umounted or something really bad will happen
|
||||
|
||||
@@ -84,8 +84,6 @@ impl FileTransferActivity {
|
||||
self.reload_remote_dir();
|
||||
}
|
||||
|
||||
/// ### edit_local_file
|
||||
///
|
||||
/// Edit a file on localhost
|
||||
fn edit_local_file(&mut self, path: &Path) -> Result<(), String> {
|
||||
// Read first 2048 bytes or less from file to check if it is textual
|
||||
@@ -147,8 +145,6 @@ impl FileTransferActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### edit_remote_file
|
||||
///
|
||||
/// Edit file on remote host
|
||||
fn edit_remote_file(&mut self, file: File) -> Result<(), String> {
|
||||
// Create temp file
|
||||
|
||||
@@ -75,8 +75,6 @@ impl From<Vec<&Entry>> for SelectedEntry {
|
||||
}
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### get_local_selected_entries
|
||||
///
|
||||
/// Get local file entry
|
||||
pub(crate) fn get_local_selected_entries(&self) -> SelectedEntry {
|
||||
match self.get_selected_index(&Id::ExplorerLocal) {
|
||||
@@ -93,8 +91,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_remote_selected_entries
|
||||
///
|
||||
/// Get remote file entry
|
||||
pub(crate) fn get_remote_selected_entries(&self) -> SelectedEntry {
|
||||
match self.get_selected_index(&Id::ExplorerRemote) {
|
||||
@@ -111,8 +107,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_remote_selected_entries
|
||||
///
|
||||
/// Get remote file entry
|
||||
pub(crate) fn get_found_selected_entries(&self) -> SelectedEntry {
|
||||
match self.get_selected_index(&Id::ExplorerFind) {
|
||||
|
||||
@@ -31,8 +31,6 @@ use super::{Entry, FileTransferActivity, LogLevel, SelectedEntry, TransferPayloa
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### action_open_local
|
||||
///
|
||||
/// Open local file
|
||||
pub(crate) fn action_open_local(&mut self) {
|
||||
let entries: Vec<Entry> = match self.get_local_selected_entries() {
|
||||
@@ -45,8 +43,6 @@ impl FileTransferActivity {
|
||||
.for_each(|x| self.action_open_local_file(x, None));
|
||||
}
|
||||
|
||||
/// ### action_open_remote
|
||||
///
|
||||
/// Open local file
|
||||
pub(crate) fn action_open_remote(&mut self) {
|
||||
let entries: Vec<Entry> = match self.get_remote_selected_entries() {
|
||||
@@ -59,15 +55,11 @@ impl FileTransferActivity {
|
||||
.for_each(|x| self.action_open_remote_file(x, None));
|
||||
}
|
||||
|
||||
/// ### action_open_local_file
|
||||
///
|
||||
/// Perform open lopcal file
|
||||
pub(crate) fn action_open_local_file(&mut self, entry: &Entry, open_with: Option<&str>) {
|
||||
self.open_path_with(entry.path(), open_with);
|
||||
}
|
||||
|
||||
/// ### action_open_local
|
||||
///
|
||||
/// Open remote file. The file is first downloaded to a temporary directory on localhost
|
||||
pub(crate) fn action_open_remote_file(&mut self, entry: &Entry, open_with: Option<&str>) {
|
||||
// Download file
|
||||
@@ -107,8 +99,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_local_open_with
|
||||
///
|
||||
/// Open selected file with provided application
|
||||
pub(crate) fn action_local_open_with(&mut self, with: &str) {
|
||||
let entries: Vec<Entry> = match self.get_local_selected_entries() {
|
||||
@@ -122,8 +112,6 @@ impl FileTransferActivity {
|
||||
.for_each(|x| self.action_open_local_file(x, Some(with)));
|
||||
}
|
||||
|
||||
/// ### action_remote_open_with
|
||||
///
|
||||
/// Open selected file with provided application
|
||||
pub(crate) fn action_remote_open_with(&mut self, with: &str) {
|
||||
let entries: Vec<Entry> = match self.get_remote_selected_entries() {
|
||||
@@ -137,8 +125,6 @@ impl FileTransferActivity {
|
||||
.for_each(|x| self.action_open_remote_file(x, Some(with)));
|
||||
}
|
||||
|
||||
/// ### open_path_with
|
||||
///
|
||||
/// Common function which opens a path with default or specified program.
|
||||
fn open_path_with(&mut self, p: &Path, with: Option<&str>) {
|
||||
// Open file
|
||||
|
||||
@@ -131,8 +131,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### tricky_move
|
||||
///
|
||||
/// Tricky move will be used whenever copy command is not available on remote host.
|
||||
/// It basically uses the tricky_copy function, then it just deletes the previous entry (`entry`)
|
||||
fn tricky_move(&mut self, entry: &Entry, dest: &Path) {
|
||||
|
||||
@@ -49,8 +49,6 @@ impl FileTransferActivity {
|
||||
self.remote_recv_file(TransferOpts::default());
|
||||
}
|
||||
|
||||
/// ### action_finalize_pending_transfer
|
||||
///
|
||||
/// Finalize "pending" transfer.
|
||||
/// The pending transfer is created after a transfer which required a user action to be completed first.
|
||||
/// The name of the file to transfer, is contained in the storage at `STORAGE_PENDING_TRANSFER`.
|
||||
@@ -228,8 +226,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### set_pending_transfer
|
||||
///
|
||||
/// Set pending transfer into storage
|
||||
pub(crate) fn set_pending_transfer(&mut self, file_name: &str) {
|
||||
self.mount_radio_replace(file_name);
|
||||
@@ -239,8 +235,6 @@ impl FileTransferActivity {
|
||||
.set_string(STORAGE_PENDING_TRANSFER, file_name.to_string());
|
||||
}
|
||||
|
||||
/// ### set_pending_transfer_many
|
||||
///
|
||||
/// Set pending transfer for many files into storage and mount radio
|
||||
pub(crate) fn set_pending_transfer_many(&mut self, files: Vec<&Entry>, dest_path: &str) {
|
||||
let file_names: Vec<&str> = files.iter().map(|x| x.name()).collect();
|
||||
@@ -250,8 +244,6 @@ impl FileTransferActivity {
|
||||
.set_string(STORAGE_PENDING_TRANSFER, dest_path.to_string());
|
||||
}
|
||||
|
||||
/// ### file_to_check
|
||||
///
|
||||
/// Get file to check for path
|
||||
pub(crate) fn file_to_check(e: &Entry, alt: Option<&String>) -> PathBuf {
|
||||
match alt {
|
||||
|
||||
@@ -36,8 +36,6 @@ enum SubmitAction {
|
||||
}
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### action_submit_local
|
||||
///
|
||||
/// Decides which action to perform on submit for local explorer
|
||||
/// Return true whether the directory changed
|
||||
pub(crate) fn action_submit_local(&mut self, entry: Entry) -> bool {
|
||||
@@ -78,8 +76,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_submit_remote
|
||||
///
|
||||
/// Decides which action to perform on submit for remote explorer
|
||||
/// Return true whether the directory changed
|
||||
pub(crate) fn action_submit_remote(&mut self, entry: Entry) -> bool {
|
||||
|
||||
@@ -222,8 +222,6 @@ impl Component<Msg, NoUserEvent> for Log {
|
||||
|
||||
// -- states
|
||||
|
||||
/// ## OwnStates
|
||||
///
|
||||
/// OwnStates contains states for this component
|
||||
#[derive(Clone, Default)]
|
||||
struct OwnStates {
|
||||
@@ -232,22 +230,16 @@ struct OwnStates {
|
||||
}
|
||||
|
||||
impl OwnStates {
|
||||
/// ### set_list_len
|
||||
///
|
||||
/// Set list length
|
||||
pub fn set_list_len(&mut self, len: usize) {
|
||||
self.list_len = len;
|
||||
}
|
||||
|
||||
/// ### get_list_index
|
||||
///
|
||||
/// Return current value for list index
|
||||
pub fn get_list_index(&self) -> usize {
|
||||
self.list_index
|
||||
}
|
||||
|
||||
/// ### incr_list_index
|
||||
///
|
||||
/// Incremenet list index
|
||||
pub fn incr_list_index(&mut self) {
|
||||
// Check if index is at last element
|
||||
@@ -256,8 +248,6 @@ impl OwnStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### decr_list_index
|
||||
///
|
||||
/// Decrement list index
|
||||
pub fn decr_list_index(&mut self) {
|
||||
// Check if index is bigger than 0
|
||||
@@ -266,8 +256,6 @@ impl OwnStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### list_index_at_last
|
||||
///
|
||||
/// Set list index at last item
|
||||
pub fn list_index_at_last(&mut self) {
|
||||
self.list_index = match self.list_len {
|
||||
@@ -276,8 +264,6 @@ impl OwnStates {
|
||||
};
|
||||
}
|
||||
|
||||
/// ### reset_list_index
|
||||
///
|
||||
/// Reset list index to last element
|
||||
pub fn reset_list_index(&mut self) {
|
||||
self.list_index = 0; // Last element is always 0
|
||||
|
||||
@@ -36,8 +36,6 @@ use tuirealm::{MockComponent, Props, State, StateValue};
|
||||
|
||||
pub const FILE_LIST_CMD_SELECT_ALL: &str = "A";
|
||||
|
||||
/// ## OwnStates
|
||||
///
|
||||
/// OwnStates contains states for this component
|
||||
#[derive(Clone, Default)]
|
||||
struct OwnStates {
|
||||
@@ -46,23 +44,17 @@ struct OwnStates {
|
||||
}
|
||||
|
||||
impl OwnStates {
|
||||
/// ### init_list_states
|
||||
///
|
||||
/// Initialize list states
|
||||
pub fn init_list_states(&mut self, len: usize) {
|
||||
self.selected = Vec::with_capacity(len);
|
||||
self.fix_list_index();
|
||||
}
|
||||
|
||||
/// ### list_index
|
||||
///
|
||||
/// Return current value for list index
|
||||
pub fn list_index(&self) -> usize {
|
||||
self.list_index
|
||||
}
|
||||
|
||||
/// ### incr_list_index
|
||||
///
|
||||
/// Incremenet list index.
|
||||
/// If `can_rewind` is `true` the index rewinds when boundary is reached
|
||||
pub fn incr_list_index(&mut self, can_rewind: bool) {
|
||||
@@ -74,8 +66,6 @@ impl OwnStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### decr_list_index
|
||||
///
|
||||
/// Decrement list index
|
||||
/// If `can_rewind` is `true` the index rewinds when boundary is reached
|
||||
pub fn decr_list_index(&mut self, can_rewind: bool) {
|
||||
@@ -98,36 +88,26 @@ impl OwnStates {
|
||||
};
|
||||
}
|
||||
|
||||
/// ### list_len
|
||||
///
|
||||
/// Returns the length of the file list, which is actually the capacity of the selection vector
|
||||
pub fn list_len(&self) -> usize {
|
||||
self.selected.capacity()
|
||||
}
|
||||
|
||||
/// ### is_selected
|
||||
///
|
||||
/// Returns whether the file with index `entry` is selected
|
||||
pub fn is_selected(&self, entry: usize) -> bool {
|
||||
self.selected.contains(&entry)
|
||||
}
|
||||
|
||||
/// ### is_selection_empty
|
||||
///
|
||||
/// Returns whether the selection is currently empty
|
||||
pub fn is_selection_empty(&self) -> bool {
|
||||
self.selected.is_empty()
|
||||
}
|
||||
|
||||
/// ### get_selection
|
||||
///
|
||||
/// Returns current file selection
|
||||
pub fn get_selection(&self) -> Vec<usize> {
|
||||
self.selected.clone()
|
||||
}
|
||||
|
||||
/// ### fix_list_index
|
||||
///
|
||||
/// Keep index if possible, otherwise set to lenght - 1
|
||||
fn fix_list_index(&mut self) {
|
||||
if self.list_index >= self.list_len() && self.list_len() > 0 {
|
||||
@@ -139,8 +119,6 @@ impl OwnStates {
|
||||
|
||||
// -- select manipulation
|
||||
|
||||
/// ### toggle_file
|
||||
///
|
||||
/// Select or deselect file with provided entry index
|
||||
pub fn toggle_file(&mut self, entry: usize) {
|
||||
match self.is_selected(entry) {
|
||||
@@ -149,8 +127,6 @@ impl OwnStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### select_all
|
||||
///
|
||||
/// Select all files
|
||||
pub fn select_all(&mut self) {
|
||||
for i in 0..self.list_len() {
|
||||
@@ -158,8 +134,6 @@ impl OwnStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### select
|
||||
///
|
||||
/// Select provided index if not selected yet
|
||||
fn select(&mut self, entry: usize) {
|
||||
if !self.is_selected(entry) {
|
||||
@@ -167,8 +141,6 @@ impl OwnStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### deselect
|
||||
///
|
||||
/// Remove element file with associated index
|
||||
fn deselect(&mut self, entry: usize) {
|
||||
if self.is_selected(entry) {
|
||||
|
||||
@@ -31,8 +31,6 @@ use crate::system::config_client::ConfigClient;
|
||||
use remotefs::Entry;
|
||||
use std::path::Path;
|
||||
|
||||
/// ## FileExplorerTab
|
||||
///
|
||||
/// File explorer tab
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FileExplorerTab {
|
||||
@@ -42,8 +40,6 @@ pub enum FileExplorerTab {
|
||||
FindRemote, // Find result tab
|
||||
}
|
||||
|
||||
/// ## FoundExplorerTab
|
||||
///
|
||||
/// Describes the explorer tab type
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum FoundExplorerTab {
|
||||
@@ -51,8 +47,6 @@ pub enum FoundExplorerTab {
|
||||
Remote,
|
||||
}
|
||||
|
||||
/// ## Browser
|
||||
///
|
||||
/// Browser contains the browser options
|
||||
pub struct Browser {
|
||||
local: FileExplorer, // Local File explorer state
|
||||
@@ -63,8 +57,6 @@ pub struct Browser {
|
||||
}
|
||||
|
||||
impl Browser {
|
||||
/// ### new
|
||||
///
|
||||
/// Build a new `Browser` struct
|
||||
pub fn new(cli: &ConfigClient) -> Self {
|
||||
Self {
|
||||
@@ -110,8 +102,6 @@ impl Browser {
|
||||
self.found = None;
|
||||
}
|
||||
|
||||
/// ### found_tab
|
||||
///
|
||||
/// Returns found tab if any
|
||||
pub fn found_tab(&self) -> Option<FoundExplorerTab> {
|
||||
self.found.as_ref().map(|x| x.0)
|
||||
@@ -121,22 +111,16 @@ impl Browser {
|
||||
self.tab
|
||||
}
|
||||
|
||||
/// ### change_tab
|
||||
///
|
||||
/// Update tab value
|
||||
pub fn change_tab(&mut self, tab: FileExplorerTab) {
|
||||
self.tab = tab;
|
||||
}
|
||||
|
||||
/// ### toggle_sync_browsing
|
||||
///
|
||||
/// Invert the current state for the sync browsing
|
||||
pub fn toggle_sync_browsing(&mut self) {
|
||||
self.sync_browsing = !self.sync_browsing;
|
||||
}
|
||||
|
||||
/// ### build_local_explorer
|
||||
///
|
||||
/// Build a file explorer with local host setup
|
||||
pub fn build_local_explorer(cli: &ConfigClient) -> FileExplorer {
|
||||
let mut builder = Self::build_explorer(cli);
|
||||
@@ -144,8 +128,6 @@ impl Browser {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
/// ### build_remote_explorer
|
||||
///
|
||||
/// Build a file explorer with remote host setup
|
||||
pub fn build_remote_explorer(cli: &ConfigClient) -> FileExplorer {
|
||||
let mut builder = Self::build_explorer(cli);
|
||||
@@ -153,8 +135,6 @@ impl Browser {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
/// ### build_explorer
|
||||
///
|
||||
/// Build explorer reading configuration from `ConfigClient`
|
||||
fn build_explorer(cli: &ConfigClient) -> FileExplorerBuilder {
|
||||
let mut builder: FileExplorerBuilder = FileExplorerBuilder::new();
|
||||
@@ -167,8 +147,6 @@ impl Browser {
|
||||
builder
|
||||
}
|
||||
|
||||
/// ### build_found_explorer
|
||||
///
|
||||
/// Build explorer reading from `ConfigClient`, for found result (has some differences)
|
||||
fn build_found_explorer(wrkdir: &Path) -> FileExplorer {
|
||||
FileExplorerBuilder::new()
|
||||
|
||||
@@ -56,8 +56,6 @@ impl Default for TransferStates {
|
||||
}
|
||||
|
||||
impl TransferStates {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new transfer states
|
||||
pub fn new() -> TransferStates {
|
||||
TransferStates {
|
||||
@@ -67,29 +65,21 @@ impl TransferStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### reset
|
||||
///
|
||||
/// Re-intiialize transfer states
|
||||
pub fn reset(&mut self) {
|
||||
self.aborted = false;
|
||||
}
|
||||
|
||||
/// ### abort
|
||||
///
|
||||
/// Set aborted to true
|
||||
pub fn abort(&mut self) {
|
||||
self.aborted = true;
|
||||
}
|
||||
|
||||
/// ### aborted
|
||||
///
|
||||
/// Returns whether transfer has been aborted
|
||||
pub fn aborted(&self) -> bool {
|
||||
self.aborted
|
||||
}
|
||||
|
||||
/// ### full_size
|
||||
///
|
||||
/// Returns the size of the entire transfer
|
||||
pub fn full_size(&self) -> usize {
|
||||
self.full.total
|
||||
@@ -128,8 +118,6 @@ impl fmt::Display for ProgressStates {
|
||||
}
|
||||
|
||||
impl ProgressStates {
|
||||
/// ### init
|
||||
///
|
||||
/// Initialize a new Progress State
|
||||
pub fn init(&mut self, sz: usize) {
|
||||
self.started = Instant::now();
|
||||
@@ -137,16 +125,12 @@ impl ProgressStates {
|
||||
self.written = 0;
|
||||
}
|
||||
|
||||
/// ### update_progress
|
||||
///
|
||||
/// Update progress state
|
||||
pub fn update_progress(&mut self, delta: usize) -> f64 {
|
||||
self.written += delta;
|
||||
self.calc_progress_percentage()
|
||||
}
|
||||
|
||||
/// ### calc_progress
|
||||
///
|
||||
/// Calculate progress in a range between 0.0 to 1.0
|
||||
pub fn calc_progress(&self) -> f64 {
|
||||
// Prevent dividing by 0
|
||||
@@ -160,22 +144,16 @@ impl ProgressStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### started
|
||||
///
|
||||
/// Get started
|
||||
pub fn started(&self) -> Instant {
|
||||
self.started
|
||||
}
|
||||
|
||||
/// ### calc_progress_percentage
|
||||
///
|
||||
/// Calculate the current transfer progress as percentage
|
||||
fn calc_progress_percentage(&self) -> f64 {
|
||||
self.calc_progress() * 100.0
|
||||
}
|
||||
|
||||
/// ### calc_bytes_per_second
|
||||
///
|
||||
/// Generic function to calculate bytes per second using elapsed time since transfer started and the bytes written
|
||||
/// and the total amount of bytes to write
|
||||
pub fn calc_bytes_per_second(&self) -> u64 {
|
||||
@@ -191,8 +169,6 @@ impl ProgressStates {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### calc_eta
|
||||
///
|
||||
/// Calculate ETA for current transfer as seconds
|
||||
fn calc_eta(&self) -> u64 {
|
||||
let elapsed_secs: u64 = self.started.elapsed().as_secs();
|
||||
@@ -206,8 +182,6 @@ impl ProgressStates {
|
||||
|
||||
// -- Options
|
||||
|
||||
/// ## TransferOpts
|
||||
///
|
||||
/// Defines the transfer options for transfer actions
|
||||
pub struct TransferOpts {
|
||||
/// Save file as
|
||||
@@ -226,16 +200,12 @@ impl Default for TransferOpts {
|
||||
}
|
||||
|
||||
impl TransferOpts {
|
||||
/// ### save_as
|
||||
///
|
||||
/// Define the name of the file to be saved
|
||||
pub fn save_as<S: AsRef<str>>(mut self, n: Option<S>) -> Self {
|
||||
self.save_as = n.map(|x| x.as_ref().to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// ### check_replace
|
||||
///
|
||||
/// Set whether to check if the file being transferred will "replace" an existing one
|
||||
pub fn check_replace(mut self, opt: bool) -> Self {
|
||||
self.check_replace = opt;
|
||||
|
||||
@@ -43,8 +43,6 @@ use tuirealm::{PollStrategy, Update};
|
||||
const LOG_CAPACITY: usize = 256;
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### tick
|
||||
///
|
||||
/// Call `Application::tick()` and process messages in `Update`
|
||||
pub(super) fn tick(&mut self) {
|
||||
match self.app.tick(PollStrategy::UpTo(3)) {
|
||||
@@ -65,8 +63,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### log
|
||||
///
|
||||
/// Add message to log events
|
||||
pub(super) fn log(&mut self, level: LogLevel, msg: String) {
|
||||
// Log to file
|
||||
@@ -87,8 +83,6 @@ impl FileTransferActivity {
|
||||
self.update_logbox();
|
||||
}
|
||||
|
||||
/// ### log_and_alert
|
||||
///
|
||||
/// Add message to log events and also display it as an alert
|
||||
pub(super) fn log_and_alert(&mut self, level: LogLevel, msg: String) {
|
||||
self.mount_error(msg.as_str());
|
||||
@@ -97,8 +91,6 @@ impl FileTransferActivity {
|
||||
self.update_logbox();
|
||||
}
|
||||
|
||||
/// ### init_config_client
|
||||
///
|
||||
/// Initialize configuration client if possible.
|
||||
/// This function doesn't return errors.
|
||||
pub(super) fn init_config_client() -> ConfigClient {
|
||||
@@ -119,29 +111,21 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### setup_text_editor
|
||||
///
|
||||
/// Set text editor to use
|
||||
pub(super) fn setup_text_editor(&self) {
|
||||
env::set_var("EDITOR", self.config().get_text_editor());
|
||||
}
|
||||
|
||||
/// ### local_to_abs_path
|
||||
///
|
||||
/// 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)
|
||||
}
|
||||
|
||||
/// ### remote_to_abs_path
|
||||
///
|
||||
/// Convert a path to absolute according to remote explorer
|
||||
pub(super) fn remote_to_abs_path(&self, path: &Path) -> PathBuf {
|
||||
path::absolutize(self.remote().wrkdir.as_path(), path)
|
||||
}
|
||||
|
||||
/// ### get_remote_hostname
|
||||
///
|
||||
/// Get remote hostname
|
||||
pub(super) fn get_remote_hostname(&self) -> String {
|
||||
let ft_params = self.context().ft_params().unwrap();
|
||||
@@ -151,8 +135,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_connection_msg
|
||||
///
|
||||
/// Get connection message to show to client
|
||||
pub(super) fn get_connection_msg(params: &ProtocolParams) -> String {
|
||||
match params {
|
||||
@@ -173,8 +155,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### notify_transfer_completed
|
||||
///
|
||||
/// Send notification regarding transfer completed
|
||||
/// The notification is sent only when these conditions are satisfied:
|
||||
///
|
||||
@@ -188,8 +168,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### notify_transfer_error
|
||||
///
|
||||
/// Send notification regarding transfer error
|
||||
/// The notification is sent only when these conditions are satisfied:
|
||||
///
|
||||
@@ -233,8 +211,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### update_local_filelist
|
||||
///
|
||||
/// Update local file list
|
||||
pub(super) fn update_local_filelist(&mut self) {
|
||||
// Get width
|
||||
@@ -280,8 +256,6 @@ impl FileTransferActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### update_remote_filelist
|
||||
///
|
||||
/// Update remote file list
|
||||
pub(super) fn update_remote_filelist(&mut self) {
|
||||
let width: usize = self
|
||||
@@ -323,8 +297,6 @@ impl FileTransferActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### update_logbox
|
||||
///
|
||||
/// Update log box
|
||||
pub(super) fn update_logbox(&mut self) {
|
||||
let mut table: TableBuilder = TableBuilder::default();
|
||||
@@ -418,8 +390,6 @@ impl FileTransferActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### finalize_find
|
||||
///
|
||||
/// Finalize find process
|
||||
pub(super) fn finalize_find(&mut self) {
|
||||
// Set found to none
|
||||
|
||||
@@ -171,8 +171,6 @@ enum UiMsg {
|
||||
ToggleSyncBrowsing,
|
||||
}
|
||||
|
||||
/// ## LogLevel
|
||||
///
|
||||
/// Log level type
|
||||
enum LogLevel {
|
||||
Error,
|
||||
@@ -180,8 +178,6 @@ enum LogLevel {
|
||||
Info,
|
||||
}
|
||||
|
||||
/// ## LogRecord
|
||||
///
|
||||
/// Log record entry
|
||||
struct LogRecord {
|
||||
pub time: DateTime<Local>,
|
||||
@@ -190,8 +186,6 @@ struct LogRecord {
|
||||
}
|
||||
|
||||
impl LogRecord {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new LogRecord
|
||||
pub fn new(level: LogLevel, msg: String) -> LogRecord {
|
||||
LogRecord {
|
||||
@@ -202,8 +196,6 @@ impl LogRecord {
|
||||
}
|
||||
}
|
||||
|
||||
/// ## FileTransferActivity
|
||||
///
|
||||
/// FileTransferActivity is the data holder for the file transfer activity
|
||||
pub struct FileTransferActivity {
|
||||
/// Exit reason
|
||||
@@ -228,8 +220,6 @@ pub struct FileTransferActivity {
|
||||
}
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new FileTransferActivity
|
||||
pub fn new(host: Localhost, params: &FileTransferParams, ticks: Duration) -> Self {
|
||||
// Get config client
|
||||
@@ -279,8 +269,6 @@ impl FileTransferActivity {
|
||||
self.browser.found_mut()
|
||||
}
|
||||
|
||||
/// ### get_cache_tmp_name
|
||||
///
|
||||
/// Get file name for a file in cache
|
||||
fn get_cache_tmp_name(&self, name: &str, file_type: Option<&str>) -> Option<String> {
|
||||
self.cache.as_ref().map(|_| {
|
||||
@@ -299,29 +287,21 @@ impl FileTransferActivity {
|
||||
})
|
||||
}
|
||||
|
||||
/// ### context
|
||||
///
|
||||
/// Returns a reference to context
|
||||
fn context(&self) -> &Context {
|
||||
self.context.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// ### context_mut
|
||||
///
|
||||
/// Returns a mutable reference to context
|
||||
fn context_mut(&mut self) -> &mut Context {
|
||||
self.context.as_mut().unwrap()
|
||||
}
|
||||
|
||||
/// ### config
|
||||
///
|
||||
/// Returns config client reference
|
||||
fn config(&self) -> &ConfigClient {
|
||||
self.context().config()
|
||||
}
|
||||
|
||||
/// ### theme
|
||||
///
|
||||
/// Get a reference to `Theme`
|
||||
fn theme(&self) -> &Theme {
|
||||
self.context().theme_provider().theme()
|
||||
@@ -335,8 +315,6 @@ impl FileTransferActivity {
|
||||
*/
|
||||
|
||||
impl Activity for FileTransferActivity {
|
||||
/// ### on_create
|
||||
///
|
||||
/// `on_create` is the function which must be called to initialize the activity.
|
||||
/// `on_create` must initialize all the data structures used by the activity
|
||||
fn on_create(&mut self, context: Context) {
|
||||
@@ -368,8 +346,6 @@ impl Activity for FileTransferActivity {
|
||||
info!("Created FileTransferActivity");
|
||||
}
|
||||
|
||||
/// ### on_draw
|
||||
///
|
||||
/// `on_draw` is the function which draws the graphical interface.
|
||||
/// This function must be called at each tick to refresh the interface
|
||||
fn on_draw(&mut self) {
|
||||
@@ -398,8 +374,6 @@ impl Activity for FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### will_umount
|
||||
///
|
||||
/// `will_umount` is the method which must be able to report to the activity manager, whether
|
||||
/// the activity should be terminated or not.
|
||||
/// If not, the call will return `None`, otherwise return`Some(ExitReason)`
|
||||
@@ -407,8 +381,6 @@ impl Activity for FileTransferActivity {
|
||||
self.exit_reason.as_ref()
|
||||
}
|
||||
|
||||
/// ### on_destroy
|
||||
///
|
||||
/// `on_destroy` is the function which cleans up runtime variables and data before terminating the activity.
|
||||
/// This function must be called once before terminating the activity.
|
||||
fn on_destroy(&mut self) -> Option<Context> {
|
||||
|
||||
@@ -40,8 +40,6 @@ use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
use thiserror::Error;
|
||||
|
||||
/// ## TransferErrorReason
|
||||
///
|
||||
/// Describes the reason that caused an error during a file transfer
|
||||
#[derive(Error, Debug)]
|
||||
enum TransferErrorReason {
|
||||
@@ -59,8 +57,6 @@ enum TransferErrorReason {
|
||||
FileTransferError(RemoteError),
|
||||
}
|
||||
|
||||
/// ## TransferPayload
|
||||
///
|
||||
/// Represents the entity to send or receive during a transfer.
|
||||
/// - File: describes an individual `File` to send
|
||||
/// - Any: Can be any kind of `Entry`, but just one
|
||||
@@ -73,8 +69,6 @@ pub(super) enum TransferPayload {
|
||||
}
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// ### connect
|
||||
///
|
||||
/// Connect to remote
|
||||
pub(super) fn connect(&mut self) {
|
||||
let ft_params = self.context().ft_params().unwrap().clone();
|
||||
@@ -116,8 +110,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### disconnect
|
||||
///
|
||||
/// disconnect from remote
|
||||
pub(super) fn disconnect(&mut self) {
|
||||
let msg: String = format!("Disconnecting from {}…", self.get_remote_hostname());
|
||||
@@ -129,16 +121,12 @@ impl FileTransferActivity {
|
||||
self.exit_reason = Some(super::ExitReason::Disconnect);
|
||||
}
|
||||
|
||||
/// ### disconnect_and_quit
|
||||
///
|
||||
/// disconnect from remote and then quit
|
||||
pub(super) fn disconnect_and_quit(&mut self) {
|
||||
self.disconnect();
|
||||
self.exit_reason = Some(super::ExitReason::Quit);
|
||||
}
|
||||
|
||||
/// ### reload_remote_dir
|
||||
///
|
||||
/// Reload remote directory entries and update browser
|
||||
pub(super) fn reload_remote_dir(&mut self) {
|
||||
// Get current entries
|
||||
@@ -149,8 +137,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### reload_local_dir
|
||||
///
|
||||
/// Reload local directory entries and update browser
|
||||
pub(super) fn reload_local_dir(&mut self) {
|
||||
let wrkdir: PathBuf = self.host.pwd();
|
||||
@@ -158,8 +144,6 @@ impl FileTransferActivity {
|
||||
self.local_mut().wrkdir = wrkdir;
|
||||
}
|
||||
|
||||
/// ### local_scan
|
||||
///
|
||||
/// Scan current local directory
|
||||
fn local_scan(&mut self, path: &Path) {
|
||||
match self.host.scan_dir(path) {
|
||||
@@ -176,8 +160,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### remote_scan
|
||||
///
|
||||
/// Scan current remote directory
|
||||
fn remote_scan(&mut self, path: &Path) {
|
||||
match self.client.list_dir(path) {
|
||||
@@ -194,8 +176,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### filetransfer_send
|
||||
///
|
||||
/// Send fs entry to remote.
|
||||
/// If dst_name is Some, entry will be saved with a different name.
|
||||
/// If entry is a directory, this applies to directory only
|
||||
@@ -229,8 +209,6 @@ impl FileTransferActivity {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_file
|
||||
///
|
||||
/// Send one file to remote at specified path.
|
||||
fn filetransfer_send_file(
|
||||
&mut self,
|
||||
@@ -261,8 +239,6 @@ impl FileTransferActivity {
|
||||
result.map_err(|x| x.to_string())
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_any
|
||||
///
|
||||
/// Send a `TransferPayload` of type `Any`
|
||||
fn filetransfer_send_any(
|
||||
&mut self,
|
||||
@@ -284,8 +260,6 @@ impl FileTransferActivity {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_many
|
||||
///
|
||||
/// Send many entries to remote
|
||||
fn filetransfer_send_many(
|
||||
&mut self,
|
||||
@@ -448,8 +422,6 @@ impl FileTransferActivity {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_file
|
||||
///
|
||||
/// Send local file and write it to remote path
|
||||
fn filetransfer_send_one(
|
||||
&mut self,
|
||||
@@ -479,8 +451,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_one_with_stream
|
||||
///
|
||||
/// Send file to remote using stream
|
||||
fn filetransfer_send_one_with_stream(
|
||||
&mut self,
|
||||
@@ -580,8 +550,6 @@ impl FileTransferActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_one_wno_stream
|
||||
///
|
||||
/// Send an `File` to remote without using streams.
|
||||
fn filetransfer_send_one_wno_stream(
|
||||
&mut self,
|
||||
@@ -631,8 +599,6 @@ impl FileTransferActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### filetransfer_recv
|
||||
///
|
||||
/// Recv fs entry from remote.
|
||||
/// If dst_name is Some, entry will be saved with a different name.
|
||||
/// If entry is a directory, this applies to directory only
|
||||
@@ -661,8 +627,6 @@ impl FileTransferActivity {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### filetransfer_recv_any
|
||||
///
|
||||
/// Recv fs entry from remote.
|
||||
/// If dst_name is Some, entry will be saved with a different name.
|
||||
/// If entry is a directory, this applies to directory only
|
||||
@@ -686,8 +650,6 @@ impl FileTransferActivity {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### filetransfer_recv_file
|
||||
///
|
||||
/// Receive a single file from remote.
|
||||
fn filetransfer_recv_file(&mut self, entry: &File, local_path: &Path) -> Result<(), String> {
|
||||
// Reset states
|
||||
@@ -705,8 +667,6 @@ impl FileTransferActivity {
|
||||
result.map_err(|x| x.to_string())
|
||||
}
|
||||
|
||||
/// ### filetransfer_send_many
|
||||
///
|
||||
/// Send many entries to remote
|
||||
fn filetransfer_recv_many(
|
||||
&mut self,
|
||||
@@ -887,8 +847,6 @@ impl FileTransferActivity {
|
||||
result
|
||||
}
|
||||
|
||||
/// ### filetransfer_recv_one
|
||||
///
|
||||
/// Receive file from remote and write it to local path
|
||||
fn filetransfer_recv_one(
|
||||
&mut self,
|
||||
@@ -914,8 +872,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### filetransfer_recv_one_with_stream
|
||||
///
|
||||
/// Receive an `Entry` from remote using stream
|
||||
fn filetransfer_recv_one_with_stream(
|
||||
&mut self,
|
||||
@@ -1023,8 +979,6 @@ impl FileTransferActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### filetransfer_recv_one_with_stream
|
||||
///
|
||||
/// Receive an `Entry` from remote without using stream
|
||||
fn filetransfer_recv_one_wno_stream(
|
||||
&mut self,
|
||||
@@ -1086,8 +1040,6 @@ impl FileTransferActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### local_changedir
|
||||
///
|
||||
/// Change directory for local
|
||||
pub(super) fn local_changedir(&mut self, path: &Path, push: bool) {
|
||||
// Get current directory
|
||||
@@ -1143,8 +1095,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### download_file_as_temp
|
||||
///
|
||||
/// Download provided file as a temporary file
|
||||
pub(super) fn download_file_as_temp(&mut self, file: &File) -> Result<PathBuf, String> {
|
||||
let tmpfile: PathBuf = match self.cache.as_ref() {
|
||||
@@ -1176,8 +1126,6 @@ impl FileTransferActivity {
|
||||
|
||||
// -- transfer sizes
|
||||
|
||||
/// ### get_total_transfer_size_local
|
||||
///
|
||||
/// Get total size of transfer for localhost
|
||||
fn get_total_transfer_size_local(&mut self, entry: &Entry) -> usize {
|
||||
match entry {
|
||||
@@ -1201,8 +1149,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_total_transfer_size_remote
|
||||
///
|
||||
/// Get total size of transfer for remote host
|
||||
fn get_total_transfer_size_remote(&mut self, entry: &Entry) -> usize {
|
||||
match entry {
|
||||
|
||||
@@ -43,8 +43,6 @@ use tuirealm::{Sub, SubClause, SubEventClause};
|
||||
impl FileTransferActivity {
|
||||
// -- init
|
||||
|
||||
/// ### init
|
||||
///
|
||||
/// Initialize file transfer activity's view
|
||||
pub(super) fn init(&mut self) {
|
||||
// Mount local file explorer
|
||||
@@ -106,8 +104,6 @@ impl FileTransferActivity {
|
||||
|
||||
// -- view
|
||||
|
||||
/// ### view
|
||||
///
|
||||
/// View gui
|
||||
pub(super) fn view(&mut self) {
|
||||
self.redraw = false;
|
||||
@@ -303,8 +299,6 @@ impl FileTransferActivity {
|
||||
|
||||
// -- partials
|
||||
|
||||
/// ### mount_info
|
||||
///
|
||||
/// Mount info box
|
||||
pub(super) fn mount_info<S: AsRef<str>>(&mut self, text: S) {
|
||||
// Mount
|
||||
@@ -320,8 +314,6 @@ impl FileTransferActivity {
|
||||
assert!(self.app.active(&Id::ErrorPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### mount_error
|
||||
///
|
||||
/// Mount error box
|
||||
pub(super) fn mount_error<S: AsRef<str>>(&mut self, text: S) {
|
||||
// Mount
|
||||
@@ -337,8 +329,6 @@ impl FileTransferActivity {
|
||||
assert!(self.app.active(&Id::ErrorPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_error
|
||||
///
|
||||
/// Umount error message
|
||||
pub(super) fn umount_error(&mut self) {
|
||||
let _ = self.app.umount(&Id::ErrorPopup);
|
||||
@@ -358,8 +348,6 @@ impl FileTransferActivity {
|
||||
assert!(self.app.active(&Id::FatalPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_fatal
|
||||
///
|
||||
/// Umount fatal error message
|
||||
pub(super) fn umount_fatal(&mut self) {
|
||||
let _ = self.app.umount(&Id::FatalPopup);
|
||||
@@ -387,8 +375,6 @@ impl FileTransferActivity {
|
||||
let _ = self.app.umount(&Id::WaitPopup);
|
||||
}
|
||||
|
||||
/// ### mount_quit
|
||||
///
|
||||
/// Mount quit popup
|
||||
pub(super) fn mount_quit(&mut self) {
|
||||
// Protocol
|
||||
@@ -404,15 +390,11 @@ impl FileTransferActivity {
|
||||
assert!(self.app.active(&Id::QuitPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_quit
|
||||
///
|
||||
/// Umount quit popup
|
||||
pub(super) fn umount_quit(&mut self) {
|
||||
let _ = self.app.umount(&Id::QuitPopup);
|
||||
}
|
||||
|
||||
/// ### mount_disconnect
|
||||
///
|
||||
/// Mount disconnect popup
|
||||
pub(super) fn mount_disconnect(&mut self) {
|
||||
// Protocol
|
||||
@@ -428,8 +410,6 @@ impl FileTransferActivity {
|
||||
assert!(self.app.active(&Id::DisconnectPopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_disconnect
|
||||
///
|
||||
/// Umount disconnect popup
|
||||
pub(super) fn umount_disconnect(&mut self) {
|
||||
let _ = self.app.umount(&Id::DisconnectPopup);
|
||||
@@ -735,8 +715,6 @@ impl FileTransferActivity {
|
||||
assert!(self.app.active(&Id::ReplacePopup).is_ok());
|
||||
}
|
||||
|
||||
/// ### is_radio_replace_extended
|
||||
///
|
||||
/// Returns whether radio replace is in "extended" mode (for many files)
|
||||
pub(super) fn is_radio_replace_extended(&self) -> bool {
|
||||
self.app.mounted(&Id::ReplacingFilesListPopup)
|
||||
@@ -799,8 +777,6 @@ impl FileTransferActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### mount_help
|
||||
///
|
||||
/// Mount help
|
||||
pub(super) fn mount_help(&mut self) {
|
||||
let key_color = self.theme().misc_keys;
|
||||
@@ -852,8 +828,6 @@ impl FileTransferActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### no_popup_mounted_clause
|
||||
///
|
||||
/// Returns a sub clause which requires that no popup is mounted in order to be satisfied
|
||||
fn no_popup_mounted_clause() -> SubClause<Id> {
|
||||
SubClause::And(
|
||||
|
||||
@@ -45,28 +45,20 @@ pub enum ExitReason {
|
||||
// -- Activity trait
|
||||
|
||||
pub trait Activity {
|
||||
/// ### on_create
|
||||
///
|
||||
/// `on_create` is the function which must be called to initialize the activity.
|
||||
/// `on_create` must initialize all the data structures used by the activity
|
||||
/// Context is taken from activity manager and will be released only when activity is destroyed
|
||||
fn on_create(&mut self, context: Context);
|
||||
|
||||
/// ### on_draw
|
||||
///
|
||||
/// `on_draw` is the function which draws the graphical interface.
|
||||
/// This function must be called at each tick to refresh the interface
|
||||
fn on_draw(&mut self);
|
||||
|
||||
/// ### will_umount
|
||||
///
|
||||
/// `will_umount` is the method which must be able to report to the activity manager, whether
|
||||
/// the activity should be terminated or not.
|
||||
/// If not, the call will return `None`, otherwise return`Some(ExitReason)`
|
||||
fn will_umount(&self) -> Option<&ExitReason>;
|
||||
|
||||
/// ### on_destroy
|
||||
///
|
||||
/// `on_destroy` is the function which cleans up runtime variables and data before terminating the activity.
|
||||
/// This function must be called once before terminating the activity.
|
||||
/// This function finally releases the context
|
||||
|
||||
@@ -35,8 +35,6 @@ use tuirealm::tui::style::Color;
|
||||
use tuirealm::{State, StateValue};
|
||||
|
||||
impl SetupActivity {
|
||||
/// ### action_on_esc
|
||||
///
|
||||
/// On <ESC>, if there are changes in the configuration, the quit dialog must be shown, otherwise
|
||||
/// we can exit without any problem
|
||||
pub(super) fn action_on_esc(&mut self) {
|
||||
@@ -47,8 +45,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_save_all
|
||||
///
|
||||
/// Save all configurations. If current tab can load values, they will be loaded, otherwise they'll just be saved.
|
||||
/// Once all the configuration has been changed, set config_changed to false
|
||||
pub(super) fn action_save_all(&mut self) -> Result<(), String> {
|
||||
@@ -59,8 +55,6 @@ impl SetupActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### action_save_config
|
||||
///
|
||||
/// Save configuration
|
||||
fn action_save_config(&mut self) -> Result<(), String> {
|
||||
// Collect input values if in setup form
|
||||
@@ -70,8 +64,6 @@ impl SetupActivity {
|
||||
self.save_config()
|
||||
}
|
||||
|
||||
/// ### action_save_theme
|
||||
///
|
||||
/// Save configuration
|
||||
fn action_save_theme(&mut self) -> Result<(), String> {
|
||||
// Collect input values if in theme form
|
||||
@@ -83,8 +75,6 @@ impl SetupActivity {
|
||||
self.save_theme()
|
||||
}
|
||||
|
||||
/// ### action_change_tab
|
||||
///
|
||||
/// Change view tab and load input values in order not to lose them
|
||||
pub(super) fn action_change_tab(&mut self, new_tab: ViewLayout) -> Result<(), String> {
|
||||
// load values for current tab first
|
||||
@@ -100,8 +90,6 @@ impl SetupActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### action_reset_config
|
||||
///
|
||||
/// Reset configuration input fields
|
||||
pub(super) fn action_reset_config(&mut self) -> Result<(), String> {
|
||||
match self.reset_config_changes() {
|
||||
@@ -113,8 +101,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_reset_theme
|
||||
///
|
||||
/// Reset configuration input fields
|
||||
pub(super) fn action_reset_theme(&mut self) -> Result<(), String> {
|
||||
match self.reset_theme_changes() {
|
||||
@@ -126,8 +112,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_delete_ssh_key
|
||||
///
|
||||
/// delete of a ssh key
|
||||
pub(super) fn action_delete_ssh_key(&mut self) {
|
||||
// Get key
|
||||
@@ -160,8 +144,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_new_ssh_key
|
||||
///
|
||||
/// Create a new ssh key
|
||||
pub(super) fn action_new_ssh_key(&mut self) {
|
||||
// get parameters
|
||||
@@ -228,8 +210,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### set_color
|
||||
///
|
||||
/// Given a component and a color, save the color into the theme
|
||||
pub(super) fn action_save_color(&mut self, component: IdTheme, color: Color) {
|
||||
let theme: &mut Theme = self.theme_mut();
|
||||
@@ -319,8 +299,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### collect_styles
|
||||
///
|
||||
/// Collect values from input and put them into the theme.
|
||||
/// If a component has an invalid color, returns Err(component_id)
|
||||
fn collect_styles(&mut self) -> Result<(), Id> {
|
||||
@@ -440,8 +418,6 @@ impl SetupActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### get_color
|
||||
///
|
||||
/// Get color from component
|
||||
fn get_color(&self, component: &Id) -> Result<Color, ()> {
|
||||
match self.app.state(component) {
|
||||
|
||||
@@ -32,8 +32,6 @@ use super::SetupActivity;
|
||||
use std::env;
|
||||
|
||||
impl SetupActivity {
|
||||
/// ### save_config
|
||||
///
|
||||
/// Save configuration
|
||||
pub(super) fn save_config(&mut self) -> Result<(), String> {
|
||||
match self.config().write_config() {
|
||||
@@ -42,8 +40,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### reset_config_changes
|
||||
///
|
||||
/// Reset configuration changes; pratically read config from file, overwriting any change made
|
||||
/// since last write action
|
||||
pub(super) fn reset_config_changes(&mut self) -> Result<(), String> {
|
||||
@@ -52,8 +48,6 @@ impl SetupActivity {
|
||||
.map_err(|e| format!("Could not reload configuration: {}", e))
|
||||
}
|
||||
|
||||
/// ### save_theme
|
||||
///
|
||||
/// Save theme to file
|
||||
pub(super) fn save_theme(&mut self) -> Result<(), String> {
|
||||
self.theme_provider()
|
||||
@@ -61,8 +55,6 @@ impl SetupActivity {
|
||||
.map_err(|e| format!("Could not save theme: {}", e))
|
||||
}
|
||||
|
||||
/// ### reset_theme_changes
|
||||
///
|
||||
/// Reset changes committed to theme
|
||||
pub(super) fn reset_theme_changes(&mut self) -> Result<(), String> {
|
||||
self.theme_provider()
|
||||
@@ -70,8 +62,6 @@ impl SetupActivity {
|
||||
.map_err(|e| format!("Could not restore theme: {}", e))
|
||||
}
|
||||
|
||||
/// ### delete_ssh_key
|
||||
///
|
||||
/// Delete ssh key from config cli
|
||||
pub(super) fn delete_ssh_key(&mut self, host: &str, username: &str) -> Result<(), String> {
|
||||
match self.config_mut().del_ssh_key(host, username) {
|
||||
@@ -83,8 +73,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### edit_ssh_key
|
||||
///
|
||||
/// Edit selected ssh key
|
||||
pub(super) fn edit_ssh_key(&mut self, idx: usize) -> Result<(), String> {
|
||||
match self.context.as_mut() {
|
||||
@@ -142,8 +130,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### add_ssh_key
|
||||
///
|
||||
/// Add provided ssh key to config client
|
||||
pub(super) fn add_ssh_key(
|
||||
&mut self,
|
||||
|
||||
@@ -256,8 +256,6 @@ pub enum ViewLayout {
|
||||
Theme,
|
||||
}
|
||||
|
||||
/// ## SetupActivity
|
||||
///
|
||||
/// Setup activity states holder
|
||||
pub struct SetupActivity {
|
||||
app: Application<Id, Msg, NoUserEvent>,
|
||||
@@ -282,15 +280,11 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### context
|
||||
///
|
||||
/// Returns a reference to context
|
||||
fn context(&self) -> &Context {
|
||||
self.context.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// ### context_mut
|
||||
///
|
||||
/// Returns a mutable reference to context
|
||||
fn context_mut(&mut self) -> &mut Context {
|
||||
self.context.as_mut().unwrap()
|
||||
@@ -316,8 +310,6 @@ impl SetupActivity {
|
||||
self.context_mut().theme_provider_mut()
|
||||
}
|
||||
|
||||
/// ### config_changed
|
||||
///
|
||||
/// Returns whether config has changed
|
||||
fn config_changed(&self) -> bool {
|
||||
self.context()
|
||||
@@ -326,8 +318,6 @@ impl SetupActivity {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// ### set_config_changed
|
||||
///
|
||||
/// Set value for config changed key into the store
|
||||
fn set_config_changed(&mut self, changed: bool) {
|
||||
self.context_mut()
|
||||
@@ -337,8 +327,6 @@ impl SetupActivity {
|
||||
}
|
||||
|
||||
impl Activity for SetupActivity {
|
||||
/// ### on_create
|
||||
///
|
||||
/// `on_create` is the function which must be called to initialize the activity.
|
||||
/// `on_create` must initialize all the data structures used by the activity
|
||||
/// Context is taken from activity manager and will be released only when activity is destroyed
|
||||
@@ -363,8 +351,6 @@ impl Activity for SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### on_draw
|
||||
///
|
||||
/// `on_draw` is the function which draws the graphical interface.
|
||||
/// This function must be called at each tick to refresh the interface
|
||||
fn on_draw(&mut self) {
|
||||
@@ -394,8 +380,6 @@ impl Activity for SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### will_umount
|
||||
///
|
||||
/// `will_umount` is the method which must be able to report to the activity manager, whether
|
||||
/// the activity should be terminated or not.
|
||||
/// If not, the call will return `None`, otherwise return`Some(ExitReason)`
|
||||
@@ -403,8 +387,6 @@ impl Activity for SetupActivity {
|
||||
self.exit_reason.as_ref()
|
||||
}
|
||||
|
||||
/// ### on_destroy
|
||||
///
|
||||
/// `on_destroy` is the function which cleans up runtime variables and data before terminating the activity.
|
||||
/// This function must be called once before terminating the activity.
|
||||
/// This function finally releases the context
|
||||
|
||||
@@ -36,8 +36,6 @@ use super::{
|
||||
use tuirealm::Update;
|
||||
|
||||
impl Update<Msg> for SetupActivity {
|
||||
/// ### update
|
||||
///
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
fn update(&mut self, msg: Option<Msg>) -> Option<Msg> {
|
||||
|
||||
@@ -54,8 +54,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### view
|
||||
///
|
||||
/// View gui
|
||||
pub(super) fn view(&mut self) {
|
||||
self.redraw = false;
|
||||
@@ -68,8 +66,6 @@ impl SetupActivity {
|
||||
|
||||
// -- mount
|
||||
|
||||
/// ### mount_error
|
||||
///
|
||||
/// Mount error box
|
||||
pub(super) fn mount_error<S: AsRef<str>>(&mut self, text: S) {
|
||||
assert!(self
|
||||
@@ -83,15 +79,11 @@ impl SetupActivity {
|
||||
assert!(self.app.active(&Id::Common(IdCommon::ErrorPopup)).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_error
|
||||
///
|
||||
/// Umount error message
|
||||
pub(super) fn umount_error(&mut self) {
|
||||
let _ = self.app.umount(&Id::Common(IdCommon::ErrorPopup));
|
||||
}
|
||||
|
||||
/// ### mount_quit
|
||||
///
|
||||
/// Mount quit popup
|
||||
pub(super) fn mount_quit(&mut self) {
|
||||
assert!(self
|
||||
@@ -105,15 +97,11 @@ impl SetupActivity {
|
||||
assert!(self.app.active(&Id::Common(IdCommon::QuitPopup)).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_quit
|
||||
///
|
||||
/// Umount quit
|
||||
pub(super) fn umount_quit(&mut self) {
|
||||
let _ = self.app.umount(&Id::Common(IdCommon::QuitPopup));
|
||||
}
|
||||
|
||||
/// ### mount_save_popup
|
||||
///
|
||||
/// Mount save popup
|
||||
pub(super) fn mount_save_popup(&mut self) {
|
||||
assert!(self
|
||||
@@ -127,15 +115,11 @@ impl SetupActivity {
|
||||
assert!(self.app.active(&Id::Common(IdCommon::SavePopup)).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_quit
|
||||
///
|
||||
/// Umount quit
|
||||
pub(super) fn umount_save_popup(&mut self) {
|
||||
let _ = self.app.umount(&Id::Common(IdCommon::SavePopup));
|
||||
}
|
||||
|
||||
/// ### mount_help
|
||||
///
|
||||
/// Mount help
|
||||
pub(super) fn mount_help(&mut self) {
|
||||
assert!(self
|
||||
@@ -149,8 +133,6 @@ impl SetupActivity {
|
||||
assert!(self.app.active(&Id::Common(IdCommon::Keybindings)).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_help
|
||||
///
|
||||
/// Umount help
|
||||
pub(super) fn umount_help(&mut self) {
|
||||
let _ = self.app.umount(&Id::Common(IdCommon::Keybindings));
|
||||
@@ -180,8 +162,6 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### new_app
|
||||
///
|
||||
/// Clean app up and remount common components and global listener
|
||||
fn new_app(&mut self, layout: ViewLayout) {
|
||||
self.app.umount_all();
|
||||
@@ -189,8 +169,6 @@ impl SetupActivity {
|
||||
self.mount_commons(layout);
|
||||
}
|
||||
|
||||
/// ### mount_commons
|
||||
///
|
||||
/// Mount common components
|
||||
fn mount_commons(&mut self, layout: ViewLayout) {
|
||||
// Radio tab
|
||||
@@ -213,8 +191,6 @@ impl SetupActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### mount_global_listener
|
||||
///
|
||||
/// Mount global listener
|
||||
fn mount_global_listener(&mut self) {
|
||||
assert!(self
|
||||
@@ -263,8 +239,6 @@ impl SetupActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### no_popup_mounted_clause
|
||||
///
|
||||
/// Returns a sub clause which requires that no popup is mounted in order to be satisfied
|
||||
fn no_popup_mounted_clause() -> SubClause<Id> {
|
||||
SubClause::And(
|
||||
|
||||
@@ -40,8 +40,6 @@ use tuirealm::{State, StateValue};
|
||||
impl SetupActivity {
|
||||
// -- view
|
||||
|
||||
/// ### init_setup
|
||||
///
|
||||
/// Initialize setup view
|
||||
pub(super) fn init_setup(&mut self) {
|
||||
// Init view (and mount commons)
|
||||
@@ -153,8 +151,6 @@ impl SetupActivity {
|
||||
self.context = Some(ctx);
|
||||
}
|
||||
|
||||
/// ### load_input_values
|
||||
///
|
||||
/// Load values from configuration into input fields
|
||||
pub(crate) fn load_input_values(&mut self) {
|
||||
// Text editor
|
||||
@@ -267,8 +263,6 @@ impl SetupActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### collect_input_values
|
||||
///
|
||||
/// Collect values from input and put them into the configuration
|
||||
pub(crate) fn collect_input_values(&mut self) {
|
||||
if let Ok(State::One(StateValue::String(editor))) =
|
||||
|
||||
@@ -37,8 +37,6 @@ use tuirealm::tui::widgets::Clear;
|
||||
impl SetupActivity {
|
||||
// -- view
|
||||
|
||||
/// ### init_ssh_keys
|
||||
///
|
||||
/// Initialize ssh keys view
|
||||
pub(super) fn init_ssh_keys(&mut self) {
|
||||
// Init view (and mount commons)
|
||||
@@ -99,8 +97,6 @@ impl SetupActivity {
|
||||
|
||||
// -- mount
|
||||
|
||||
/// ### mount_del_ssh_key
|
||||
///
|
||||
/// Mount delete ssh key component
|
||||
pub(crate) fn mount_del_ssh_key(&mut self) {
|
||||
assert!(self
|
||||
@@ -114,15 +110,11 @@ impl SetupActivity {
|
||||
assert!(self.app.active(&Id::Ssh(IdSsh::DelSshKeyPopup)).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_del_ssh_key
|
||||
///
|
||||
/// Umount delete ssh key
|
||||
pub(crate) fn umount_del_ssh_key(&mut self) {
|
||||
let _ = self.app.umount(&Id::Ssh(IdSsh::DelSshKeyPopup));
|
||||
}
|
||||
|
||||
/// ### mount_new_ssh_key
|
||||
///
|
||||
/// Mount new ssh key prompt
|
||||
pub(crate) fn mount_new_ssh_key(&mut self) {
|
||||
assert!(self
|
||||
@@ -144,16 +136,12 @@ impl SetupActivity {
|
||||
assert!(self.app.active(&Id::Ssh(IdSsh::SshHost)).is_ok());
|
||||
}
|
||||
|
||||
/// ### umount_new_ssh_key
|
||||
///
|
||||
/// Umount new ssh key prompt
|
||||
pub(crate) fn umount_new_ssh_key(&mut self) {
|
||||
let _ = self.app.umount(&Id::Ssh(IdSsh::SshUsername));
|
||||
let _ = self.app.umount(&Id::Ssh(IdSsh::SshHost));
|
||||
}
|
||||
|
||||
/// ### reload_ssh_keys
|
||||
///
|
||||
/// Reload ssh keys
|
||||
pub(crate) fn reload_ssh_keys(&mut self) {
|
||||
let keys: Vec<String> = self
|
||||
|
||||
@@ -35,8 +35,6 @@ use tuirealm::tui::layout::{Constraint, Direction, Layout};
|
||||
impl SetupActivity {
|
||||
// -- view
|
||||
|
||||
/// ### init_theme
|
||||
///
|
||||
/// Initialize thene view
|
||||
pub(super) fn init_theme(&mut self) {
|
||||
// Init view (and mount commons)
|
||||
@@ -298,8 +296,6 @@ impl SetupActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// ### load_styles
|
||||
///
|
||||
/// Load values from theme into input fields
|
||||
pub(crate) fn load_styles(&mut self) {
|
||||
let theme: Theme = self.theme().clone();
|
||||
|
||||
@@ -33,8 +33,6 @@ use crate::system::theme_provider::ThemeProvider;
|
||||
|
||||
use tuirealm::terminal::TerminalBridge;
|
||||
|
||||
/// ## Context
|
||||
///
|
||||
/// Context holds data structures shared by the activities
|
||||
pub struct Context {
|
||||
ft_params: Option<FileTransferParams>,
|
||||
@@ -46,8 +44,6 @@ pub struct Context {
|
||||
}
|
||||
|
||||
impl Context {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new Context
|
||||
pub fn new(
|
||||
config_client: ConfigClient,
|
||||
@@ -106,15 +102,11 @@ impl Context {
|
||||
|
||||
// -- error
|
||||
|
||||
/// ### set_error
|
||||
///
|
||||
/// Set context error
|
||||
pub fn set_error(&mut self, err: String) {
|
||||
self.error = Some(err);
|
||||
}
|
||||
|
||||
/// ### error
|
||||
///
|
||||
/// Get error message and remove it from the context
|
||||
pub fn error(&mut self) -> Option<String> {
|
||||
self.error.take()
|
||||
|
||||
@@ -31,8 +31,6 @@ use std::collections::HashMap;
|
||||
|
||||
// -- store state
|
||||
|
||||
/// ## StoreState
|
||||
///
|
||||
/// Store state describes a value in the store
|
||||
#[allow(dead_code)]
|
||||
enum StoreState {
|
||||
@@ -46,8 +44,6 @@ enum StoreState {
|
||||
|
||||
// -- store
|
||||
|
||||
/// ## Store
|
||||
///
|
||||
/// Store represent the context store
|
||||
/// The store is a key-value hash map. Each key must be unique
|
||||
/// To each key a `StoreState` is assigned
|
||||
@@ -57,8 +53,6 @@ pub(crate) struct Store {
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Store {
|
||||
/// ### init
|
||||
///
|
||||
/// Initialize a new Store
|
||||
pub fn init() -> Self {
|
||||
Store {
|
||||
@@ -68,8 +62,6 @@ impl Store {
|
||||
|
||||
// -- getters
|
||||
|
||||
/// ### get_string
|
||||
///
|
||||
/// Get string from store
|
||||
pub fn get_string(&self, key: &str) -> Option<&str> {
|
||||
match self.store.get(key) {
|
||||
@@ -78,8 +70,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_signed
|
||||
///
|
||||
/// Get signed from store
|
||||
pub fn get_signed(&self, key: &str) -> Option<isize> {
|
||||
match self.store.get(key) {
|
||||
@@ -88,8 +78,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_unsigned
|
||||
///
|
||||
/// Get unsigned from store
|
||||
pub fn get_unsigned(&self, key: &str) -> Option<usize> {
|
||||
match self.store.get(key) {
|
||||
@@ -98,8 +86,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_float
|
||||
///
|
||||
/// get float from store
|
||||
pub fn get_float(&self, key: &str) -> Option<f64> {
|
||||
match self.store.get(key) {
|
||||
@@ -108,8 +94,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_boolean
|
||||
///
|
||||
/// get boolean from store
|
||||
pub fn get_boolean(&self, key: &str) -> Option<bool> {
|
||||
match self.store.get(key) {
|
||||
@@ -118,8 +102,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### isset
|
||||
///
|
||||
/// Check if a state is set in the store
|
||||
pub fn isset(&self, key: &str) -> bool {
|
||||
self.store.get(key).is_some()
|
||||
@@ -127,44 +109,32 @@ impl Store {
|
||||
|
||||
// -- setters
|
||||
|
||||
/// ### set_string
|
||||
///
|
||||
/// Set string into the store
|
||||
pub fn set_string(&mut self, key: &str, val: String) {
|
||||
self.store.insert(key.to_string(), StoreState::Str(val));
|
||||
}
|
||||
|
||||
/// ### set_signed
|
||||
///
|
||||
/// Set signed number
|
||||
pub fn set_signed(&mut self, key: &str, val: isize) {
|
||||
self.store.insert(key.to_string(), StoreState::Signed(val));
|
||||
}
|
||||
|
||||
/// ### set_signed
|
||||
///
|
||||
/// Set unsigned number
|
||||
pub fn set_unsigned(&mut self, key: &str, val: usize) {
|
||||
self.store
|
||||
.insert(key.to_string(), StoreState::Unsigned(val));
|
||||
}
|
||||
|
||||
/// ### set_float
|
||||
///
|
||||
/// Set floating point number
|
||||
pub fn set_float(&mut self, key: &str, val: f64) {
|
||||
self.store.insert(key.to_string(), StoreState::Float(val));
|
||||
}
|
||||
|
||||
/// ### set_boolean
|
||||
///
|
||||
/// Set boolean
|
||||
pub fn set_boolean(&mut self, key: &str, val: bool) {
|
||||
self.store.insert(key.to_string(), StoreState::Boolean(val));
|
||||
}
|
||||
|
||||
/// ### set
|
||||
///
|
||||
/// Set a key as a flag; has no value
|
||||
pub fn set(&mut self, key: &str) {
|
||||
self.store.insert(key.to_string(), StoreState::Flag);
|
||||
@@ -172,8 +142,6 @@ impl Store {
|
||||
|
||||
// -- Consumers
|
||||
|
||||
/// ### take_string
|
||||
///
|
||||
/// Take string from store
|
||||
pub fn take_string(&mut self, key: &str) -> Option<String> {
|
||||
match self.store.remove(key) {
|
||||
@@ -182,8 +150,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### take_signed
|
||||
///
|
||||
/// Take signed from store
|
||||
pub fn take_signed(&mut self, key: &str) -> Option<isize> {
|
||||
match self.store.remove(key) {
|
||||
@@ -192,8 +158,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### take_unsigned
|
||||
///
|
||||
/// Take unsigned from store
|
||||
pub fn take_unsigned(&mut self, key: &str) -> Option<usize> {
|
||||
match self.store.remove(key) {
|
||||
@@ -202,8 +166,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_float
|
||||
///
|
||||
/// Take float from store
|
||||
pub fn take_float(&mut self, key: &str) -> Option<f64> {
|
||||
match self.store.remove(key) {
|
||||
@@ -212,8 +174,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_boolean
|
||||
///
|
||||
/// Take boolean from store
|
||||
pub fn take_boolean(&mut self, key: &str) -> Option<bool> {
|
||||
match self.store.remove(key) {
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
// Ext
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
|
||||
/// ## random_alphanumeric_with_len
|
||||
///
|
||||
/// Generate a random alphanumeric string with provided length
|
||||
pub fn random_alphanumeric_with_len(len: usize) -> String {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
Reference in New Issue
Block a user