From 0828d3ff58ba87e2db8486d963896236bfff8541 Mon Sep 17 00:00:00 2001 From: kxxt Date: Wed, 15 May 2024 23:27:57 +0800 Subject: [PATCH] feat/tui: show/hide CWD in cmdline --- src/action.rs | 1 + src/event.rs | 2 +- src/tui/app.rs | 14 ++++++++++++++ src/tui/event_list.rs | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/action.rs b/src/action.rs index 83ac8e96..56d5e2be 100644 --- a/src/action.rs +++ b/src/action.rs @@ -34,6 +34,7 @@ pub enum Action { ScrollToEnd, ToggleFollow, ToggleEnvDisplay, + ToggleCwdDisplay, StopFollow, // Sizing ShrinkPane, diff --git a/src/event.rs b/src/event.rs index 1cf0eeb4..5dfd6059 100644 --- a/src/event.rs +++ b/src/event.rs @@ -235,7 +235,7 @@ impl TracerEventDetails { }); }); // Handle cwd - if cwd != &baseline.cwd { + if cwd != &baseline.cwd && rt_modifier.show_cwd { spans.push(space.clone()); spans.push(format!("-C {}", escape_str_for_bash!(cwd)).set_style(THEME.cwd)); } diff --git a/src/tui/app.rs b/src/tui/app.rs index 4a407963..3f26ee8a 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -332,6 +332,9 @@ impl App { KeyCode::Char('e') if ke.modifiers == KeyModifiers::NONE => { action_tx.send(Action::ToggleEnvDisplay)?; } + KeyCode::Char('w') if ke.modifiers == KeyModifiers::NONE => { + action_tx.send(Action::ToggleCwdDisplay)?; + } KeyCode::F(1) if ke.modifiers == KeyModifiers::NONE => { action_tx.send(Action::SetActivePopup(ActivePopup::Help))?; } @@ -460,6 +463,9 @@ impl App { Action::ToggleEnvDisplay => { self.event_list.toggle_env_display(); } + Action::ToggleCwdDisplay => { + self.event_list.toggle_cwd_display(); + } Action::StopFollow => { self.event_list.stop_follow(); } @@ -740,6 +746,14 @@ impl App { "Show Env" } ), + help_item!( + "W", + if self.event_list.is_cwd_in_cmdline() { + "Hide CWD" + } else { + "Show CWD" + } + ), help_item!("V", "View"), help_item!("Ctrl+F", "Search"), )); diff --git a/src/tui/event_list.rs b/src/tui/event_list.rs index e38ccb4a..e16f53d6 100644 --- a/src/tui/event_list.rs +++ b/src/tui/event_list.rs @@ -146,6 +146,12 @@ impl EventList { self.rebuild_event_strings(); } + pub fn toggle_cwd_display(&mut self) { + self.rt_modifier.show_cwd = !self.rt_modifier.show_cwd; + self.should_refresh_lines_cache = true; + self.rebuild_event_strings(); + } + /// returns the index of the selected item if there is any pub fn selection_index(&self) -> Option { self.state.selected().map(|i| self.window.0 + i)