Skip to content

Commit

Permalink
Made changes to main
Browse files Browse the repository at this point in the history
  • Loading branch information
vrn21 committed Jan 7, 2024
1 parent cb16ea5 commit d86c76b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 27 deletions.
51 changes: 50 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 25 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{string, collections::HashMap};
use piston_rs;
use reqwest::Response;

slint::include_modules!();
use std::collections::HashMap;
Expand All @@ -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();
Expand Down
35 changes: 10 additions & 25 deletions ui/appwindow.slint
Original file line number Diff line number Diff line change
@@ -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 <string> 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 <string> stderr: "//Compile time warnings \n \n let him start cooking!!";
Expand All @@ -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;
}

Expand All @@ -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 {
Expand Down

0 comments on commit d86c76b

Please sign in to comment.