mirror of
https://github.com/LordMZTE/mcstat.git
synced 2024-05-09 07:31:10 +02:00
block table entry will no longer be smaller then title
This commit is contained in:
parent
d6710cfac7
commit
ae580c1d00
|
@ -1,4 +1,7 @@
|
||||||
use std::{io::{self, Write}, cmp::{min, max}};
|
use std::{
|
||||||
|
cmp::{max, min},
|
||||||
|
io::{self, Write},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(SmartDefault)]
|
#[derive(SmartDefault)]
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
|
@ -55,9 +58,9 @@ impl Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn opt_big_entry(&mut self, name: impl ToString, val: Option<impl ToString>) {
|
pub fn opt_big_entry(&mut self, name: impl ToString, val: Option<impl ToString>) {
|
||||||
self.entries.push(Box::new(OptBigTableEntry(
|
self.entries.push(Box::new(OptBigTableEntry(val.map(|t| {
|
||||||
val.map(|t| BigTableEntry::new(name.to_string(), t.to_string(), self.max_block_width)),
|
BigTableEntry::new(name.to_string(), t.to_string(), self.max_block_width)
|
||||||
)));
|
}))));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_small_width(&mut self, width: usize) {
|
fn set_small_width(&mut self, width: usize) {
|
||||||
|
@ -107,7 +110,10 @@ impl TableEntry for BigTableEntry {
|
||||||
impl BigTableEntry {
|
impl BigTableEntry {
|
||||||
pub fn new(name: String, val: String, maxwidth: usize) -> Self {
|
pub fn new(name: String, val: String, maxwidth: usize) -> Self {
|
||||||
let val_width = min(
|
let val_width = min(
|
||||||
|
max(
|
||||||
val.lines().map(|s| s.len() + 4).max().unwrap_or_default(),
|
val.lines().map(|s| s.len() + 4).max().unwrap_or_default(),
|
||||||
|
name.len() + 4,
|
||||||
|
),
|
||||||
maxwidth,
|
maxwidth,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue