Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Fix issues with incorrect terminal width
Alexis Sellier committed 3 years ago
commit 1d798a80b4f957a454060d9533c94afbf33e0d9e
parent fd936becf18e8245f1acc6e98ec3507838650746
3 files changed +16 -6
modified radicle-cli/src/terminal/io.rs
@@ -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) {
modified radicle-cli/src/terminal/table.rs
@@ -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()
+
                }
+
            );
        }
    }

modified radicle-cli/src/terminal/textbox.rs
@@ -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 {