From: MegaBrutal Date: Tue, 21 Feb 2023 02:20:55 +0000 (+0100) Subject: Cosmetic changes in output X-Git-Url: http://git.megabrutal.com/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=hlquery.git Cosmetic changes in output --- diff --git a/src/main.rs b/src/main.rs index 6e87bad..d9e2a27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,13 +72,17 @@ impl HLQueryResult { } const PAD_WIDTH: usize = 25; +const SEP_WIDTH: usize = 60; impl Display for HLQueryResult { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + writeln!(f, "{}", "=".repeat(SEP_WIDTH))?; write_datapoint!(f, PAD_WIDTH, "Address:", self.address)?; + writeln!(f, "{}", "=".repeat(SEP_WIDTH))?; + match &self.info { Ok(info) => { - writeln!(f, "\nServer info:")?; + writeln!(f, "\n* Server info: *\n")?; write_datapoint!(f, PAD_WIDTH, "Server name:", info.name)?; write_datapoint!(f, PAD_WIDTH, "Game:", info.game)?; write_datapoint!(f, PAD_WIDTH, "Folder:", info.folder)?; @@ -101,36 +105,39 @@ impl Display for HLQueryResult { write_datapoint!(f, PAD_WIDTH, "Source TV port:", SourceTVInfo(&info.source_tv))?; }, Err(e) => - writeln!(f, "Failed to query server info:\t{}", e)? + writeln!(f, "\nFailed to query server info:\t{}", e)? } match &self.rules { Ok(rules) => { - writeln!(f, "\nGame rules (CVARs):")?; + writeln!(f, "\n\n* Game rules (CVARs): *\n")?; for rule in rules { write_datapoint!(f, PAD_WIDTH, rule.name, format!("\"{}\"", rule.value))?; } } Err(e) => - writeln!(f, "Failed to query game rules:\t{}", e)? + writeln!(f, "\nFailed to query game rules:\t{}", e)? } match &self.players { Ok(players) => { - writeln!(f, "\nPlayers:")?; - writeln!(f, "\t{:>3} players online.", players.len())?; - for player in players { - writeln!(f, "{}: {:<30} {:>4} {:>10} {}", - player.index, - player.name, - player.score, - player.duration, - TheShipPlayer(&player.the_ship))?; + writeln!(f, "\n\n* Players: *")?; + writeln!(f, "\t{:>3} players online\n", players.len())?; + if players.len() > 0 { + writeln!(f, "{:^5} {:^30} {:^4} {:^10} {}", "Index", "Player name", "Score", "Duration", "The Ship")?; + for player in players { + writeln!(f, "{:>5} {:<30} {:>4} {:>10} {}", + player.index, + player.name, + player.score, + player.duration, + TheShipPlayer(&player.the_ship))?; + } } Ok(()) } Err(e) => - writeln!(f, "Failed to query players:\t{}", e) + writeln!(f, "\nFailed to query players:\t{}", e) } } } @@ -150,12 +157,14 @@ impl HLQuery { impl Display for HLQuery { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + writeln!(f, "{}", "*".repeat(SEP_WIDTH))?; write_datapoint!(f, PAD_WIDTH, "Input:", self.input)?; match &self.result { Ok(v) => { - write_datapoint!(f, PAD_WIDTH, "Number of addresses:", format!("{}\n", v.len()))?; + write_datapoint!(f, PAD_WIDTH, "Number of addresses:", format!("{}", v.len()))?; + writeln!(f, "{}\n", "*".repeat(SEP_WIDTH))?; for r in v { - writeln!(f, "{r}\n")?; + writeln!(f, "{r}")?; }; Ok(()) },