Skip to content

Commit 6d0af4b

Browse files
authored
feat(tui): add shortcut for clearing task logs (#10828)
### Description I use turborepo for long running `dev` tasks and sometimes I want to clear the output of just one pane, for example server logs before triggering a request. If I clear my terminal buffer it clears everything including the TUI, and the content is still there to be scrolled to. What I really want is to only clear the logs for a single task. This PR introduces the "Clear logs" option, currently bound to `shift-c` (I tried to pick a shortcut inkeeping with the others). It clears the logs only for the current task Example screencasts below ### Testing Instructions - Run some tasks with the `--ui=tui` - Press `shift-c` on a pane with output - See that only that panes output is cleared, and new logs appear as normal I attempted to write tests for this but I wasn't keen on all the hoops I had to jump through to try and test that it actually clears the buffer **Examples** Attempting and failing to clear with cmd+k: https://github.com/user-attachments/assets/d72a304d-c4b8-467b-9c17-16422552610e New behaviour with shift-c: https://github.com/user-attachments/assets/00440758-aa16-402f-9119-086639f4fb62
1 parent b2d47bc commit 6d0af4b

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

crates/turborepo-ui/src/tui/app.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,12 @@ impl<W> App<W> {
605605
task.parser.screen_mut().set_scrollback(0);
606606
Ok(())
607607
}
608+
609+
pub fn clear_task_logs(&mut self) -> Result<(), Error> {
610+
let task = self.get_full_task_mut()?;
611+
task.clear_logs();
612+
Ok(())
613+
}
608614
}
609615

610616
impl<W: Write> App<W> {
@@ -899,6 +905,9 @@ fn update(
899905
app.scroll_momentum.reset();
900906
app.jump_to_logs_bottom()?;
901907
}
908+
Event::ClearLogs => {
909+
app.clear_task_logs()?;
910+
}
902911
Event::EnterInteractive => {
903912
app.is_task_selection_pinned = true;
904913
app.interact()?;

crates/turborepo-ui/src/tui/event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum Event {
3434
PageDown,
3535
JumpToLogsTop,
3636
JumpToLogsBottom,
37+
ClearLogs,
3738
SetStdin {
3839
task: String,
3940
stdin: Box<dyn std::io::Write + Send>,

crates/turborepo-ui/src/tui/input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ fn translate_key_event(options: InputOptions, key_event: KeyEvent) -> Option<Eve
120120
KeyCode::PageDown | KeyCode::Char('D') => Some(Event::PageDown),
121121
KeyCode::Char('t') => Some(Event::JumpToLogsTop),
122122
KeyCode::Char('b') => Some(Event::JumpToLogsBottom),
123+
KeyCode::Char('C') => Some(Event::ClearLogs),
123124
KeyCode::Char('m') => Some(Event::ToggleHelpPopup),
124125
KeyCode::Char('p') => Some(Event::TogglePinnedTask),
125126
KeyCode::Up | KeyCode::Char('k') => Some(Event::Up),

crates/turborepo-ui/src/tui/popup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const BIND_LIST: &[&str] = [
2121
"d - Scroll logs down",
2222
"Shift+u - Page logs up",
2323
"Shift+d - Page logs down",
24+
"Shift+c - Clear logs",
2425
"t - Jump to top of logs",
2526
"b - Jump to bottom of logs",
2627
]

crates/turborepo-ui/src/tui/term_output.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,11 @@ impl<W> TerminalOutput<W> {
170170
pub fn copy_selection(&self) -> Option<String> {
171171
self.parser.screen().selected_text()
172172
}
173+
174+
pub fn clear_logs(&mut self) {
175+
self.output.clear();
176+
177+
// clear screen and reset cursor
178+
self.process(b"\x1bc");
179+
}
173180
}

0 commit comments

Comments
 (0)