Cosmetic changes in output master
authorMegaBrutal <megabrutal+github@megabrutal.com>
Tue, 21 Feb 2023 02:20:55 +0000 (03:20 +0100)
committerMegaBrutal <megabrutal+github@megabrutal.com>
Tue, 21 Feb 2023 02:20:55 +0000 (03:20 +0100)
src/main.rs

index 6e87bad1633f1fbe0a378ecaa9914858d1d1417d..d9e2a27dbb07451cc4d5839795bd0ba4a3b5ea16 100644 (file)
@@ -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(())
             },