From ee43377a9cc20498021c1205e6826cc501425dcc Mon Sep 17 00:00:00 2001 From: Ezinwa Okpoechi Date: Mon, 21 May 2018 15:00:00 +0200 Subject: [PATCH] Move colors to printer module --- src/decorations.rs | 3 +-- src/printer.rs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/decorations.rs b/src/decorations.rs index bd557064..40c4d80e 100644 --- a/src/decorations.rs +++ b/src/decorations.rs @@ -1,7 +1,6 @@ use ansi_term::Style; use diff::LineChange; -use printer::Printer; -use Colors; +use printer::{Colors, Printer}; #[derive(Clone)] pub struct DecorationText { diff --git a/src/printer.rs b/src/printer.rs index 8334e496..912d0148 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,3 +1,5 @@ +use ansi_term::Colour::{Fixed, Green, Red, White, Yellow}; +use ansi_term::Style; use app::Config; use console::AnsiCodeIterator; use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration}; @@ -9,7 +11,6 @@ use std::vec::Vec; use style::OutputWrap; use syntect::highlighting; use terminal::as_terminal_escaped; -use Colors; pub struct Printer<'a> { handle: &'a mut Write, @@ -252,3 +253,33 @@ impl<'a> Printer<'a> { Ok(()) } } + +const GRID_COLOR: u8 = 238; +const LINE_NUMBER_COLOR: u8 = 244; + +#[derive(Default)] +pub struct Colors { + pub grid: Style, + pub filename: Style, + pub git_added: Style, + pub git_removed: Style, + pub git_modified: Style, + pub line_number: Style, +} + +impl Colors { + fn plain() -> Self { + Colors::default() + } + + fn colored() -> Self { + Colors { + grid: Fixed(GRID_COLOR).normal(), + filename: White.bold(), + git_added: Green.normal(), + git_removed: Red.normal(), + git_modified: Yellow.normal(), + line_number: Fixed(LINE_NUMBER_COLOR).normal(), + } + } +}