use chrono::{Date, UTC, Datelike};
use git2::Oid;
use nom::{IResult, alpha, digit, space, rest};
use regex::{Regex, RegexBuilder};
use term;
use toml::{self, Value};
use std::collections::BTreeMap;
use std::fs::File;
use std::io::prelude::*;
use std::{iter, str};
use config::Config;
use errors::*;
pub static TOML_DEFAULT_KEY: &'static str = "default";
pub static TOML_FOOTERS_KEY: &'static str = "footers";
pub static TOML_NAME_KEY: &'static str = "name";
pub static TOML_TAG: &'static str = "tag";
pub static TOML_TEXT_KEY: &'static str = "text";
pub static TOML_ONCE_KEY: &'static str = "once";
pub static TOML_HEADER_KEY: &'static str = "header";
pub static TOML_FOOTER_KEY: &'static str = "footer";
#[derive(PartialEq)]
pub enum Printed {
Nothing,
Something,
}
pub trait Print {
fn print<T: Write, F, G, H>(&self,
t: &mut T,
config: &Config,
tag: Option<&str>,
c1: &F,
c2: &G,
c3: &H)
-> Result<Printed>
where F: Fn(&mut T) -> Result<()>,
G: Fn(&mut T) -> Result<()>,
H: Fn(&mut T) -> Result<()>;
fn print_default<T: Write>(&self, t: &mut T, config: &Config, tag: Option<&str>) -> Result<()> {
self.print(t, config, tag, &|_| Ok(()), &|_| Ok(()), &|_| Ok(()))?;
Ok(())
}
fn print_default_term(&self,
mut t: &mut Box<term::StdoutTerminal>,
config: &Config,
tag: Option<&str>)
-> Result<()> {
self.print(&mut t,
config,
tag,
&|t| {
t.fg(term::color::BRIGHT_BLUE)?;
Ok(())
},
&|t| {
t.fg(term::color::WHITE)?;
Ok(())
},
&|t| {
t.reset()?;
Ok(())
})?;
Ok(())
}
fn contains_tag(&self, tag: Option<&str>) -> bool;
fn contains_untagged_elements(&self) -> bool;
fn matches_default_tag(&self, tag: Option<&str>) -> bool {
match tag {
Some(tag) => tag == TOML_DEFAULT_KEY && self.contains_untagged_elements(),
None => false,
}
}
fn should_be_printed(&self, tag: Option<&str>) -> bool {
self.contains_tag(tag) || self.matches_default_tag(tag)
}
fn print_to_term_and_write_to_vector(&self