-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: inputs get messed up when a line overflows
- Loading branch information
Showing
5 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use console::Term; | ||
|
||
/// Returns a tuple with the height of the output and the number of lines that overflow the terminal width | ||
pub fn get_height(term: &Term, output: String) -> (usize, usize) { | ||
let max_width = term.size().1 as usize; | ||
let height = output.lines().count() - 1; | ||
// calculate potential overflow of lines overflowing terminal width | ||
let overflow = output | ||
.lines() | ||
.map(|l| { | ||
if l.chars().count() > max_width { | ||
l.chars().count() / max_width | ||
} else { | ||
0 | ||
} | ||
}) | ||
.sum::<usize>(); | ||
(height, overflow) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters