Skip to content

Commit

Permalink
refactor: simplify get_height_of_terminal() and get_width...
Browse files Browse the repository at this point in the history
  • Loading branch information
muzimuzhi authored and bootandy committed Sep 16, 2024
1 parent b636086 commit 86b2bd9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,19 @@ fn should_init_color(no_color: bool, force_color: bool) -> bool {
}

fn get_height_of_terminal() -> usize {
// Simplify once https://github.com/eminence/terminal-size/pull/41 is
// merged
terminal_size()
// Windows CI runners detect a terminal height of 0
.map(|(_, Height(h))| max(h as usize, DEFAULT_NUMBER_OF_LINES))
.map(|(_, Height(h))| max(h.into(), DEFAULT_NUMBER_OF_LINES))
.unwrap_or(DEFAULT_NUMBER_OF_LINES)
- 10
}

fn get_width_of_terminal() -> usize {
// Simplify once https://github.com/eminence/terminal-size/pull/41 is
// merged
terminal_size()
.map(|(Width(w), _)| match cfg!(windows) {
// Windows CI runners detect a very low terminal width
true => max(w as usize, DEFAULT_TERMINAL_WIDTH),
false => w as usize,
true => max(w.into(), DEFAULT_TERMINAL_WIDTH),
false => w.into(),
})
.unwrap_or(DEFAULT_TERMINAL_WIDTH)
}
Expand Down

0 comments on commit 86b2bd9

Please sign in to comment.