diff --git a/cortex-tui/src/capture.rs b/cortex-tui/src/capture.rs index 2ec9a334..d431df78 100644 --- a/cortex-tui/src/capture.rs +++ b/cortex-tui/src/capture.rs @@ -32,8 +32,12 @@ use cortex_tui_capture::{ }; use ratatui::buffer::Buffer as RatatuiBuffer; use std::sync::atomic::{AtomicU64, Ordering}; +use std::time::Instant; use tracing::{debug, info, warn}; +/// Minimum interval between frame captures when capture_all is enabled (1 second) +const MIN_CAPTURE_INTERVAL_SECS: u64 = 1; + /// Static frame counter for unique frame labeling static FRAME_COUNTER: AtomicU64 = AtomicU64::new(0); @@ -54,6 +58,8 @@ pub struct TuiCapture { modal_open: bool, /// Last captured event description last_event: String, + /// Last time a frame was captured (for rate limiting capture_all mode) + last_capture_time: Option, } impl TuiCapture { @@ -80,6 +86,7 @@ impl TuiCapture { autocomplete_visible: false, modal_open: false, last_event: String::new(), + last_capture_time: None, } } @@ -201,6 +208,9 @@ impl TuiCapture { /// /// This should be called after each render. It captures the current /// buffer state as ASCII art. + /// + /// When `capture_all` is enabled, frames are rate-limited to at most + /// one per second to avoid excessive logging and storage. pub fn capture_frame(&mut self, buffer: &RatatuiBuffer, label: Option<&str>) { if let Some(ref mut manager) = self.inner { let snapshot = BufferSnapshot::from_ratatui_buffer(buffer); @@ -212,6 +222,15 @@ impl TuiCapture { let event = std::mem::take(&mut self.last_event); format!("{} - {}", self.current_view, event) } else if self.capture_all { + // Rate limit capture_all frames to max 1 per second + let now = Instant::now(); + if let Some(last_time) = self.last_capture_time { + if now.duration_since(last_time).as_secs() < MIN_CAPTURE_INTERVAL_SECS { + // Skip this frame - not enough time has passed + return; + } + } + self.last_capture_time = Some(now); let frame_num = FRAME_COUNTER.fetch_add(1, Ordering::SeqCst); format!("{} - frame {}", self.current_view, frame_num) } else {