mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Form submit
This commit is contained in:
@@ -67,7 +67,7 @@ pub struct AuthActivity {
|
|||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub form_submit: bool, // becomes true after user has submitted fields
|
pub form_submit: bool, // becomes true after user has submitted fields
|
||||||
pub esc_called: bool, // Becomes true if user has pressed esc
|
pub esc_called: bool, // Becomes true if user has pressed esc
|
||||||
selected_field: InputField,
|
selected_field: InputField,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,29 +113,59 @@ impl Activity for AuthActivity {
|
|||||||
match key.code {
|
match key.code {
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.esc_called = true;
|
self.esc_called = true;
|
||||||
break
|
break;
|
||||||
},
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
// TODO: handle submit (check form)
|
// Handle submit
|
||||||
},
|
// Check form
|
||||||
|
// Check address
|
||||||
|
if self.address.len() == 0 {
|
||||||
|
popup = Some(String::from("Invalid address"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Check port
|
||||||
|
// Convert port to number
|
||||||
|
match self.port.parse::<usize>() {
|
||||||
|
Ok(val) => {
|
||||||
|
if val > 65535 {
|
||||||
|
popup = Some(String::from(
|
||||||
|
"Specified port must be in range 0-65535",
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
popup =
|
||||||
|
Some(String::from("Specified port is not a number"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check username
|
||||||
|
if self.username.len() == 0 {
|
||||||
|
popup = Some(String::from("Invalid username"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Everything OK, set enter
|
||||||
|
self.form_submit = true;
|
||||||
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
// Pop last char
|
// Pop last char
|
||||||
match self.selected_field {
|
match self.selected_field {
|
||||||
InputField::Address => {
|
InputField::Address => {
|
||||||
let _ = self.address.pop();
|
let _ = self.address.pop();
|
||||||
},
|
}
|
||||||
InputField::Password => {
|
InputField::Password => {
|
||||||
let _ = self.password.pop();
|
let _ = self.password.pop();
|
||||||
},
|
}
|
||||||
InputField::Username => {
|
InputField::Username => {
|
||||||
let _ = self.username.pop();
|
let _ = self.username.pop();
|
||||||
},
|
}
|
||||||
InputField::Port => {
|
InputField::Port => {
|
||||||
let _ = self.port.pop();
|
let _ = self.port.pop();
|
||||||
},
|
}
|
||||||
_ => { /* Nothing to do */ }
|
_ => { /* Nothing to do */ }
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
KeyCode::Up => {
|
KeyCode::Up => {
|
||||||
// Move item up
|
// Move item up
|
||||||
self.selected_field = match self.selected_field {
|
self.selected_field = match self.selected_field {
|
||||||
@@ -145,7 +175,7 @@ impl Activity for AuthActivity {
|
|||||||
InputField::Username => InputField::Protocol,
|
InputField::Username => InputField::Protocol,
|
||||||
InputField::Password => InputField::Username,
|
InputField::Password => InputField::Username,
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
KeyCode::Down => {
|
KeyCode::Down => {
|
||||||
// Move item down
|
// Move item down
|
||||||
self.selected_field = match self.selected_field {
|
self.selected_field = match self.selected_field {
|
||||||
@@ -155,7 +185,7 @@ impl Activity for AuthActivity {
|
|||||||
InputField::Username => InputField::Password,
|
InputField::Username => InputField::Password,
|
||||||
InputField::Password => InputField::Password, // End of list
|
InputField::Password => InputField::Password, // End of list
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
KeyCode::Char(ch) => {
|
KeyCode::Char(ch) => {
|
||||||
match self.selected_field {
|
match self.selected_field {
|
||||||
InputField::Address => self.address.push(ch),
|
InputField::Address => self.address.push(ch),
|
||||||
@@ -166,10 +196,10 @@ impl Activity for AuthActivity {
|
|||||||
if ch.is_numeric() {
|
if ch.is_numeric() {
|
||||||
self.port.push(ch);
|
self.port.push(ch);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => { /* Nothing to do */ }
|
_ => { /* Nothing to do */ }
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
KeyCode::Left => {
|
KeyCode::Left => {
|
||||||
// If current field is Protocol handle event... (move element left)
|
// If current field is Protocol handle event... (move element left)
|
||||||
if self.selected_field == InputField::Protocol {
|
if self.selected_field == InputField::Protocol {
|
||||||
@@ -178,7 +208,7 @@ impl Activity for AuthActivity {
|
|||||||
ScpProtocol::Ftp => ScpProtocol::Sftp, // End of list
|
ScpProtocol::Ftp => ScpProtocol::Sftp, // End of list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
KeyCode::Right => {
|
KeyCode::Right => {
|
||||||
// If current field is Protocol handle event... ( move element right )
|
// If current field is Protocol handle event... ( move element right )
|
||||||
if self.selected_field == InputField::Protocol {
|
if self.selected_field == InputField::Protocol {
|
||||||
@@ -187,7 +217,7 @@ impl Activity for AuthActivity {
|
|||||||
ScpProtocol::Ftp => ScpProtocol::Ftp, // End of list
|
ScpProtocol::Ftp => ScpProtocol::Ftp, // End of list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => { /* Nothing to do */ }
|
_ => { /* Nothing to do */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user