}
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)?;
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)
}
}
}
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(())
},