ctl-core 0.2.0

Shared clap chassis for the *ctl CLIs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Private terminal width detection for the semantic renderer.

use comfy_table::Table;

const MIN_WIDTH: u16 = 20;

/// Detected TTY width, or `COLUMNS` when at least 20.
pub(crate) fn terminal_width() -> Option<u16> {
    Table::new().width().or_else(|| {
        std::env::var("COLUMNS")
            .ok()?
            .parse::<u16>()
            .ok()
            .filter(|width| *width >= MIN_WIDTH)
    })
}