aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2018-09-07 00:07:16 +0200
committerDaniel <kingdread@gmx.de>2018-09-07 00:07:16 +0200
commitb94272563e98ca268bcee800533ce851cce9c604 (patch)
treed510e70e85987a0bd47b1c1749b4366f31ecb3b8 /src/main.rs
parent92cc9192081a3fa5cc9e5846dfe7118f5b87ae42 (diff)
downloadraidgrep-b94272563e98ca268bcee800533ce851cce9c604.tar.gz
raidgrep-b94272563e98ca268bcee800533ce851cce9c604.tar.bz2
raidgrep-b94272563e98ca268bcee800533ce851cce9c604.zip
move output formatting to submodule
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 6 insertions, 31 deletions
diff --git a/src/main.rs b/src/main.rs
index 502d98e..c776336 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,9 +7,8 @@ extern crate evtclib;
extern crate regex;
extern crate walkdir;
-use std::fmt;
use std::fs::File;
-use std::io::BufReader;
+use std::io::{self, BufReader};
use std::path::PathBuf;
use std::str::FromStr;
@@ -23,6 +22,8 @@ use evtclib::{AgentKind, AgentName, EventKind, Log};
mod errors;
use errors::RuntimeError;
+mod output;
+
#[derive(StructOpt, Debug)]
#[structopt(name = "raidgrep")]
struct Opt {
@@ -66,7 +67,7 @@ impl FromStr for SearchField {
}
#[derive(Debug, Clone)]
-struct LogResult {
+pub struct LogResult {
log_file: PathBuf,
time: NaiveDateTime,
boss_name: String,
@@ -74,39 +75,13 @@ struct LogResult {
}
#[derive(Debug, Clone)]
-struct Player {
+pub struct Player {
account_name: String,
character_name: String,
profession: String,
subgroup: u8,
}
-impl fmt::Display for LogResult {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use colored::Colorize;
- writeln!(f, "{}: {:?}", "File".green(), self.log_file)?;
- writeln!(
- f,
- "{}: {} - {}: {}",
- "Date".green(),
- self.time,
- "Boss".green(),
- self.boss_name
- )?;
- for player in &self.players {
- writeln!(
- f,
- " {:2} {:20} {:19} {}",
- player.subgroup,
- player.account_name.yellow(),
- player.character_name.cyan(),
- player.profession
- )?;
- }
- Ok(())
- }
-}
-
fn main() {
let opt = Opt::from_args();
let result = grep(&opt);
@@ -132,7 +107,7 @@ fn grep(opt: &Opt) -> Result<(), RuntimeError> {
let entry = entry?;
if is_log_file(&entry) {
if let Some(result) = search_log(&entry, opt)? {
- println!("{}", result);
+ output::colored(io::stdout(), &result)?;
}
}
}