diff --git a/bins/bounty-cli/src/tui/leaderboard.rs b/bins/bounty-cli/src/tui/leaderboard.rs index 9361cbb..2e6b512 100644 --- a/bins/bounty-cli/src/tui/leaderboard.rs +++ b/bins/bounty-cli/src/tui/leaderboard.rs @@ -21,6 +21,8 @@ struct App { entries: Vec, scroll_offset: usize, error: Option, + is_resizing: bool, + last_mouse_position: (u16, u16), } fn parse_entries(data: &Value) -> Vec { @@ -121,7 +123,11 @@ fn ui(frame: &mut Frame, app: &App) { .border_style(Style::default().fg(Color::Cyan)) .title(title), ) - .row_highlight_style(Style::default().bg(Color::DarkGray)); + .row_highlight_style(Style::default().bg(if app.is_resizing { + Color::DarkGray + } else { + Color::DarkGray + })); frame.render_widget(table, chunks[0]); @@ -137,6 +143,8 @@ pub async fn run(rpc_url: &str) -> Result<()> { entries: vec![], scroll_offset: 0, error: None, + is_resizing: false, + last_mouse_position: (0, 0), }; let mut last_fetch = Instant::now() - Duration::from_secs(10); @@ -172,10 +180,16 @@ pub async fn run(rpc_url: &str) -> Result<()> { _ => {} } } + } else if let Event::Mouse(mouse) = event::read()? { + if mouse.kind == event::MouseEventKind::Down { + app.is_resizing = true; + } else if mouse.kind == event::MouseEventKind::Up { + app.is_resizing = false; + } else if mouse.kind == event::MouseEventKind::Moved { + app.last_mouse_position = (mouse.column, mouse.row); + } } } } - - super::restore_terminal(&mut terminal)?; Ok(()) -} +} \ No newline at end of file diff --git a/bins/bounty-cli/src/tui/mod.rs b/bins/bounty-cli/src/tui/mod.rs index fd11f1a..89cb0ba 100644 --- a/bins/bounty-cli/src/tui/mod.rs +++ b/bins/bounty-cli/src/tui/mod.rs @@ -4,6 +4,7 @@ pub mod weights; use anyhow::Result; use crossterm::{ + event::{self, DisableMouseCapture, EnableMouseCapture}, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; @@ -13,7 +14,7 @@ use std::io; pub fn setup_terminal() -> Result>> { enable_raw_mode()?; let mut stdout = io::stdout(); - execute!(stdout, EnterAlternateScreen)?; + execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; let backend = CrosstermBackend::new(stdout); let terminal = Terminal::new(backend)?; Ok(terminal) @@ -21,7 +22,28 @@ pub fn setup_terminal() -> Result>> { pub fn restore_terminal(terminal: &mut Terminal>) -> Result<()> { disable_raw_mode()?; - execute!(terminal.backend_mut(), LeaveAlternateScreen)?; + execute!(terminal.backend_mut(), LeaveAlternateScreen, DisableMouseCapture)?; terminal.show_cursor()?; Ok(()) } + +pub fn handle_events(terminal: &mut Terminal>, is_resizing: &mut bool) -> Result<()> { + loop { + if let event::Event::Mouse(event) = event::read()? { + match event.kind { + event::MouseEventKind::Moved => { + // Handle mouse move event + } + event::MouseEventKind::Pressed(_) => { + *is_resizing = true; + // Handle mouse press event + } + event::MouseEventKind::Released(_) => { + *is_resizing = false; + // Handle mouse release event + } + _ => {} + } + } + } +} \ No newline at end of file diff --git a/bins/bounty-cli/src/tui/stats.rs b/bins/bounty-cli/src/tui/stats.rs index 60a438b..ef2de1b 100644 --- a/bins/bounty-cli/src/tui/stats.rs +++ b/bins/bounty-cli/src/tui/stats.rs @@ -65,7 +65,7 @@ fn stat_block<'a>(label: &'a str, value: u64, color: Color) -> Paragraph<'a> { ) } -fn ui(frame: &mut Frame, stats: &StatsData, error: &Option) { +fn ui(frame: &mut Frame, stats: &StatsData, error: &Option, is_resizing: bool) { let outer = Layout::default() .direction(Direction::Vertical) .constraints([ @@ -117,6 +117,13 @@ fn ui(frame: &mut Frame, stats: &StatsData, error: &Option) { .style(Style::default().fg(Color::DarkGray)) .block(Block::default().borders(Borders::ALL)); frame.render_widget(help, outer[2]); + + if is_resizing { + let resize_text = Paragraph::new("Resizing...") + .style(Style::default().fg(Color::Red).bold()) + .block(Block::default().borders(Borders::ALL)); + frame.render_widget(resize_text, outer[2]); + } } pub async fn run(rpc_url: &str) -> Result<()> { @@ -124,6 +131,7 @@ pub async fn run(rpc_url: &str) -> Result<()> { let mut stats = StatsData::default(); let mut error: Option = None; let mut last_fetch = Instant::now() - Duration::from_secs(10); + let mut is_resizing = false; loop { if last_fetch.elapsed() >= Duration::from_secs(5) { @@ -137,7 +145,7 @@ pub async fn run(rpc_url: &str) -> Result<()> { last_fetch = Instant::now(); } - terminal.draw(|f| ui(f, &stats, &error))?; + terminal.draw(|f| ui(f, &stats, &error, is_resizing))?; if event::poll(Duration::from_millis(100))? { if let Event::Key(key) = event::read()? { @@ -146,10 +154,17 @@ pub async fn run(rpc_url: &str) -> Result<()> { { break; } + } else if let Event::Mouse(event) = event::read()? { + if event.kind == MouseEventKind::Down { + is_resizing = true; + } else if event.kind == MouseEventKind::Up { + is_resizing = false; + terminal.draw(|f| ui(f, &stats, &error, is_resizing))?; + } } } } super::restore_terminal(&mut terminal)?; Ok(()) -} +} \ No newline at end of file