1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// `error_chain!` can recurse deeply
#![recursion_limit = "1024"]

#[macro_use]
extern crate derive_builder;

#[macro_use]
extern crate error_chain;

#[macro_use]
extern crate clap;

#[macro_use]
extern crate lazy_static;

extern crate ansi_term;
extern crate atty;
extern crate console;
extern crate content_inspector;
extern crate directories;
extern crate encoding;
extern crate shell_words;
extern crate syntect;

mod assets;
mod builder;
mod decorations;
mod dirs;
mod inputfile;
mod line_range;
mod output;
mod preprocessor;
mod printer;
mod style;
mod syntax_mapping;
mod terminal;

pub use builder::{PagingMode, PrettyPrint, PrettyPrinter};
// pub use style::OutputComponent;

mod errors {
    error_chain! {
        foreign_links {
            Clap(::clap::Error);
            Io(::std::io::Error);
            SyntectError(::syntect::LoadingError);
            ParseIntError(::std::num::ParseIntError);
        }
    }
}

pub use errors::Error as PrettyPrintError;

#[cfg(test)]
mod tests {
    use super::*;

    /// Pretty prints its own code
    #[test]
    fn it_works() {
        let printer = PrettyPrinter::default().build().unwrap();
        printer.file("fixtures/fib.rs").unwrap();
    }

    /// Pretty prints its own code with some more formatting shenanigans
    #[test]
    fn it_works_with_output_opts() {
        let printer = PrettyPrinter::default()
            .line_numbers(true)
            .header(true)
            .grid(true)
            .paging_mode(PagingMode::Never)
            .language("ruby")
            .build()
            .unwrap();

        let example = r#"
        def fib(n)        
            return 1 if n <= 1
            fib(n-1) + fib(n-2)
        end
        "#;
        printer.string_with_header(example, "example.rb").unwrap();
    }

    /// Show available syntax highlighting themes
    #[test]
    fn show_themes() {
        let printer = PrettyPrinter::default().build().unwrap();
        assert!(printer.get_themes().len() > 0);
        println!("{:?}", printer.get_themes().keys());
    }
}