ui and shenanigans

This commit is contained in:
gallant 2022-10-04 17:38:15 -05:00
parent 7da5e13b91
commit 5f7e3081e0

View file

@ -1,31 +1,36 @@
use egui::Window;
use crate::connect_ssh;
/// We derive Deserialize/Serialize so we can persist app state on shutdown. /// We derive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(serde::Deserialize, serde::Serialize)] #[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state #[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct TemplateApp { pub struct TemplateApp {
// Example stuff: // Example stuff:
label: String, label: String,
deets: SshDeets,
// this how you opt-out of serialization of a member // this how you opt-out of serialization of a member
#[serde(skip)] #[serde(skip)]
value: f32, value: f32,
} }
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)]
pub struct SshDeets { pub struct SshDeets {
dns: bool, pub dns: bool,
user: String, pub user: String,
ip: String, pub ip: String,
port: String, pub port: String,
mask: Option<String>, pub mask: String,
} }
impl Default for SshDeets { impl Default for SshDeets {
fn default() -> Self { fn default() -> Self {
Self { Self {
dns: true, dns: true,
user: String::from("No"), user: "No".to_owned(),
ip: String::from("127.0.0.1"), ip: "127.0.0.1".to_owned(),
port: String::from("8080"), port: "8080".to_owned(),
mask: None, mask: "".to_owned(),
} }
} }
} }
@ -36,27 +41,26 @@ impl SshDeets {
username: &str, username: &str,
ip_addy: &str, ip_addy: &str,
port_num: &str, port_num: &str,
masking: Option<String>) -> Self masking: String) -> Self
{ {
let balling = Self { Self {
dns: yeah, dns: yeah,
user: String::from(username), user: String::from(username),
ip: String::from(ip_addy), ip: String::from(ip_addy),
port: String::from(port_num), port: String::from(port_num),
mask: masking, mask: masking,
}; }
balling
} }
pub fn concat(self, connect: bool) -> Vec<String> { pub fn concat(self, connect: bool) -> Vec<String> {
let mut final_thing: Vec<String> = vec![]; let mut final_thing: Vec<String> = vec![];
if connect == false{ if connect == false{
if self.dns == true && self.mask != None{ if self.dns == true {
final_thing.push(String::from("--dns")); final_thing.push(String::from("--dns"));
final_thing.push(String::from("-Nr")); final_thing.push(String::from("-Nr"));
final_thing.push(format!("{}@{}", self.user, self.ip)); final_thing.push(format!("{}:{}", self.user, self.ip));
final_thing.push(String::from("-x")); final_thing.push(String::from("-x"));
final_thing.push(self.mask.unwrap()); final_thing.push(self.mask);
return final_thing; return final_thing;
} }
else { else {
@ -72,6 +76,7 @@ impl Default for TemplateApp {
fn default() -> Self { fn default() -> Self {
Self { Self {
// Example stuff: // Example stuff:
deets: SshDeets::default(),
label: "Hello World!".to_owned(), label: "Hello World!".to_owned(),
value: 2.7, value: 2.7,
} }
@ -103,7 +108,8 @@ impl eframe::App for TemplateApp {
/// Called each time the UI needs repainting, which may be many times per second. /// Called each time the UI needs repainting, which may be many times per second.
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let Self { label, value } = self; let Self { label, value, deets } = self;
// Examples of how to create different panels and windows. // Examples of how to create different panels and windows.
// Pick whichever suits you. // Pick whichever suits you.
@ -152,25 +158,37 @@ impl eframe::App for TemplateApp {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
// The central panel the region left after adding TopPanel's and SidePanel's // The central panel the region left after adding TopPanel's and SidePanel's
ui.label("put your linux ssh username, ip, and port (does not have to be root)");
ui.text_edit_singleline(&mut deets.user);
ui.text_edit_singleline(&mut deets.ip);
ui.text_edit_singleline(&mut deets.port);
ui.text_edit_singleline(label); ui.label("check if using --dns flag");
ui.heading("eframe template"); ui.checkbox(&mut deets.dns, "dns'd");
ui.label("include mask flags");
ui.text_edit_singleline(&mut deets.mask);
if ui.button("connect").clicked() {
//connect_ssh(false, *deets);
}
/* ui.heading("eframe template");
ui.hyperlink("https://github.com/emilk/eframe_template"); ui.hyperlink("https://github.com/emilk/eframe_template");
ui.add(egui::github_link_file!( ui.add(egui::github_link_file!(
"https://github.com/emilk/eframe_template/blob/master/", "https://github.com/emilk/eframe_template/blob/master/",
"Source code." "Source code."
)); )); */
egui::warn_if_debug_build(ui); egui::warn_if_debug_build(ui);
}); });
if false {
egui::Window::new("Window").show(ctx, |ui| { Window::new("info")
ui.label("Windows can be moved by dragging them."); .anchor(egui::Align2::RIGHT_TOP, [-5.0,5.0])
ui.label("They are automatically sized based on contents."); .default_size([500.0,500.0])
ui.label("You can turn on resizing and scrolling if you like."); .show(ctx, |ui| {
ui.label("You would normally chose either panels OR windows."); ui.label("Make sure you have ssh keys, no password connecting!");
}); });
}
} }
} }