ui: extract term_width() helper as static function

I'll add progress output wrapper which will be used in place of ui object.
This commit is contained in:
Yuya Nishihara 2023-06-13 18:39:09 +09:00
parent dbe8d3fcdc
commit dc7f7fb23d

View file

@ -278,11 +278,7 @@ impl Ui {
}
pub fn term_width(&self) -> Option<u16> {
if let Some(cols) = env::var("COLUMNS").ok().and_then(|s| s.parse().ok()) {
Some(cols)
} else {
crossterm::terminal::size().ok().map(|(cols, _)| cols)
}
term_width()
}
/// Construct a guard object which writes `data` when dropped. Useful for
@ -337,3 +333,11 @@ impl Drop for OutputGuard {
_ = self.output.flush();
}
}
fn term_width() -> Option<u16> {
if let Some(cols) = env::var("COLUMNS").ok().and_then(|s| s.parse().ok()) {
Some(cols)
} else {
crossterm::terminal::size().ok().map(|(cols, _)| cols)
}
}