Fix issues with incorrect terminal width
For some reason, the terminal width isn't always valid, and then ends up returning `80`. Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
fd936becf1
commit
1d798a80b4
|
|
@ -56,9 +56,10 @@ pub fn tip_args(args: fmt::Arguments) {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn width() -> usize {
|
||||
let (_, rows) = console::Term::stdout().size();
|
||||
rows as usize
|
||||
pub fn width() -> Option<usize> {
|
||||
console::Term::stdout()
|
||||
.size_checked()
|
||||
.map(|(_, cols)| cols as usize)
|
||||
}
|
||||
|
||||
pub fn headline(headline: &str) {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,14 @@ impl<const W: usize> Table<W> {
|
|||
.ok();
|
||||
}
|
||||
}
|
||||
println!("{}", console::truncate_str(&output, width - 1, "…"));
|
||||
println!(
|
||||
"{}",
|
||||
if let Some(width) = width {
|
||||
console::truncate_str(&output, width - 1, "…")
|
||||
} else {
|
||||
output.into()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,10 @@ impl fmt::Display for TextBox {
|
|||
.max()
|
||||
.unwrap_or(0)
|
||||
+ 2;
|
||||
if term::width() < width + 2 {
|
||||
width = term::width() - 2
|
||||
if let Some(max) = term::width() {
|
||||
if max < width + 2 {
|
||||
width = max - 2
|
||||
}
|
||||
}
|
||||
|
||||
let (connector, header_width) = if !self.first {
|
||||
|
|
|
|||
Loading…
Reference in New Issue