use chrono::{Date, UTC, Datelike};
use git2::Oid;
use nom::{IResult, alpha, digit, space, rest};
use regex::{Regex, RegexBuilder};
use term;
use toml;
use toml::Value;
use std::collections::BTreeMap;
use std::fmt;
use std::fs::File;
use std::io::prelude::*;
use std::io;
use std::iter;
use std::str;
use config::Config;
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(Debug)]
pub enum Error {
CommitMessageLength,
FooterParsing(String),
Io(io::Error),
ParagraphParsing(String),
SummaryParsing(String),
Terminal,
Toml(toml::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::CommitMessageLength => write!(f, "Commit message length too small."),
Error::FooterParsing(ref line) => write!(f, "Footer parsing: '{}'", line),
Error::Io(ref e) => write!(f, "Io: {}", e),
Error::ParagraphParsing(ref line) => write!(f, "Paragraph parsing: '{}'", line),
Error::SummaryParsing(ref line) => write!(f, "Summary parsing: '{}'", line),
Error::Terminal => write!(f, "Could not print to terminal."),
Error::Toml(ref e) => write!(f, "Toml: {}", e),
}
}
}
impl From<term::Error> for Error {
fn from(_err: term::Error) -> Error {
Error::Terminal
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err)
}
}
impl From<toml::Error> for Error {
fn from(err: toml::Error) -> Error {
Error::Toml(err)
}
}
#[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, Error>
where F: Fn(&mut T) -> Result<(), Error>,
G: Fn(&mut T) -> Result<(), Error>,
H: Fn(&mut T) -> Result<(), Error>;
fn print_default<T: Write>(