mirror of
https://github.com/LordMZTE/mcstat.git
synced 2024-04-28 20:08:35 +02:00
added mod list version support
print_table! macro now takes argument for width of placeholders
This commit is contained in:
parent
1779273659
commit
2673036cb0
|
@ -29,6 +29,10 @@ args:
|
||||||
- mods:
|
- mods:
|
||||||
short: m
|
short: m
|
||||||
help: "if supplied, a mod list will be printed"
|
help: "if supplied, a mod list will be printed"
|
||||||
|
- modversions:
|
||||||
|
short: v
|
||||||
|
help: "if supplied, mods will also have their version info printed"
|
||||||
|
requires: "mods"
|
||||||
|
|
||||||
# IMAGE ARGS
|
# IMAGE ARGS
|
||||||
# TODO due to a bug in clap, the image argument is always required because size has a default value
|
# TODO due to a bug in clap, the image argument is always required because size has a default value
|
||||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -12,31 +12,31 @@ use asciify::AsciiBuilder;
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! print_table {
|
macro_rules! print_table {
|
||||||
//list entry
|
//list entry
|
||||||
(l $l:expr => $k:expr) => {
|
($width:expr; l $l:expr => $k:expr) => {
|
||||||
println!("{: <20} | {}", $l, $k);
|
println!("{: <width$} | {}", $l, $k, width = $width);
|
||||||
};
|
};
|
||||||
|
|
||||||
//block
|
//block
|
||||||
(b $l:expr => $k:expr) => {
|
($width:expr; b $l:expr => $k:expr) => {
|
||||||
println!("{:=^25}\n{}\n=========================", $l, $k);
|
println!("{:=^width$}\n{}\n{:=<width$}", $l, $k, "", width = $width);
|
||||||
};
|
};
|
||||||
|
|
||||||
//list entry option
|
//list entry option
|
||||||
(lo $l:expr => $k:expr) => {
|
($width:expr; lo $l:expr => $k:expr) => {
|
||||||
if let Some(txt) = $k {
|
if let Some(txt) = $k {
|
||||||
println!("{: <20} | {}", $l, txt);
|
println!("{: <width$} | {}", $l, txt, width = $width);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//block option
|
//block option
|
||||||
(bo $l:expr => $k:expr) => {
|
($width:expr; bo $l:expr => $k:expr) => {
|
||||||
if let Some(txt) = $k {
|
if let Some(txt) = $k {
|
||||||
println!("{:=^25}\n{}\n=========================", $l, txt);
|
println!("{:=^width$}\n{}\n{:=<width$}", $l, txt, "", width = $width);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($($t:tt $l:expr => $k:expr),+ $(,)?) => {
|
($width:expr; $($t:tt $l:expr => $k:expr),+ $(,)?) => {
|
||||||
$(print_table!($t $l => $k);)*
|
$(print_table!($width; $t $l => $k);)*
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -105,6 +105,7 @@ async fn main() -> Result<()> {
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
||||||
print_table! {
|
print_table! {
|
||||||
|
40;
|
||||||
bo "Raw Json" => if matches.is_present("raw") {Some(raw_response)} else {None},
|
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" => {
|
||||||
|
@ -124,7 +125,7 @@ async fn main() -> Result<()> {
|
||||||
l "Online Players" => response.players.online,
|
l "Online Players" => response.players.online,
|
||||||
l "Max Players" => response.players.max,
|
l "Max Players" => response.players.max,
|
||||||
bo "Mods" => if let (Some(mods), true) = (response.modinfo, matches.is_present("mods")) {
|
bo "Mods" => if let (Some(mods), true) = (response.modinfo, matches.is_present("mods")) {
|
||||||
Some(get_modlist(mods))
|
Some(get_modlist(mods, matches.is_present("modversions")))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
@ -172,12 +173,30 @@ async fn asciify_base64_image(favicon: String, config: AsciiConfig) -> Result<St
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_modlist(list: ModInfo) -> String {
|
fn get_modlist(list: ModInfo, version_info: bool) -> String {
|
||||||
match list {
|
let infos = match list {
|
||||||
ModInfo::Forge { mod_list: l } => l,
|
ModInfo::Forge { mod_list: l } => l,
|
||||||
}
|
};
|
||||||
.into_iter()
|
|
||||||
.map(|m| m.modid)
|
let max_width = if version_info {
|
||||||
.intersperse("\n".to_owned())
|
infos
|
||||||
.collect()
|
.iter()
|
||||||
|
.map(|m| m.modid.len())
|
||||||
|
.max()
|
||||||
|
.unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
infos
|
||||||
|
.into_iter()
|
||||||
|
.map(|m| {
|
||||||
|
if version_info {
|
||||||
|
format!("{: <width$} | {}", m.modid, m.version, width = max_width)
|
||||||
|
} else {
|
||||||
|
m.modid
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.intersperse("\n".to_owned())
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue