mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
add markdown output for default command
This commit is contained in:
parent
e0ee5f1d7f
commit
1d495ff7b9
|
@ -7,3 +7,4 @@ authors = ["olivia <olivia@fastmail.com>"]
|
||||||
clap = "2.32.0"
|
clap = "2.32.0"
|
||||||
indicatif = "0.9.0"
|
indicatif = "0.9.0"
|
||||||
console = "0.6.2"
|
console = "0.6.2"
|
||||||
|
syntect = "3.0.2"
|
||||||
|
|
4
default_out.md
Normal file
4
default_out.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
## Welcome to Rustlings!
|
||||||
|
|
||||||
|
To get started, run `rustlings verify` in order to get the first exercise.
|
||||||
|
Make sure to have your editor open!
|
22
src/main.rs
22
src/main.rs
|
@ -2,15 +2,21 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate console;
|
extern crate console;
|
||||||
extern crate indicatif;
|
extern crate indicatif;
|
||||||
|
extern crate syntect;
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use indicatif::ProgressBar;
|
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::fs::remove_file;
|
||||||
|
use std::io::BufRead;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = App::new("r2")
|
let matches = App::new("rustlings")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.author("Olivia Hugger")
|
.author("Olivia Hugger")
|
||||||
.about("Test")
|
.about("Test")
|
||||||
|
@ -21,6 +27,9 @@ fn main() {
|
||||||
.arg(Arg::with_name("file").required(true).index(1)),
|
.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#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#);
|
println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#);
|
||||||
println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
|
println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
|
||||||
|
@ -130,6 +139,17 @@ fn main() {
|
||||||
compile_only("exercises/error_handling/option1.rs");
|
compile_only("exercises/error_handling/option1.rs");
|
||||||
test("exercises/error_handling/result1.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(®ions[..], true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\x1b[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_only(filename: &str) {
|
fn compile_only(filename: &str) {
|
||||||
|
|
Loading…
Reference in a new issue