@@ -21,25 +21,26 @@ mod app;
2121mod assets;
2222mod decorations;
2323mod diff;
24+mod output;
2425mod printer;
2526mod style;
2627mod terminal;
2728
2829use std::fs::{self, File};
29−use std::io::{self, BufRead, BufReader, Write};
30+use std::io::{self, BufRead, BufReader};
3031use std::path::Path;
31−use std::process::{self, Child, Command, Stdio};
32+use std::process;
3233
33−use ansi_term::Colour::{Fixed, Green, Red, White, Yellow};
34−use ansi_term::Style;
34+use ansi_term::Colour::{Green, Red};
3535
3636use syntect::easy::HighlightLines;
3737use syntect::highlighting::Theme;
3838use syntect::parsing::SyntaxDefinition;
3939
40−use app::{App, PagingMode};
40+use app::App;
4141use assets::{config_dir, syntax_set_path, theme_set_path, HighlightingAssets};
4242use diff::get_git_diff;
43+use output::OutputType;
4344use printer::Printer;
4445
4546mod errors {
@@ -53,88 +54,6 @@ mod errors {
5354
5455use errors::*;
5556
56−enum OutputType {
57− Pager(Child),
58− Stdout(io::Stdout),
59−}
60−
61−impl OutputType {
62− fn from_mode(mode: PagingMode) -> Self {
63− use PagingMode::*;
64− match mode {
65− Always => OutputType::try_pager(false),
66− QuitIfOneScreen => OutputType::try_pager(true),
67− _ => OutputType::stdout(),
68− }
69− }
70−
71− /// Try to launch the pager. Fall back to stdout in case of errors.
72− fn try_pager(quit_if_one_screen: bool) -> Self {
73− let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
74− if quit_if_one_screen {
75− args.push("--quit-if-one-screen");
76− }
77− Command::new("less")
78− .args(&args)
79− .stdin(Stdio::piped())
80− .spawn()
81− .map(OutputType::Pager)
82− .unwrap_or_else(|_| OutputType::stdout())
83− }
84−
85− fn stdout() -> Self {
86− OutputType::Stdout(io::stdout())
87− }
88−
89− fn handle(&mut self) -> Result<&mut Write> {
90− Ok(match *self {
91− OutputType::Pager(ref mut command) => command
92− .stdin
93− .as_mut()
94− .chain_err(|| "Could not open stdin for pager")?,
95− OutputType::Stdout(ref mut handle) => handle,
96− })
97− }
98−}
99−
100−impl Drop for OutputType {
101− fn drop(&mut self) {
102− if let OutputType::Pager(ref mut command) = *self {
103− let _ = command.wait();
104− }
105− }
106−}
107−
108−const GRID_COLOR: u8 = 238;
109−const LINE_NUMBER_COLOR: u8 = 244;
110−
111−#[derive(Default)]
112−pub struct Colors {
113− pub grid: Style,
114− pub filename: Style,
115− pub git_added: Style,
116− pub git_removed: Style,
117− pub git_modified: Style,
118− pub line_number: Style,
119−}
120−
121−impl Colors {
122− fn plain() -> Self {
123− Colors::default()
124− }
125−
126− fn colored() -> Self {
127− Colors {
128− grid: Fixed(GRID_COLOR).normal(),
129− filename: White.bold(),
130− git_added: Green.normal(),
131− git_removed: Red.normal(),
132− git_modified: Yellow.normal(),
133− line_number: Fixed(LINE_NUMBER_COLOR).normal(),
134− }
135− }
136−}
137−
13857fn print_file(
13958 theme: &Theme,
14059 syntax: &SyntaxDefinition,