diff options
author | Daniel <kingdread@gmx.de> | 2020-04-06 14:43:28 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-04-06 14:43:28 +0200 |
commit | a304370df4f998f7054731bac173113f91bf5cb1 (patch) | |
tree | aab806f530e8871dbc35368e021485dc02265c54 /src/output/formats.rs | |
parent | f7a0f17ce47e15f4cb39b49fecf4e252ce7897c3 (diff) | |
download | raidgrep-a304370df4f998f7054731bac173113f91bf5cb1.tar.gz raidgrep-a304370df4f998f7054731bac173113f91bf5cb1.tar.bz2 raidgrep-a304370df4f998f7054731bac173113f91bf5cb1.zip |
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.
Diffstat (limited to 'src/output/formats.rs')
-rw-r--r-- | src/output/formats.rs | 23 |
1 files changed, 19 insertions, 4 deletions
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 } |