Skip to content

Commit

Permalink
fix(tui): build new virtual terminal on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Aug 13, 2024
1 parent f9ecf88 commit 91f8368
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<W: Write> App<W> {
#[tracing::instrument(skip(self, output))]
pub fn process_output(&mut self, task: &str, output: &[u8]) -> Result<(), Error> {
let task_output = self.tasks.get_mut(task).unwrap();
task_output.parser.process(output);
task_output.process(output);
Ok(())
}
}
Expand Down
20 changes: 17 additions & 3 deletions crates/turborepo-ui/src/tui/term_output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::Write;
use std::{io::Write, mem};

use turborepo_vt100 as vt100;

Expand All @@ -8,7 +8,10 @@ use super::{
Error,
};

const SCROLLBACK_LEN: usize = 1024;

pub struct TerminalOutput<W> {
output: Vec<u8>,
pub parser: vt100::Parser,
pub stdin: Option<W>,
pub status: Option<String>,
Expand All @@ -27,7 +30,8 @@ enum LogBehavior {
impl<W> TerminalOutput<W> {
pub fn new(rows: u16, cols: u16, stdin: Option<W>) -> Self {
Self {
parser: vt100::Parser::new(rows, cols, 1024),
output: Vec::new(),
parser: vt100::Parser::new(rows, cols, SCROLLBACK_LEN),
stdin,
status: None,
output_logs: None,
Expand All @@ -47,9 +51,19 @@ impl<W> TerminalOutput<W> {
self.parser.screen().size()
}

pub fn process(&mut self, bytes: &[u8]) {
self.parser.process(bytes);
self.output.extend_from_slice(bytes);
}

pub fn resize(&mut self, rows: u16, cols: u16) {
if self.parser.screen().size() != (rows, cols) {
self.parser.screen_mut().set_size(rows, cols);
let scrollback = self.parser.screen().scrollback();
let mut new_parser = vt100::Parser::new(rows, cols, SCROLLBACK_LEN);
new_parser.process(&self.output);
new_parser.screen_mut().set_scrollback(scrollback);
// Completely swap out the old vterm with a new correctly sized one
mem::swap(&mut self.parser, &mut new_parser);
}
}

Expand Down

0 comments on commit 91f8368

Please sign in to comment.