ui: simplify size() to only return width, rename it to term_width()

I'm going to add $COLUMNS override, and it should work even if ioctl() on tty
failed. This means that the return type has to be (Option<u16>, Option<u16>).
Since we don't use the row count, I decided to drop it.
This commit is contained in:
Yuya Nishihara 2023-03-10 19:00:32 +09:00
parent b6cac0c6aa
commit afdf9e19f2
2 changed files with 4 additions and 4 deletions

View file

@ -63,8 +63,8 @@ impl Progress {
}
let bar_width = ui
.size()
.map(|(cols, _rows)| usize::from(cols))
.term_width()
.map(usize::from)
.unwrap_or(0)
.saturating_sub(self.buffer.len() - control_chars + 2);
self.buffer.push('[');

View file

@ -288,8 +288,8 @@ impl Ui {
rpassword::prompt_password(format!("{prompt}: "))
}
pub fn size(&self) -> Option<(u16, u16)> {
crossterm::terminal::size().ok()
pub fn term_width(&self) -> Option<u16> {
crossterm::terminal::size().ok().map(|(cols, _)| cols)
}
/// Construct a guard object which writes `data` when dropped. Useful for