diff --git a/Cargo.lock b/Cargo.lock index d69dd85..fcdae6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1812,13 +1812,27 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.5", "tokio", "tower-service", "tracing", "want", ] +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http", + "hyper", + "rustls", + "tokio", + "tokio-rustls", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -2963,6 +2977,16 @@ dependencies = [ "futures-io", ] +[[package]] +name = "piston_rs" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "156a44794feea1834eaf5dbf3a8c31d3f7bae829d5a6145403605d64b843127b" +dependencies = [ + "reqwest", + "serde", +] + [[package]] name = "pkg-config" version = "0.3.28" @@ -3031,6 +3055,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" name = "precise_age_calculator_rs" version = "0.1.0" dependencies = [ + "piston_rs", "reqwest", "slint", "slint-build", @@ -3242,6 +3267,7 @@ dependencies = [ "http", "http-body", "hyper", + "hyper-rustls", "hyper-tls", "ipnet", "js-sys", @@ -3251,17 +3277,21 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", + "rustls", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", "system-configuration", "tokio", "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "winreg", ] @@ -3384,6 +3414,15 @@ dependencies = [ "sct", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64", +] + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -4095,6 +4134,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.10" diff --git a/Cargo.toml b/Cargo.toml index 3706d3e..940ddc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +piston_rs = "0.4.3" reqwest = "0.11.23" slint = "1.0" diff --git a/src/main.rs b/src/main.rs index e62704b..0fc6c9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ use std::{string, collections::HashMap}; +use piston_rs; +use reqwest::Response; slint::include_modules!(); use std::collections::HashMap; @@ -7,10 +9,32 @@ use std::collections::HashMap; //bussiness logic in this case compiling the code fn main() -> Result<(), slint::PlatformError> { let ui = AppWindow::new()?; - let ui_handle = ui.as_weak(); ui.compile_code_rs(move |string,string,string| { let ui = ui_handle.unwrap(); + let client = piston_rs::Client::new(); + let executor = piston_rs::Executor::new() + .set_language("rust") + .set_version("*") + .add_file(piston_rs::File::default() + .set_name("main.rs") + .set_content(ui.get_code) + ); + + match client.execute(&executor) { + Ok(response) => { + print!("Language : Rust {}",response.version); + if let Some(c) = &response.compile{ + ui.set_stderr(response.compile) + } + ui.set_stdout(response.run.output); + } + Err(err) => { + ui.set_stderr("Something bad happend, its from our side, sorry, {:?}",err); + } + } + + // let URL = "https://play.rust-lang.org/execute"; // let mut data : HashMap<&str,&str> = HashMap::new(); diff --git a/ui/appwindow.slint b/ui/appwindow.slint index 4ba4b52..fb0b1a0 100644 --- a/ui/appwindow.slint +++ b/ui/appwindow.slint @@ -1,26 +1,8 @@ import { TextEdit , VerticalBox,Button, GroupBox, HorizontalBox} from "std-widgets.slint"; - -component MainCodeEditor { - -} - -component CompileTimeWarnings { - -} - -component CompileButton { - -} - -component ResultCompiled { - -} - - export component Example inherits Window { background: #131516; width: 1080px; - height: 690px; + height: 400px; in-out property code: "//hello world! I'm Krusty the Krab and i like money lol. \n \n//Insert your rusty code over here and i will do the rest\n \n//Also,I tell NO to code that asks input from user \n \n \nfn main(){\n //write code here\n}"; out property stderr: "//Compile time warnings \n \n let him start cooking!!"; @@ -35,9 +17,9 @@ export component Example inherits Window { spacing: 10px; MainCode := TextEdit { - font-size: 21px; - width: parent.width; - height: 400px; + font-size: 18px; + width: 80%; + height: 300px; text: code; } @@ -49,13 +31,16 @@ export component Example inherits Window { primary: true; clicked => { //compile code logic - self.text = "Compiled"; + self.text = "Compiling"; self.primary = !self.primary; - compile_code_rs(MainCode.text,StdErr.text,StdOut.text); + stderr = "He is cooking, wait patiently...!"; + stdout = "Wait until he brings the meal..."; + // compile_code_rs(MainCode.text,StdErr.text,StdOut.text); + self.text = "Compiled"; } } - HorizontalBox { + OutputSection := HorizontalBox { padding: 10px; StdErr := TextEdit {