mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 20:42:10 +00:00
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:
parent
dbe8d3fcdc
commit
dc7f7fb23d
1 changed files with 9 additions and 5 deletions
14
src/ui.rs
14
src/ui.rs
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue