mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Remote directory path in authentication form and in bookmarks parameters
This commit is contained in:
committed by
Christian Visintin
parent
e0d8b80cdf
commit
2caa0432df
@@ -171,6 +171,12 @@ impl AuthActivity {
|
||||
// Load parameters into components
|
||||
self.protocol = bookmark.protocol;
|
||||
self.mount_protocol(bookmark.protocol);
|
||||
self.mount_remote_directory(
|
||||
bookmark
|
||||
.entry_directory
|
||||
.map(|x| x.to_string_lossy().to_string())
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
match bookmark.params {
|
||||
ProtocolParams::AwsS3(params) => self.load_bookmark_s3_into_gui(params),
|
||||
ProtocolParams::Generic(params) => self.load_bookmark_generic_into_gui(params),
|
||||
|
||||
@@ -112,6 +112,42 @@ impl Component<Msg, NoUserEvent> for ProtocolRadio {
|
||||
}
|
||||
}
|
||||
|
||||
// -- remote directory
|
||||
|
||||
#[derive(MockComponent)]
|
||||
pub struct InputRemoteDirectory {
|
||||
component: Input,
|
||||
}
|
||||
|
||||
impl InputRemoteDirectory {
|
||||
pub fn new(remote_dir: &str, color: Color) -> Self {
|
||||
Self {
|
||||
component: Input::default()
|
||||
.borders(
|
||||
Borders::default()
|
||||
.color(color)
|
||||
.modifiers(BorderType::Rounded),
|
||||
)
|
||||
.foreground(color)
|
||||
.placeholder("/home/foo", Style::default().fg(Color::Rgb(128, 128, 128)))
|
||||
.title("Default remote directory", Alignment::Left)
|
||||
.input_type(InputType::Text)
|
||||
.value(remote_dir),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Component<Msg, NoUserEvent> for InputRemoteDirectory {
|
||||
fn on(&mut self, ev: Event<NoUserEvent>) -> Option<Msg> {
|
||||
handle_input_ev(
|
||||
self,
|
||||
ev,
|
||||
Msg::Ui(UiMsg::RemoteDirectoryBlurDown),
|
||||
Msg::Ui(UiMsg::RemoteDirectoryBlurUp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// -- address
|
||||
|
||||
#[derive(MockComponent)]
|
||||
|
||||
@@ -37,8 +37,8 @@ pub use bookmarks::{
|
||||
RecentsList,
|
||||
};
|
||||
pub use form::{
|
||||
InputAddress, InputPassword, InputPort, InputS3AccessKey, InputS3Bucket, InputS3Endpoint,
|
||||
InputS3Profile, InputS3Region, InputS3SecretAccessKey, InputS3SecurityToken,
|
||||
InputAddress, InputPassword, InputPort, InputRemoteDirectory, InputS3AccessKey, InputS3Bucket,
|
||||
InputS3Endpoint, InputS3Profile, InputS3Region, InputS3SecretAccessKey, InputS3SecurityToken,
|
||||
InputS3SessionToken, InputUsername, ProtocolRadio, RadioS3NewPathStyle,
|
||||
};
|
||||
pub use popup::{
|
||||
|
||||
@@ -78,7 +78,7 @@ impl AuthActivity {
|
||||
Ok(FileTransferParams {
|
||||
protocol,
|
||||
params: ProtocolParams::Generic(params),
|
||||
entry_directory: None,
|
||||
entry_directory: self.get_input_remote_directory(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ impl AuthActivity {
|
||||
Ok(FileTransferParams {
|
||||
protocol: FileTransferProtocol::AwsS3,
|
||||
params: ProtocolParams::AwsS3(params),
|
||||
entry_directory: None,
|
||||
entry_directory: self.get_input_remote_directory(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ pub enum Id {
|
||||
Protocol,
|
||||
QuitPopup,
|
||||
RecentsList,
|
||||
RemoteDirectory,
|
||||
S3AccessKey,
|
||||
S3Bucket,
|
||||
S3Endpoint,
|
||||
@@ -125,6 +126,8 @@ pub enum UiMsg {
|
||||
ProtocolBlurDown,
|
||||
ProtocolBlurUp,
|
||||
RececentsListBlur,
|
||||
RemoteDirectoryBlurDown,
|
||||
RemoteDirectoryBlurUp,
|
||||
S3AccessKeyBlurDown,
|
||||
S3AccessKeyBlurUp,
|
||||
S3BucketBlurDown,
|
||||
|
||||
@@ -178,7 +178,7 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::BookmarksList).is_ok());
|
||||
}
|
||||
UiMsg::PasswordBlurDown => {
|
||||
assert!(self.app.active(&Id::Protocol).is_ok());
|
||||
assert!(self.app.active(&Id::RemoteDirectory).is_ok());
|
||||
}
|
||||
UiMsg::PasswordBlurUp => {
|
||||
assert!(self.app.active(&Id::Username).is_ok());
|
||||
@@ -199,6 +199,15 @@ impl AuthActivity {
|
||||
.is_ok());
|
||||
}
|
||||
UiMsg::ProtocolBlurUp => {
|
||||
assert!(self.app.active(&Id::RemoteDirectory).is_ok());
|
||||
}
|
||||
UiMsg::RececentsListBlur => {
|
||||
assert!(self.app.active(&Id::BookmarksList).is_ok());
|
||||
}
|
||||
UiMsg::RemoteDirectoryBlurDown => {
|
||||
assert!(self.app.active(&Id::Protocol).is_ok());
|
||||
}
|
||||
UiMsg::RemoteDirectoryBlurUp => {
|
||||
assert!(self
|
||||
.app
|
||||
.active(match self.input_mask() {
|
||||
@@ -207,9 +216,6 @@ impl AuthActivity {
|
||||
})
|
||||
.is_ok());
|
||||
}
|
||||
UiMsg::RececentsListBlur => {
|
||||
assert!(self.app.active(&Id::BookmarksList).is_ok());
|
||||
}
|
||||
UiMsg::S3BucketBlurDown => {
|
||||
assert!(self.app.active(&Id::S3Region).is_ok());
|
||||
}
|
||||
@@ -259,7 +265,7 @@ impl AuthActivity {
|
||||
assert!(self.app.active(&Id::S3SecurityToken).is_ok());
|
||||
}
|
||||
UiMsg::S3NewPathStyleBlurDown => {
|
||||
assert!(self.app.active(&Id::Protocol).is_ok());
|
||||
assert!(self.app.active(&Id::RemoteDirectory).is_ok());
|
||||
}
|
||||
UiMsg::S3NewPathStyleBlurUp => {
|
||||
assert!(self.app.active(&Id::S3SessionToken).is_ok());
|
||||
|
||||
@@ -31,6 +31,7 @@ use crate::filetransfer::params::{AwsS3Params, GenericProtocolParams, ProtocolPa
|
||||
use crate::filetransfer::FileTransferParams;
|
||||
use crate::utils::ui::draw_area_in;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use tuirealm::tui::layout::{Constraint, Direction, Layout};
|
||||
use tuirealm::tui::widgets::Clear;
|
||||
@@ -67,6 +68,7 @@ impl AuthActivity {
|
||||
let default_protocol: FileTransferProtocol = self.context().config().get_default_protocol();
|
||||
// Auth form
|
||||
self.mount_protocol(default_protocol);
|
||||
self.mount_remote_directory("");
|
||||
self.mount_address("");
|
||||
self.mount_port(Self::get_default_port_for_protocol(default_protocol));
|
||||
self.mount_username("");
|
||||
@@ -165,6 +167,7 @@ impl AuthActivity {
|
||||
Constraint::Length(3), // region
|
||||
Constraint::Length(3), // profile
|
||||
Constraint::Length(3), // access_key
|
||||
Constraint::Length(3), // remote directory
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
@@ -177,6 +180,7 @@ impl AuthActivity {
|
||||
Constraint::Length(3), // port
|
||||
Constraint::Length(3), // username
|
||||
Constraint::Length(3), // password
|
||||
Constraint::Length(3), // remote directory
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
@@ -197,17 +201,18 @@ impl AuthActivity {
|
||||
// Render input mask
|
||||
match self.input_mask() {
|
||||
InputMask::AwsS3 => {
|
||||
let s3_view_ids = self.get_s3_view();
|
||||
self.app.view(&s3_view_ids[0], f, input_mask[0]);
|
||||
self.app.view(&s3_view_ids[1], f, input_mask[1]);
|
||||
self.app.view(&s3_view_ids[2], f, input_mask[2]);
|
||||
self.app.view(&s3_view_ids[3], f, input_mask[3]);
|
||||
let view_ids = self.get_s3_view();
|
||||
self.app.view(&view_ids[0], f, input_mask[0]);
|
||||
self.app.view(&view_ids[1], f, input_mask[1]);
|
||||
self.app.view(&view_ids[2], f, input_mask[2]);
|
||||
self.app.view(&view_ids[3], f, input_mask[3]);
|
||||
}
|
||||
InputMask::Generic => {
|
||||
self.app.view(&Id::Address, f, input_mask[0]);
|
||||
self.app.view(&Id::Port, f, input_mask[1]);
|
||||
self.app.view(&Id::Username, f, input_mask[2]);
|
||||
self.app.view(&Id::Password, f, input_mask[3]);
|
||||
let view_ids = self.get_generic_params_view();
|
||||
self.app.view(&view_ids[0], f, input_mask[0]);
|
||||
self.app.view(&view_ids[1], f, input_mask[1]);
|
||||
self.app.view(&view_ids[2], f, input_mask[2]);
|
||||
self.app.view(&view_ids[3], f, input_mask[3]);
|
||||
}
|
||||
}
|
||||
// Bookmark chunks
|
||||
@@ -563,6 +568,21 @@ impl AuthActivity {
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
pub(super) fn mount_remote_directory<S: AsRef<str>>(&mut self, entry_directory: S) {
|
||||
let protocol_color = self.theme().auth_protocol;
|
||||
assert!(self
|
||||
.app
|
||||
.remount(
|
||||
Id::RemoteDirectory,
|
||||
Box::new(components::InputRemoteDirectory::new(
|
||||
entry_directory.as_ref(),
|
||||
protocol_color
|
||||
)),
|
||||
vec![]
|
||||
)
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
pub(super) fn mount_address(&mut self, address: &str) {
|
||||
let addr_color = self.theme().auth_address;
|
||||
assert!(self
|
||||
@@ -754,6 +774,15 @@ impl AuthActivity {
|
||||
.new_path_style(new_path_style)
|
||||
}
|
||||
|
||||
pub(super) fn get_input_remote_directory(&self) -> Option<PathBuf> {
|
||||
match self.app.state(&Id::RemoteDirectory) {
|
||||
Ok(State::One(StateValue::String(x))) if !x.is_empty() => {
|
||||
Some(PathBuf::from(x.as_str()))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn get_input_addr(&self) -> String {
|
||||
match self.app.state(&Id::Address) {
|
||||
Ok(State::One(StateValue::String(x))) => x,
|
||||
@@ -913,26 +942,52 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the visible element in the generic params form, based on current focus
|
||||
fn get_generic_params_view(&self) -> [Id; 4] {
|
||||
match self.app.focus() {
|
||||
Some(&Id::RemoteDirectory) => {
|
||||
[Id::Port, Id::Username, Id::Password, Id::RemoteDirectory]
|
||||
}
|
||||
_ => [Id::Address, Id::Port, Id::Username, Id::Password],
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the visible element in the aws-s3 form, based on current focus
|
||||
fn get_s3_view(&self) -> [Id; 4] {
|
||||
match self.app.focus() {
|
||||
Some(&Id::S3AccessKey) => [
|
||||
Some(&Id::S3AccessKey) => {
|
||||
[Id::S3Region, Id::S3Endpoint, Id::S3Profile, Id::S3AccessKey]
|
||||
}
|
||||
Some(&Id::S3SecretAccessKey) => [
|
||||
Id::S3Endpoint,
|
||||
Id::S3Profile,
|
||||
Id::S3AccessKey,
|
||||
Id::S3SecretAccessKey,
|
||||
],
|
||||
Some(&Id::S3SecurityToken) => [
|
||||
Id::S3Profile,
|
||||
Id::S3AccessKey,
|
||||
Id::S3SecretAccessKey,
|
||||
Id::S3SecurityToken,
|
||||
],
|
||||
Some(&Id::S3SessionToken) => [
|
||||
Id::S3AccessKey,
|
||||
Id::S3SecretAccessKey,
|
||||
Id::S3SecurityToken,
|
||||
Id::S3SessionToken,
|
||||
],
|
||||
Some(
|
||||
&Id::S3SecretAccessKey
|
||||
| &Id::S3SecurityToken
|
||||
| &Id::S3SessionToken
|
||||
| &Id::S3NewPathStyle,
|
||||
) => [
|
||||
Some(&Id::S3NewPathStyle) => [
|
||||
Id::S3SecretAccessKey,
|
||||
Id::S3SecurityToken,
|
||||
Id::S3SessionToken,
|
||||
Id::S3NewPathStyle,
|
||||
],
|
||||
Some(&Id::RemoteDirectory) => [
|
||||
Id::S3SecurityToken,
|
||||
Id::S3SessionToken,
|
||||
Id::S3NewPathStyle,
|
||||
Id::RemoteDirectory,
|
||||
],
|
||||
_ => [Id::S3Bucket, Id::S3Region, Id::S3Endpoint, Id::S3Profile],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user