This commit is contained in:
liv 2019-01-09 20:33:58 +01:00
parent a388bb3798
commit e03a98cbf6
3 changed files with 25 additions and 28 deletions

View file

@ -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,7 +26,8 @@ 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();
@ -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),
}

View file

@ -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") {
@ -19,16 +19,14 @@ pub fn run(matches: clap::ArgMatches) {
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();
}

View file

@ -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")?;