From a304370df4f998f7054731bac173113f91bf5cb1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 6 Apr 2020 14:43:28 +0200 Subject: implement guild display & filtering options Filtering based on guilds is slow, as it will have to retrieve every guild name from the GW2 API, and it has to parse every log file instead of bailing early. Therefore, guilds are not searched by default, and have to be explicitely turned on with --guilds. In addition, this means that raidgrep will now need network access when --guilds is passed, which was not the case before. --- src/output/formats.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/output/formats.rs') diff --git a/src/output/formats.rs b/src/output/formats.rs index 5915069..b697401 100644 --- a/src/output/formats.rs +++ b/src/output/formats.rs @@ -2,6 +2,7 @@ use std::fmt::Write; use super::{LogResult, FightOutcome}; +use super::super::guilds; /// An output format pub trait Format: Sync + Send { @@ -12,7 +13,9 @@ pub trait Format: Sync + Send { /// The human readable, colored format. #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] -pub struct HumanReadable; +pub struct HumanReadable { + pub show_guilds: bool, +} impl Format for HumanReadable { @@ -35,14 +38,26 @@ impl Format for HumanReadable { outcome, ).unwrap(); for player in &item.players { - writeln!( + write!( result, - " {:2} {:20} {:19} {}", + " {:2} {:20} {:19} {:12}", player.subgroup, player.account_name.yellow(), player.character_name.cyan(), - player.profession + player.profession, ).unwrap(); + if self.show_guilds { + let guild = player.guild_id.as_ref().and_then(|id| guilds::lookup(id)); + if let Some(guild) = guild { + write!( + result, + " [{}] {}", + guild.tag().magenta(), + guild.name().magenta(), + ).unwrap(); + } + } + writeln!(result).unwrap(); } result } -- cgit v1.2.3