Switch to colored because termion isn't supported on windows

pull/1/head
trivernis 4 years ago
parent 3c88632548
commit 70e5cb68ea

48
Cargo.lock generated

@ -94,6 +94,16 @@ dependencies = [
"vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "colored"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crc32fast"
version = "1.2.0"
@ -225,11 +235,6 @@ dependencies = [
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "numtoa"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "onig"
version = "6.0.0"
@ -308,19 +313,6 @@ dependencies = [
"proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.3.9"
@ -382,9 +374,10 @@ dependencies = [
[[package]]
name = "snekdown"
version = "0.10.0"
version = "0.10.1"
dependencies = [
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -392,7 +385,6 @@ dependencies = [
"regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"syntect 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -463,17 +455,6 @@ dependencies = [
"yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
"numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -588,6 +569,7 @@ dependencies = [
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
"checksum colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
"checksum flate2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2cfff41391129e0a856d6d822600b8d71179d46879e310417eb9c762eb178b42"
@ -607,7 +589,6 @@ dependencies = [
"checksum miniz_oxide 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aa679ff6578b1cddee93d7e82e263b94a575e0bfced07284eb0c037c1d2416a5"
"checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum onig 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd91ccd8a02fce2f7e8a86655aec67bc6c171e6f8e704118a0e8c4b866a05a8a"
"checksum onig_sys 69.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3814583fad89f3c60ae0701d80e87e1fd3028741723deda72d0d4a0ecf0cb0db"
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
@ -616,8 +597,6 @@ dependencies = [
"checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
"checksum proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101"
"checksum quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
"checksum regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
"checksum ryu 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1"
@ -632,7 +611,6 @@ dependencies = [
"checksum syn 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "bb37da98a55b1d08529362d9cbb863be17556873df2585904ab9d2bc951291d0"
"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
"checksum syntect 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83b43a6ca1829ccb0c933b615c9ea83ffc8793ae240cecbd15119b13d741161d"
"checksum termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.10.0"
version = "0.10.1"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"
@ -19,10 +19,10 @@ path = "src/main.rs"
[dependencies]
crossbeam-utils = "0.7.2"
structopt = "0.3.14"
termion = "1.5.5"
minify = "1.1.1"
htmlescape = "0.3.1"
syntect = "4.2.0"
chrono = "0.4.11"
regex = "1.3.9"
lazy_static = "1.4.0"
lazy_static = "1.4.0"
colored = "1.9.3"

@ -2,11 +2,10 @@ use snekdown::format::html::ToHtml;
use snekdown::Parser;
use std::fs::write;
use std::time::Instant;
use termion::style;
use colored::Colorize;
use std::path::PathBuf;
use structopt::StructOpt;
use termion::color::{Fg, Red};
#[derive(StructOpt, Debug)]
struct Opt {
@ -22,22 +21,33 @@ fn main() {
let opt: Opt = Opt::from_args();
if !opt.input.exists() {
println!(
"{}The input file {} could not be found{}",
Fg(Red),
opt.input.to_str().unwrap(),
style::Reset
"{}",
format!(
"The input file {} could not be found",
opt.input.to_str().unwrap()
)
.red()
);
return;
}
let start = Instant::now();
let mut parser = Parser::new_from_file(opt.input.to_str().unwrap().to_string()).unwrap();
let document = parser.parse();
println!("{}Parsing took: {:?}", style::Italic, start.elapsed());
println!(
"{}",
format!("Parsing took: {:?}", start.elapsed()).italic()
);
let start_render = Instant::now();
match opt.format.as_str() {
"html" => write(opt.output.to_str().unwrap(), document.to_html()).unwrap(),
_ => println!("Unknown format {}", opt.format),
}
println!("Rendering took: {:?}", start_render.elapsed());
println!("Total: {:?}{}", start.elapsed(), style::Reset);
println!(
"{}",
format!("Rendering took: {:?}", start_render.elapsed()).italic()
);
println!(
"{}",
format!("Total: {:?}", start.elapsed()).italic()
);
}

@ -3,6 +3,7 @@ use super::tokens::*;
use crate::parsing::charstate::CharStateMachine;
use crate::parsing::inline::ParseInline;
use crate::parsing::placeholders::ProcessPlaceholders;
use colored::*;
use crossbeam_utils::sync::WaitGroup;
use std::collections::HashMap;
use std::error::Error;
@ -13,8 +14,6 @@ use std::io;
use std::path::Path;
use std::sync::{Arc, Mutex};
use std::thread;
use termion::color::{self, Fg};
use termion::style;
macro_rules! parse_option {
($option:expr, $index:expr) => {
@ -35,19 +34,14 @@ impl Display for ParseError {
if let Some(message) = &self.message {
write!(
f,
"{} Parse Error at index {}: {}{}",
Fg(color::Red),
self.index,
message,
style::Reset
"{}",
format!("Parse Error at index {}: {}", self.index, message).red()
)
} else {
write!(
f,
"{} Parse Error at index {}{}",
Fg(color::Red),
self.index,
style::Reset
"{}",
format!("Parse Error at index {}", self.index).red()
)
}
}
@ -184,10 +178,8 @@ impl Parser {
let path_info = Path::new(&path);
if !path_info.exists() || !path_info.is_file() {
println!(
"{}Import of \"{}\" failed: The file doesn't exist.{}",
Fg(color::Yellow),
path,
style::Reset
"{}",
format!("Import of \"{}\" failed: The file doesn't exist.", path,).red()
);
return Err(ParseError::new_with_message(
self.index,
@ -198,10 +190,8 @@ impl Parser {
let mut paths = self.paths.lock().unwrap();
if paths.iter().find(|item| **item == path) != None {
println!(
"{}Import of \"{}\" failed: Cyclic import.{}",
Fg(color::Yellow),
path,
style::Reset
"{}",
format!("Import of \"{}\" failed: Cyclic import.", path).yellow()
);
return Err(ParseError::new_with_message(self.index, "cyclic import"));
}
@ -236,15 +226,15 @@ impl Parser {
if let Some(path) = &self.path {
if let Some(position) = err.get_position(&self.get_text()) {
println!(
"{} Error in File {}:{}:{} - {}",
Fg(color::Red),
path,
position.0,
position.1,
err
"{}",
format!(
"Error in File {}:{}:{} - {}",
path, position.0, position.1, err
)
.red()
);
} else {
println!("{} Error in File {}: {}", Fg(color::Red), path, err);
println!("{}", format!("Error in File {}: {}", path, err).red());
}
} else {
println!("{}", err);

Loading…
Cancel
Save