summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-11-26 11:10:38 +0100
committerolivia <olivia@fastmail.com>2018-11-26 11:10:38 +0100
commit1d495ff7b9c0a9d638576558d409533e80ba2330 (patch)
treece629142652587ee299f311e83ff3f34f2db5748 /src
parente0ee5f1d7fd706705f169074356280ea8b245d69 (diff)
add markdown output for default command
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 1a085ef..e84dff7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,15 +2,21 @@
extern crate clap;
extern crate console;
extern crate indicatif;
+extern crate syntect;
use clap::{App, Arg, SubCommand};
use console::{style, Emoji};
use indicatif::ProgressBar;
+use syntect::easy::HighlightFile;
+use syntect::parsing::SyntaxSet;
+use syntect::highlighting::{ThemeSet, Style};
+use syntect::util::{as_24_bit_terminal_escaped, LinesWithEndings};
use std::fs::remove_file;
+use std::io::BufRead;
use std::process::Command;
fn main() {
- let matches = App::new("r2")
+ let matches = App::new("rustlings")
.version(crate_version!())
.author("Olivia Hugger")
.about("Test")
@@ -21,6 +27,9 @@ fn main() {
.arg(Arg::with_name("file").required(true).index(1)),
).get_matches();
+ let ss = SyntaxSet::load_defaults_newlines();
+ let ts = ThemeSet::load_defaults();
+
println!(r#" _ _ _ "#);
println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#);
println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
@@ -130,6 +139,17 @@ fn main() {
compile_only("exercises/error_handling/option1.rs");
test("exercises/error_handling/result1.rs");
}
+
+ if let None = matches.subcommand_name() {
+ let mut highlighter = HighlightFile::new("default_out.md", &ss, &ts.themes["Solarized (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);
+ println!("{}", as_24_bit_terminal_escaped(&regions[..], true));
+ }
+ }
+
+ println!("\x1b[0m");
}
fn compile_only(filename: &str) {