mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
SetupActivity ok
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
// Locals
|
// Locals
|
||||||
use super::{Color, Popup, SetupActivity};
|
use super::{Color, Popup, SetupActivity};
|
||||||
// Ext
|
// Ext
|
||||||
|
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
impl SetupActivity {
|
impl SetupActivity {
|
||||||
@@ -103,6 +104,14 @@ impl SetupActivity {
|
|||||||
// Prepare text editor
|
// Prepare text editor
|
||||||
env::set_var("EDITOR", cli.get_text_editor());
|
env::set_var("EDITOR", cli.get_text_editor());
|
||||||
let placeholder: String = format!("# Type private SSH key for {}@{}\n", username, host);
|
let placeholder: String = format!("# Type private SSH key for {}@{}\n", username, host);
|
||||||
|
// Put input mode back to normal
|
||||||
|
let _ = disable_raw_mode();
|
||||||
|
// Leave alternate mode
|
||||||
|
if let Some(ctx) = self.context.as_mut() {
|
||||||
|
ctx.leave_alternate_screen();
|
||||||
|
}
|
||||||
|
// Re-enable raw mode
|
||||||
|
let _ = enable_raw_mode();
|
||||||
// Write key to file
|
// Write key to file
|
||||||
match edit::edit(placeholder.as_bytes()) {
|
match edit::edit(placeholder.as_bytes()) {
|
||||||
Ok(rsa_key) => {
|
Ok(rsa_key) => {
|
||||||
@@ -111,16 +120,16 @@ impl SetupActivity {
|
|||||||
if rsa_key.is_empty() {
|
if rsa_key.is_empty() {
|
||||||
// Report error: empty key
|
// Report error: empty key
|
||||||
self.popup = Some(Popup::Alert(Color::Red, format!("SSH Key is empty")));
|
self.popup = Some(Popup::Alert(Color::Red, format!("SSH Key is empty")));
|
||||||
return;
|
} else {
|
||||||
}
|
// Add key
|
||||||
// Add key
|
if let Err(err) =
|
||||||
if let Err(err) =
|
self.add_ssh_key(host.as_str(), username.as_str(), rsa_key.as_str())
|
||||||
self.add_ssh_key(host.as_str(), username.as_str(), rsa_key.as_str())
|
{
|
||||||
{
|
self.popup = Some(Popup::Alert(
|
||||||
self.popup = Some(Popup::Alert(
|
Color::Red,
|
||||||
Color::Red,
|
format!("Could not create new private key: {}", err),
|
||||||
format!("Could not create new private key: {}", err),
|
))
|
||||||
))
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -131,6 +140,13 @@ impl SetupActivity {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Restore terminal
|
||||||
|
if let Some(ctx) = self.context.as_mut() {
|
||||||
|
// Clear screen
|
||||||
|
ctx.clear_screen();
|
||||||
|
// Enter alternate mode
|
||||||
|
ctx.enter_alternate_screen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
use super::{ConfigClient, Popup, SetupActivity};
|
use super::{ConfigClient, Popup, SetupActivity};
|
||||||
use crate::system::environment;
|
use crate::system::environment;
|
||||||
// Ext
|
// Ext
|
||||||
|
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -119,6 +120,12 @@ impl SetupActivity {
|
|||||||
Some(cli) => {
|
Some(cli) => {
|
||||||
// Set text editor
|
// Set text editor
|
||||||
env::set_var("EDITOR", cli.get_text_editor());
|
env::set_var("EDITOR", cli.get_text_editor());
|
||||||
|
// Prepare terminal
|
||||||
|
let _ = disable_raw_mode();
|
||||||
|
// Leave alternate mode
|
||||||
|
if let Some(ctx) = self.context.as_mut() {
|
||||||
|
ctx.leave_alternate_screen();
|
||||||
|
}
|
||||||
// Check if key exists
|
// Check if key exists
|
||||||
match cli.iter_ssh_keys().nth(self.ssh_key_idx) {
|
match cli.iter_ssh_keys().nth(self.ssh_key_idx) {
|
||||||
Some(key) => {
|
Some(key) => {
|
||||||
@@ -128,8 +135,30 @@ impl SetupActivity {
|
|||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
Some((_, _, key_path)) => match edit::edit_file(key_path.as_path())
|
Some((_, _, key_path)) => match edit::edit_file(key_path.as_path())
|
||||||
{
|
{
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => {
|
||||||
Err(err) => Err(format!("Could not edit ssh key: {}", err)),
|
// Restore terminal
|
||||||
|
if let Some(ctx) = self.context.as_mut() {
|
||||||
|
// Clear screen
|
||||||
|
ctx.clear_screen();
|
||||||
|
// Enter alternate mode
|
||||||
|
ctx.enter_alternate_screen();
|
||||||
|
}
|
||||||
|
// Re-enable raw mode
|
||||||
|
let _ = enable_raw_mode();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
// Restore terminal
|
||||||
|
if let Some(ctx) = self.context.as_mut() {
|
||||||
|
// Clear screen
|
||||||
|
ctx.clear_screen();
|
||||||
|
// Enter alternate mode
|
||||||
|
ctx.enter_alternate_screen();
|
||||||
|
}
|
||||||
|
// Re-enable raw mode
|
||||||
|
let _ = enable_raw_mode();
|
||||||
|
Err(format!("Could not edit ssh key: {}", err))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Err(err) => Err(format!("Could not read ssh key: {}", err)),
|
Err(err) => Err(format!("Could not read ssh key: {}", err)),
|
||||||
|
|||||||
@@ -409,6 +409,7 @@ impl SetupActivity {
|
|||||||
Block::default()
|
Block::default()
|
||||||
.borders(Borders::TOP | Borders::RIGHT | Borders::LEFT)
|
.borders(Borders::TOP | Borders::RIGHT | Borders::LEFT)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
|
.style(Style::default().fg(Color::White))
|
||||||
.title("Host name or address"),
|
.title("Host name or address"),
|
||||||
);
|
);
|
||||||
let username: Paragraph = Paragraph::new(self.user_input.get(1).unwrap().as_str())
|
let username: Paragraph = Paragraph::new(self.user_input.get(1).unwrap().as_str())
|
||||||
@@ -418,8 +419,9 @@ impl SetupActivity {
|
|||||||
}))
|
}))
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.borders(Borders::TOP | Borders::RIGHT | Borders::LEFT)
|
.borders(Borders::BOTTOM | Borders::RIGHT | Borders::LEFT)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
|
.style(Style::default().fg(Color::White))
|
||||||
.title("Username"),
|
.title("Username"),
|
||||||
);
|
);
|
||||||
(address, username)
|
(address, username)
|
||||||
|
|||||||
Reference in New Issue
Block a user