diff --git a/src/data/format.rs b/src/data/format.rs index 9e61f4b..3e46281 100644 --- a/src/data/format.rs +++ b/src/data/format.rs @@ -36,6 +36,10 @@ pub trait Verbosity { fn show_id(&self) -> bool { false } + #[inline] + fn ellipsis_threshold(&self) -> Option { + 1024.try_into().ok() + } } impl Verbosity for i8 { @@ -55,6 +59,14 @@ impl Verbosity for i8 { fn show_id(&self) -> bool { *self >= 1 } + #[inline] + fn ellipsis_threshold(&self) -> Option { + match *self { + 1.. => None, + 0 => 1024.try_into().ok(), + ..=-1 => 25.try_into().ok(), + } + } } pub trait Format { @@ -95,7 +107,16 @@ pub trait Format { } if let Some(val) = values.single() { - f.write_fmt(format_args!("{{{val}}}"))?; + if let Some(t) = Self::verbosity().ellipsis_threshold() { + let formatted = val.to_string(); + if formatted.len() > t.get() { + write!(f, "{{{}…}}", &formatted[..t.get()])?; + } else { + write!(f, "{{{formatted}}}")?; + } + } else { + write!(f, "{{{val}}}")?; + } return Ok(()); }