Skip to content

Commit 124fc68

Browse files
committed
fix(core): compact parser raw outputs over certain size
1 parent 7976e9d commit 124fc68

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • packages/nx/src/native/tui

packages/nx/src/native/tui/pty.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,25 @@ impl PtyInstance {
749749
/// Resize after a clear loses historical content but keeps the live viewport.
750750
const MAX_RAW_OUTPUT_BYTES: usize = 5 * 1024 * 1024; // 5 MB
751751

752-
/// Process output with an existing parser
752+
/// Process output with an existing parser.
753+
///
754+
/// When the raw output buffer exceeds `MAX_RAW_OUTPUT_BYTES`, we compact
755+
/// the parser: create a fresh one at the same dimensions, replay just the
756+
/// formatted screen state (scrollback + visible), and swap. This keeps
757+
/// raw_output small enough for resize to work without unbounded growth.
753758
pub fn process_output(&self, output: &[u8]) {
754759
let normalized = normalize_newlines(output);
755760
let mut parser = self.parser.write();
756761
parser.process(&normalized);
757762
if parser.get_raw_output().len() > Self::MAX_RAW_OUTPUT_BYTES {
758-
parser.clear_raw_output();
763+
let screen = parser.screen();
764+
let (rows, cols) = screen.size();
765+
let formatted = screen.all_contents_formatted();
766+
let scrollback = screen.scrollback();
767+
let mut compacted = Parser::new(rows, cols, Self::SCROLLBACK_SIZE);
768+
compacted.process(&formatted);
769+
compacted.screen_mut().set_scrollback(scrollback);
770+
*parser = compacted;
759771
}
760772
}
761773
}

0 commit comments

Comments
 (0)