(
reader: &mut MmapReader,
entries: &mut Vec<MonitorEntry>,
recent_updates: &mut Vec<(String, String)>,
last_idx: &mut u64,
stdout: &mut std::io::Stdout,
)
| 422 | } |
| 423 | |
| 424 | fn monitor_loop( |
| 425 | reader: &mut MmapReader, |
| 426 | entries: &mut Vec<MonitorEntry>, |
| 427 | recent_updates: &mut Vec<(String, String)>, |
| 428 | last_idx: &mut u64, |
| 429 | stdout: &mut std::io::Stdout, |
| 430 | ) -> std::io::Result<()> { |
| 431 | use crossterm::{cursor, event, execute, terminal}; |
| 432 | use std::collections::HashMap; |
| 433 | |
| 434 | let mut cost_cache = CostCache::new(); |
| 435 | let mut scroll_offset: usize = 0; |
| 436 | let mut last_log_lines: usize = 20; |
| 437 | |
| 438 | loop { |
| 439 | // Poll for key events (100ms timeout = our refresh rate). |
| 440 | if event::poll(std::time::Duration::from_millis(100))? { |
| 441 | if let event::Event::Key(key) = event::read()? { |
| 442 | match key.code { |
| 443 | event::KeyCode::Char('c') |
| 444 | if key.modifiers.contains(event::KeyModifiers::CONTROL) => |
| 445 | { |
| 446 | break; |
| 447 | } |
| 448 | event::KeyCode::Char('r') |
| 449 | if key.modifiers.contains(event::KeyModifiers::CONTROL) => |
| 450 | { |
| 451 | entries.clear(); |
| 452 | recent_updates.clear(); |
| 453 | scroll_offset = 0; |
| 454 | } |
| 455 | event::KeyCode::Up => { |
| 456 | scroll_offset = scroll_offset.saturating_add(1); |
| 457 | } |
| 458 | event::KeyCode::Down => { |
| 459 | scroll_offset = scroll_offset.saturating_sub(1); |
| 460 | } |
| 461 | event::KeyCode::PageUp => { |
| 462 | scroll_offset = scroll_offset.saturating_add(last_log_lines.max(1)); |
| 463 | } |
| 464 | event::KeyCode::PageDown => { |
| 465 | scroll_offset = scroll_offset.saturating_sub(last_log_lines.max(1)); |
| 466 | } |
| 467 | _ => {} |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | // Re-read mmap for new entries. |
| 473 | let _ = reader.refresh(); |
| 474 | let current_idx = reader.write_idx(); |
| 475 | if current_idx > *last_idx { |
| 476 | for i in *last_idx..current_idx { |
| 477 | let slot = (i as usize) % RING_CAPACITY; |
| 478 | if let Some(e) = reader.entry(slot) { |
| 479 | push_recent_update(recent_updates, &e.project, &e.tool_name); |
| 480 | entries.push(e); |
| 481 | } |
no test coverage detected