mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-23 03:38:09 -05:00
rustfmt
This commit is contained in:
parent
a388bb3798
commit
e03a98cbf6
3 changed files with 25 additions and 28 deletions
39
src/main.rs
39
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),
|
||||
}
|
||||
|
|
12
src/run.rs
12
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();
|
||||
}
|
||||
|
|
|
@ -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")?;
|
||||
|
|
Loading…
Reference in a new issue