Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): avoid rendering area more than u16::MAX (#7867)
### Description Fix for #7843 ### Testing Instructions Verify that there is no longer a panic when persisting tasks with large amount of lines e.g. `yes | head -n 1000` (Waiting on user test to confirm fix works) Closes TURBO-2735
- Loading branch information
1 parent
ab248ec
commit 7c5b0c4
Showing
3 changed files
with
53 additions
and
10 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
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 |
---|---|---|
@@ -1,21 +1,52 @@ | ||
pub struct EntireScreen<'a>(pub(crate) &'a crate::Screen); | ||
pub struct EntireScreen<'a> { | ||
screen: &'a crate::Screen, | ||
// If present, screen will be truncated to only display lines that fit in those cells | ||
max_lines: Option<usize>, | ||
size: (usize, u16), | ||
} | ||
|
||
impl<'a> EntireScreen<'a> { | ||
#[must_use] | ||
pub fn new(screen: &'a crate::Screen) -> Self { | ||
Self { | ||
size: screen.grid().size_with_contents(), | ||
screen, | ||
max_lines: None, | ||
} | ||
} | ||
|
||
pub fn with_max_lines(&mut self, max_lines: Option<usize>) { | ||
self.max_lines = max_lines; | ||
} | ||
|
||
#[must_use] | ||
pub fn cell(&self, row: u16, col: u16) -> Option<&crate::Cell> { | ||
self.0.grid().all_row(row).and_then(|r| r.get(col)) | ||
match self.max_lines { | ||
// We need to do some trimming | ||
Some(max_lines) if self.size().0 > max_lines => { | ||
// in this case we fuck ourselves :) HARD | ||
let (height, _) = self.size(); | ||
// Skip over these | ||
let lines_to_cut = (height - max_lines) as u16; | ||
Check warning on line 30 in crates/turborepo-vt100/src/entire_screen.rs GitHub Actions / Turborepo rust clippy
|
||
self.screen | ||
.grid() | ||
.all_row(lines_to_cut + row) | ||
.and_then(|r| r.get(col)) | ||
} | ||
_ => self.screen.grid().all_row(row).and_then(|r| r.get(col)), | ||
} | ||
} | ||
|
||
#[must_use] | ||
pub fn contents(&self) -> String { | ||
let mut s = String::new(); | ||
self.0.grid().write_full_contents(&mut s); | ||
self.screen.grid().write_full_contents(&mut s); | ||
s | ||
} | ||
|
||
/// Size required to render all contents | ||
#[must_use] | ||
pub fn size(&self) -> (usize, u16) { | ||
self.0.grid().size_with_contents() | ||
self.size | ||
} | ||
} |
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