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.
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct TemplateApp {
// Example stuff:
label: String,
deets: SshDeets,
// this how you opt-out of serialization of a member
#[serde(skip)]
value: f32,
}
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)]
pub struct SshDeets {
dns: bool,
user: String,
ip: String,
port: String,
mask: Option<String>,
pub dns: bool,
pub user: String,
pub ip: String,
pub port: String,
pub mask: String,
}
impl Default for SshDeets {
fn default() -> Self {
Self {
dns: true,
user: String::from("No"),
ip: String::from("127.0.0.1"),
port: String::from("8080"),
mask: None,
user: "No".to_owned(),
ip: "127.0.0.1".to_owned(),
port: "8080".to_owned(),
mask: "".to_owned(),
}
}
}
@ -36,27 +41,26 @@ impl SshDeets {
username: &str,
ip_addy: &str,
port_num: &str,
masking: Option<String>) -> Self
masking: String) -> Self
{
let balling = Self {
Self {
dns: yeah,
user: String::from(username),
ip: String::from(ip_addy),
port: String::from(port_num),
mask: masking,
};
balling
}
}
pub fn concat(self, connect: bool) -> Vec<String> {
let mut final_thing: Vec<String> = vec![];
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("-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(self.mask.unwrap());
final_thing.push(self.mask);
return final_thing;
}
else {
@ -72,6 +76,7 @@ impl Default for TemplateApp {
fn default() -> Self {
Self {
// Example stuff:
deets: SshDeets::default(),
label: "Hello World!".to_owned(),
value: 2.7,
}
@ -103,8 +108,9 @@ impl eframe::App for TemplateApp {
/// 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`.
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.
// Pick whichever suits you.
// Tip: a good default choice is to just keep the `CentralPanel`.
@ -152,25 +158,37 @@ impl eframe::App for TemplateApp {
egui::CentralPanel::default().show(ctx, |ui| {
// 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.label("check if using --dns flag");
ui.checkbox(&mut deets.dns, "dns'd");
ui.text_edit_singleline(label);
ui.heading("eframe template");
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.add(egui::github_link_file!(
"https://github.com/emilk/eframe_template/blob/master/",
"Source code."
));
)); */
egui::warn_if_debug_build(ui);
});
if false {
egui::Window::new("Window").show(ctx, |ui| {
ui.label("Windows can be moved by dragging them.");
ui.label("They are automatically sized based on contents.");
ui.label("You can turn on resizing and scrolling if you like.");
ui.label("You would normally chose either panels OR windows.");
});
}
Window::new("info")
.anchor(egui::Align2::RIGHT_TOP, [-5.0,5.0])
.default_size([500.0,500.0])
.show(ctx, |ui| {
ui.label("Make sure you have ssh keys, no password connecting!");
});
}
}