From e03a98cbf6491dcf36e8a96fda20764bc1e1748e Mon Sep 17 00:00:00 2001 From: liv Date: Wed, 9 Jan 2019 20:33:58 +0100 Subject: [PATCH] rustfmt --- src/main.rs | 39 +++++++++++++++++++-------------------- src/run.rs | 12 +++++------- src/verify.rs | 2 +- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0fc0692..c229e0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,19 @@ -use clap::{App, Arg, SubCommand, crate_version}; -use syntect::easy::HighlightFile; -use syntect::parsing::SyntaxSet; -use syntect::highlighting::{ThemeSet, Style}; -use syntect::util::{as_24_bit_terminal_escaped}; +use crate::run::run; +use crate::verify::verify; +use clap::{crate_version, App, Arg, SubCommand}; +use notify::DebouncedEvent; +use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use std::io::BufRead; use std::sync::mpsc::channel; use std::time::Duration; -use notify::DebouncedEvent; -use notify::{RecommendedWatcher, Watcher, RecursiveMode}; -use crate::verify::verify; -use crate::run::run; +use syntect::easy::HighlightFile; +use syntect::highlighting::{Style, ThemeSet}; +use syntect::parsing::SyntaxSet; +use syntect::util::as_24_bit_terminal_escaped; mod run; -mod verify; mod util; +mod verify; fn main() { let matches = App::new("rustlings") @@ -26,11 +26,12 @@ fn main() { SubCommand::with_name("run") .alias("r") .arg(Arg::with_name("file").required(true).index(1)), - ).get_matches(); + ) + .get_matches(); let ss = SyntaxSet::load_defaults_newlines(); let ts = ThemeSet::load_defaults(); - + println!(r#" _ _ _ "#); println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#); println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#); @@ -55,7 +56,8 @@ fn main() { } if let None = matches.subcommand_name() { - let mut highlighter = HighlightFile::new("default_out.md", &ss, &ts.themes["base16-eighties.dark"]).unwrap(); + let mut highlighter = + HighlightFile::new("default_out.md", &ss, &ts.themes["base16-eighties.dark"]).unwrap(); for maybe_line in highlighter.reader.lines() { let line = maybe_line.unwrap(); let regions: Vec<(Style, &str)> = highlighter.highlight_lines.highlight(&line, &ss); @@ -76,14 +78,11 @@ fn watch() -> notify::Result<()> { loop { match rx.recv() { - Ok(event) => { - match event { - DebouncedEvent::Chmod(_) - | DebouncedEvent::Write(_) => { - let _ignored = verify(); - } - _ => {} + Ok(event) => match event { + DebouncedEvent::Chmod(_) | DebouncedEvent::Write(_) => { + let _ignored = verify(); } + _ => {} }, Err(e) => println!("watch error: {:?}", e), } diff --git a/src/run.rs b/src/run.rs index 9605370..093d1e4 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,7 +1,7 @@ +use crate::util::clean; 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") { @@ -16,19 +16,17 @@ pub fn run(matches: clap::ArgMatches) { 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); + 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); + + let formatstr = format!("{} Ran {} with errors", Emoji("⚠️ ", "!"), filename); println!("{}", style(formatstr).red()); clean(); } diff --git a/src/verify.rs b/src/verify.rs index e4a1d2a..4da1562 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,7 +1,7 @@ +use crate::util::clean; use console::{style, Emoji}; use indicatif::ProgressBar; use std::process::Command; -use crate::util::clean; pub fn verify() -> Result<(), ()> { compile_only("exercises/ex1.rs")?;