summaryrefslogtreecommitdiff
path: root/src/run.rs
diff options
context:
space:
mode:
authorliv <liv@fastmail.com>2019-01-09 20:33:43 +0100
committerliv <liv@fastmail.com>2019-01-09 20:33:43 +0100
commita388bb3798e2595c47924c6e4128f10e00cfc705 (patch)
tree66b3503a37c567e7cee67a3522103a88541a6978 /src/run.rs
parent679508b278643f5ce3796cafb512a03df61939c7 (diff)
split codebase
Diffstat (limited to 'src/run.rs')
-rw-r--r--src/run.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/run.rs b/src/run.rs
new file mode 100644
index 0000000..9605370
--- /dev/null
+++ b/src/run.rs
@@ -0,0 +1,49 @@
+use console::{style, Emoji};
+use indicatif::ProgressBar;
+use std::process::Command;
+use crate::util::clean;
+
+pub fn run(matches: clap::ArgMatches) {
+ if let Some(filename) = matches.value_of("file") {
+ let bar = ProgressBar::new_spinner();
+ bar.set_message(format!("Compiling {}...", filename).as_str());
+ bar.enable_steady_tick(100);
+ let compilecmd = Command::new("rustc")
+ .args(&[filename, "-o", "temp"])
+ .output()
+ .expect("fail");
+ bar.set_message(format!("Running {}...", filename).as_str());
+ if compilecmd.status.success() {
+ let runcmd = Command::new("./temp").output().expect("fail");
+ bar.finish_and_clear();
+
+ if runcmd.status.success() {
+ println!("{}", String::from_utf8_lossy(&runcmd.stdout));
+ let formatstr =
+ format!("{} Successfully ran {}", Emoji("✅", "✓"), filename);
+ println!("{}", style(formatstr).green());
+ clean();
+ } else {
+ println!("{}", String::from_utf8_lossy(&runcmd.stdout));
+ println!("{}", String::from_utf8_lossy(&runcmd.stderr));
+
+ let formatstr =
+ format!("{} Ran {} with errors", Emoji("⚠️ ", "!"), filename);
+ println!("{}", style(formatstr).red());
+ clean();
+ }
+ } else {
+ bar.finish_and_clear();
+ let formatstr = format!(
+ "{} Compilation of {} failed! Compiler error message:\n",
+ Emoji("⚠️ ", "!"),
+ filename
+ );
+ println!("{}", style(formatstr).red());
+ println!("{}", String::from_utf8_lossy(&compilecmd.stderr));
+ clean();
+ }
+ } else {
+ panic!("Please supply a filename!");
+ }
+}