Skip to main content

ctl_core/
layout.rs

1//! Private terminal width detection for the semantic renderer.
2
3use comfy_table::Table;
4
5const MIN_WIDTH: u16 = 20;
6
7/// Detected TTY width, or `COLUMNS` when at least 20.
8pub(crate) fn terminal_width() -> Option<u16> {
9    Table::new().width().or_else(|| {
10        std::env::var("COLUMNS")
11            .ok()?
12            .parse::<u16>()
13            .ok()
14            .filter(|width| *width >= MIN_WIDTH)
15    })
16}