on master help sign in
Move colors to printer module
commitee43377a9cc20498021c1205e6826cc501425dcc authorEzinwa Okpoechi <brainmaestro@outlook.com> dateMon 21 May 2018, 15:00 (8 years ago) parent120b33a
2 files changed+33−3
src/decorations.rs+1−2 src/printer.rs+32−1
src/decorations.rs+1−2
@@ -1,7 +1,6 @@
11use ansi_term::Style;
22use diff::LineChange;
3−use printer::Printer;
4−use Colors;
3+use printer::{Colors, Printer};
54
65#[derive(Clone)]
76pub struct DecorationText {
src/printer.rs+32−1
@@ -1,3 +1,5 @@
1+use ansi_term::Colour::{Fixed, Green, Red, White, Yellow};
2+use ansi_term::Style;
13use app::Config;
24use console::AnsiCodeIterator;
35use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration};
@@ -9,7 +11,6 @@ use std::vec::Vec;
911use style::OutputWrap;
1012use syntect::highlighting;
1113use terminal::as_terminal_escaped;
12−use Colors;
1314
1415pub struct Printer<'a> {
1516 handle: &'a mut Write,
@@ -252,3 +253,33 @@ impl<'a> Printer<'a> {
252253 Ok(())
253254 }
254255}
256+
257+const GRID_COLOR: u8 = 238;
258+const LINE_NUMBER_COLOR: u8 = 244;
259+
260+#[derive(Default)]
261+pub struct Colors {
262+ pub grid: Style,
263+ pub filename: Style,
264+ pub git_added: Style,
265+ pub git_removed: Style,
266+ pub git_modified: Style,
267+ pub line_number: Style,
268+}
269+
270+impl Colors {
271+ fn plain() -> Self {
272+ Colors::default()
273+ }
274+
275+ fn colored() -> Self {
276+ Colors {
277+ grid: Fixed(GRID_COLOR).normal(),
278+ filename: White.bold(),
279+ git_added: Green.normal(),
280+ git_removed: Red.normal(),
281+ git_modified: Yellow.normal(),
282+ line_number: Fixed(LINE_NUMBER_COLOR).normal(),
283+ }
284+ }
285+}