diff --git a/cli/src/native/actions.rs b/cli/src/native/actions.rs index 4dc0efa..44543ff 100644 --- a/cli/src/native/actions.rs +++ b/cli/src/native/actions.rs @@ -1076,7 +1076,7 @@ pub async fn execute_command(cmd: &Value, state: &mut DaemonState) -> Value { "setcontent" => handle_setcontent(cmd, state).await, "headers" => handle_headers(cmd, state).await, "offline" => handle_offline(cmd, state).await, - "console" => handle_console(state).await, + "console" => handle_console(cmd, state).await, "errors" => handle_errors(state).await, "state_save" => handle_state_save(cmd, state).await, "state_load" => handle_state_load(cmd, state).await, @@ -2887,8 +2887,15 @@ async fn handle_offline(cmd: &Value, state: &DaemonState) -> Result Result { - Ok(state.event_tracker.get_console_json()) +async fn handle_console(cmd: &Value, state: &mut DaemonState) -> Result { + let clear = cmd.get("clear").and_then(|v| v.as_bool()).unwrap_or(false); + if clear { + state.event_tracker.clear_console(); + Ok(json!({ "cleared": true })) + } else { + let result = state.event_tracker.get_console_json(); + Ok(result) + } } async fn handle_errors(state: &DaemonState) -> Result { diff --git a/cli/src/native/network.rs b/cli/src/native/network.rs index 3d5bad4..4994a74 100644 --- a/cli/src/native/network.rs +++ b/cli/src/native/network.rs @@ -322,6 +322,10 @@ impl EventTracker { }); } + pub fn clear_console(&mut self) { + self.console_entries.clear(); + } + pub fn get_console_json(&self) -> Value { let messages: Vec = self .console_entries diff --git a/cli/src/output.rs b/cli/src/output.rs index 5d70ff2..5c275e6 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -430,11 +430,12 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou } return; } - // Cleared (cookies or request log) + // Cleared (cookies, console, or request log) if let Some(cleared) = data.get("cleared").and_then(|v| v.as_bool()) { if cleared { let label = match action { Some("cookies_clear") => "Cookies cleared", + Some("console") => "Console log cleared", _ => "Request log cleared", }; println!("{} {}", color::success_indicator(), label);