@@ -21,13 +21,12 @@ mod app;
2121mod assets;
2222mod diff;
2323mod printer;
24+mod style;
2425mod terminal;
2526
26−use std::collections::HashSet;
2727use std::fs::{self, File};
2828use std::io::{self, BufRead, BufReader, Write};
2929use std::process::{self, Child, Command, Stdio};
30−use std::str::FromStr;
3130
3231#[cfg(unix)]
3332use std::os::unix::fs::FileTypeExt;
@@ -50,102 +49,11 @@ mod errors {
5049 Clap(::clap::Error);
5150 Io(::std::io::Error);
5251 }
53−
54− errors {
55− NoCorrectStylesSpecified {
56− description("no correct styles specified")
57− }
58−
59− UnknownStyleName(name: String) {
60− description("unknown style name")
61− display("unknown style name: '{}'", name)
62− }
63− }
6452 }
6553}
6654
6755use errors::*;
6856
69−#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
70−pub enum OutputComponent {
71− Auto,
72− Changes,
73− Grid,
74− Header,
75− Numbers,
76− Full,
77− Plain,
78−}
79−
80−impl OutputComponent {
81− fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
82− match *self {
83− OutputComponent::Auto => if interactive_terminal {
84− OutputComponent::Full.components(interactive_terminal)
85− } else {
86− OutputComponent::Plain.components(interactive_terminal)
87− },
88− OutputComponent::Changes => &[OutputComponent::Changes],
89− OutputComponent::Grid => &[OutputComponent::Grid],
90− OutputComponent::Header => &[OutputComponent::Header],
91− OutputComponent::Numbers => &[OutputComponent::Numbers],
92− OutputComponent::Full => &[
93− OutputComponent::Changes,
94− OutputComponent::Grid,
95− OutputComponent::Header,
96− OutputComponent::Numbers,
97− ],
98− OutputComponent::Plain => &[],
99− }
100− }
101−}
102−
103−impl FromStr for OutputComponent {
104− type Err = Error;
105−
106− fn from_str(s: &str) -> Result<Self> {
107− match s {
108− "auto" => Ok(OutputComponent::Auto),
109− "changes" => Ok(OutputComponent::Changes),
110− "grid" => Ok(OutputComponent::Grid),
111− "header" => Ok(OutputComponent::Header),
112− "numbers" => Ok(OutputComponent::Numbers),
113− "full" => Ok(OutputComponent::Full),
114− "plain" => Ok(OutputComponent::Plain),
115− _ => Err(ErrorKind::UnknownStyleName(s.to_owned()).into()),
116− }
117− }
118−}
119−
120−pub struct OutputComponents(HashSet<OutputComponent>);
121−
122−impl OutputComponents {
123− fn changes(&self) -> bool {
124− self.0.contains(&OutputComponent::Changes)
125− }
126−
127− fn grid(&self) -> bool {
128− self.0.contains(&OutputComponent::Grid)
129− }
130−
131− fn header(&self) -> bool {
132− self.0.contains(&OutputComponent::Header)
133− }
134−
135− fn numbers(&self) -> bool {
136− self.0.contains(&OutputComponent::Numbers)
137− }
138−}
139−
140−pub struct Options<'a> {
141− pub true_color: bool,
142− pub output_components: OutputComponents,
143− pub language: Option<&'a str>,
144− pub colored_output: bool,
145− pub paging: bool,
146− pub term_width: usize,
147−}
148−
14957enum OutputType {
15058 Pager(Child),
15159 Stdout(io::Stdout),