mirror of
https://github.com/LordMZTE/mcstat.git
synced 2024-05-19 07:09:45 +02:00
raw output will now display nothing else
fmt
This commit is contained in:
parent
2673036cb0
commit
d16af9e11b
|
@ -11,8 +11,9 @@ clap = { version = "^2.33", features = ["yaml"] }
|
||||||
image-base64 = "0.1.0"
|
image-base64 = "0.1.0"
|
||||||
image = "0.23.9"
|
image = "0.23.9"
|
||||||
asciify = "0.1.6"
|
asciify = "0.1.6"
|
||||||
async-minecraft-ping = { git="https://github.com/LordMZTE/async-minecraft-ping.git", tag="v0.2.2" }
|
async-minecraft-ping = { path="../../../async-minecraft-ping/async-minecraft-ping" }
|
||||||
tokio = { version = "0.2.22", features = ["full"] }
|
tokio = { version = "0.2.22", features = ["full"] }
|
||||||
itertools = "0.9.0"
|
itertools = "0.9.0"
|
||||||
termcolor = "1"
|
termcolor = "1"
|
||||||
anyhow = "1.0.32"
|
anyhow = "1.0.32"
|
||||||
|
serde_json = "1.0.58"
|
||||||
|
|
|
@ -42,7 +42,8 @@ macro_rules! print_table {
|
||||||
|
|
||||||
/// returns an `Option` of the expression passed in
|
/// returns an `Option` of the expression passed in
|
||||||
/// `None` if the `is_empty` on the expression returns true, `Some(x)` otherwise
|
/// `None` if the `is_empty` on the expression returns true, `Some(x)` otherwise
|
||||||
/// this is a macro and not a function because `is_empty` is not defined in any trait
|
/// this is a macro and not a function because `is_empty` is not defined in any
|
||||||
|
/// trait
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! none_if_empty {
|
macro_rules! none_if_empty {
|
||||||
($x:expr) => {
|
($x:expr) => {
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -11,7 +11,7 @@ use tokio::time;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use asciify::AsciiBuilder;
|
use asciify::AsciiBuilder;
|
||||||
use async_minecraft_ping::{ConnectionConfig, ModInfo, ServerDescription};
|
use async_minecraft_ping::{ConnectionConfig, ModInfo, ServerDescription, StatusResponse};
|
||||||
use clap::App;
|
use clap::App;
|
||||||
use image::ImageFormat;
|
use image::ImageFormat;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -63,13 +63,20 @@ async fn main() -> Result<()> {
|
||||||
.context("timeout is invalid value")?,
|
.context("timeout is invalid value")?,
|
||||||
));
|
));
|
||||||
|
|
||||||
let (response, raw_response) = tokio::select! {
|
let raw_response = tokio::select! {
|
||||||
_ = &mut timeout => Err(anyhow!("Connection to server timed out")),
|
_ = &mut timeout => Err(anyhow!("Connection to server timed out")),
|
||||||
r = async {
|
r = async {
|
||||||
let mut con = config.connect().await?;
|
let mut con = config.connect().await?;
|
||||||
con.status().await
|
con.status_raw().await
|
||||||
} => r,
|
} => r,
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
if matches.is_present("raw") {
|
||||||
|
println!("{}", raw_response);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = serde_json::from_str::<StatusResponse>(&raw_response)?;
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Image
|
// region Image
|
||||||
|
@ -106,7 +113,6 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
print_table! {
|
print_table! {
|
||||||
40;
|
40;
|
||||||
bo "Raw Json" => if matches.is_present("raw") {Some(raw_response)} else {None},
|
|
||||||
bo "Description" => none_if_empty!(remove_formatting(&response.description.get_text())),
|
bo "Description" => none_if_empty!(remove_formatting(&response.description.get_text())),
|
||||||
bo "Extra Description" => {
|
bo "Extra Description" => {
|
||||||
if let ServerDescription::Big(big_desc) = response.description {
|
if let ServerDescription::Big(big_desc) = response.description {
|
||||||
|
@ -149,7 +155,8 @@ async fn asciify_base64_image(favicon: String, config: AsciiConfig) -> Result<St
|
||||||
let builder = config.apply(AsciiBuilder::new_from_image(image));
|
let builder = config.apply(AsciiBuilder::new_from_image(image));
|
||||||
|
|
||||||
let mut buf = if config.colored {
|
let mut buf = if config.colored {
|
||||||
//this does not write to stdout but just gets the correct color information for stdout
|
// this does not write to stdout but just gets the correct color
|
||||||
|
// information for stdout
|
||||||
let mut buf = BufferWriter::stdout(ColorChoice::Always).buffer();
|
let mut buf = BufferWriter::stdout(ColorChoice::Always).buffer();
|
||||||
builder.to_stream_colored(&mut buf);
|
builder.to_stream_colored(&mut buf);
|
||||||
buf
|
buf
|
||||||
|
|
Loading…
Reference in a new issue