chore: formatting

This commit is contained in:
Michel de Graaf
2026-01-04 20:37:03 +01:00
parent 94b33d4bd6
commit dfe6f532fa
22 changed files with 582 additions and 507 deletions
+26 -25
View File
@@ -1,27 +1,27 @@
use crate::models::FileDisplayData;
use crate::ui::{
border_style, border_type, format_bytes, format_shortcuts_styled,
get_bitrate, get_spinner_char, header_style, highlight_style,
primary_style, success_style, warning_style, HIGHLIGHT_SYMBOL,
HIGHLIGHT_SYMBOL, border_style, border_type, format_bytes,
format_shortcuts_styled, get_bitrate, get_spinner_char, header_style,
highlight_style, primary_style, success_style, warning_style,
};
use color_eyre::Result;
use ratatui::text::{Line, Span};
use ratatui::{
crossterm::event::{self, poll, Event, KeyCode, KeyEvent, KeyEventKind},
DefaultTerminal, Frame,
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, poll},
layout::{Alignment, Constraint, Layout},
style::Style,
widgets::{
Block, Borders, Cell, HighlightSpacing, Paragraph, Row, StatefulWidget,
Table, TableState, Wrap,
},
DefaultTerminal, Frame,
};
use soulseek_rs::Client;
use std::{
collections::HashSet,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
atomic::{AtomicBool, Ordering},
},
time::{Duration, Instant},
};
@@ -114,9 +114,10 @@ impl FileSelector {
};
if poll(timeout)?
&& let Event::Key(key) = event::read()? {
self.handle_key(key);
}
&& let Event::Key(key) = event::read()?
{
self.handle_key(key);
}
}
Ok((terminal, self.selected_indices.iter().copied().collect()))
@@ -158,13 +159,13 @@ impl FileSelector {
fn toggle_selection(&mut self) {
if let Some(filtered_idx) = self.state.selected()
&& let Some(&original_idx) = self.filtered_indices.get(filtered_idx)
{
if self.selected_indices.contains(&original_idx) {
self.selected_indices.remove(&original_idx);
} else {
self.selected_indices.insert(original_idx);
}
{
if self.selected_indices.contains(&original_idx) {
self.selected_indices.remove(&original_idx);
} else {
self.selected_indices.insert(original_idx);
}
}
}
fn handle_key(&mut self, key: KeyEvent) {
@@ -194,11 +195,11 @@ impl FileSelector {
// If nothing selected, select the current item under cursor
if self.selected_indices.is_empty()
&& let Some(filtered_idx) = self.state.selected()
&& let Some(&original_idx) =
self.filtered_indices.get(filtered_idx)
{
self.selected_indices.insert(original_idx);
}
&& let Some(&original_idx) =
self.filtered_indices.get(filtered_idx)
{
self.selected_indices.insert(original_idx);
}
self.should_exit = true;
}
KeyCode::Up | KeyCode::Down => {
@@ -236,11 +237,11 @@ impl FileSelector {
// If nothing selected, select the current item under cursor
if self.selected_indices.is_empty()
&& let Some(filtered_idx) = self.state.selected()
&& let Some(&original_idx) =
self.filtered_indices.get(filtered_idx)
{
self.selected_indices.insert(original_idx);
}
&& let Some(&original_idx) =
self.filtered_indices.get(filtered_idx)
{
self.selected_indices.insert(original_idx);
}
self.should_exit = true;
}
KeyCode::Esc | KeyCode::Char('q') => {
+21 -20
View File
@@ -1,13 +1,14 @@
use crate::models::DownloadEntry;
use crate::ui::{
border_style, border_type, error_style, format_bytes_progress,
format_progress_bar, format_shortcuts_styled, format_speed, header_style,
highlight_style, inactive_style, primary_style, warning_style,
COLOR_PRIMARY, HIGHLIGHT_SYMBOL,
COLOR_PRIMARY, HIGHLIGHT_SYMBOL, border_style, border_type, error_style,
format_bytes_progress, format_progress_bar, format_shortcuts_styled,
format_speed, header_style, highlight_style, inactive_style, primary_style,
warning_style,
};
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, poll, Event, KeyCode, KeyEvent, KeyEventKind},
DefaultTerminal, Frame,
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, poll},
layout::{Alignment, Constraint, Layout},
style::{Modifier, Style},
text::{Line, Span},
@@ -15,11 +16,10 @@ use ratatui::{
Block, Borders, Cell, HighlightSpacing, Paragraph, Row, StatefulWidget,
Table, TableState,
},
DefaultTerminal, Frame,
};
use soulseek_rs::{Client, DownloadStatus};
use std::{
sync::{mpsc, mpsc::Receiver, Arc},
sync::{Arc, mpsc, mpsc::Receiver},
thread,
time::Duration,
};
@@ -82,18 +82,18 @@ impl MultiDownloadProgress {
let mut need_start_next = false;
for download_entry in &mut self.downloads {
if let Some(receiver) = &download_entry.receiver
&& let Ok(status) = receiver.try_recv() {
let was_active = !download_entry.download.is_finished();
download_entry.download.status = status;
let is_finished = download_entry.download.is_finished();
&& let Ok(status) = receiver.try_recv()
{
let was_active = !download_entry.download.is_finished();
download_entry.download.status = status;
let is_finished = download_entry.download.is_finished();
// If download just finished, decrement active count
if was_active && is_finished {
self.active_count =
self.active_count.saturating_sub(1);
need_start_next = true;
}
// If download just finished, decrement active count
if was_active && is_finished {
self.active_count = self.active_count.saturating_sub(1);
need_start_next = true;
}
}
}
// Start next batch after iteration completes
@@ -103,9 +103,10 @@ impl MultiDownloadProgress {
// Handle keyboard input
if poll(Duration::from_millis(100))?
&& let Event::Key(key) = event::read()? {
self.handle_key(key);
}
&& let Event::Key(key) = event::read()?
{
self.handle_key(key);
}
// Exit when user cancels or all downloads finished
if self.should_exit || self.all_finished() {
+35 -34
View File
@@ -3,28 +3,28 @@ use crate::models::{
SearchStatus,
};
use crate::ui::panes::{
render_downloads_pane, render_results_pane, render_searches_pane,
ResultsPaneParams,
ResultsPaneParams, render_downloads_pane, render_results_pane,
render_searches_pane,
};
use crate::ui::{
border_style, border_type, format_shortcuts_styled, render_download_stats,
};
use color_eyre::Result;
use ratatui::{
DefaultTerminal, Frame,
crossterm::event::{
self, poll, Event, KeyCode, KeyEvent, KeyEventKind, MouseButton,
MouseEvent, MouseEventKind,
self, Event, KeyCode, KeyEvent, KeyEventKind, MouseButton, MouseEvent,
MouseEventKind, poll,
},
layout::{Constraint, Layout},
widgets::{Block, Borders, Paragraph},
DefaultTerminal, Frame,
};
use soulseek_rs::{Client, DownloadStatus};
use std::{
sync::{
Arc,
atomic::AtomicBool,
mpsc::{self},
Arc,
},
thread,
time::{Duration, Instant},
@@ -521,35 +521,35 @@ impl MainTui {
// Check if click is within searches pane
if let Some(area) = self.state.searches_pane_area
&& col >= area.x
&& col < area.x + area.width
&& row >= area.y
&& row < area.y + area.height
{
self.state.focused_pane = FocusedPane::Searches;
return Ok(());
}
&& col < area.x + area.width
&& row >= area.y
&& row < area.y + area.height
{
self.state.focused_pane = FocusedPane::Searches;
return Ok(());
}
// Check if click is within results pane
if let Some(area) = self.state.results_pane_area
&& col >= area.x
&& col < area.x + area.width
&& row >= area.y
&& row < area.y + area.height
{
self.state.focused_pane = FocusedPane::Results;
return Ok(());
}
&& col < area.x + area.width
&& row >= area.y
&& row < area.y + area.height
{
self.state.focused_pane = FocusedPane::Results;
return Ok(());
}
// Check if click is within downloads pane
if let Some(area) = self.state.downloads_pane_area
&& col >= area.x
&& col < area.x + area.width
&& row >= area.y
&& row < area.y + area.height
{
self.state.focused_pane = FocusedPane::Downloads;
return Ok(());
}
&& col < area.x + area.width
&& row >= area.y
&& row < area.y + area.height
{
self.state.focused_pane = FocusedPane::Downloads;
return Ok(());
}
}
Ok(())
@@ -747,13 +747,14 @@ impl MainTui {
// Update selected search if this is the active one
if let Some(selected_idx) = selected_search_index
&& selected_idx == idx {
self.state.results_items = search.results.clone();
self.state.results_filtered_items =
search.results.clone();
self.state.results_filtered_indices =
(0..search.results.len()).collect();
}
&& selected_idx == idx
{
self.state.results_items = search.results.clone();
self.state.results_filtered_items =
search.results.clone();
self.state.results_filtered_indices =
(0..search.results.len()).collect();
}
}
// Mark as completed after timeout
+4 -4
View File
@@ -1,16 +1,16 @@
use crate::models::DownloadEntry;
use crate::ui::{
border_style, border_type, error_style, format_bytes, format_speed,
header_style, highlight_style, inactive_style, success_style,
warning_style, HIGHLIGHT_SYMBOL,
HIGHLIGHT_SYMBOL, border_style, border_type, error_style, format_bytes,
format_speed, header_style, highlight_style, inactive_style, success_style,
warning_style,
};
use ratatui::{
Frame,
layout::Rect,
widgets::{
Block, Borders, Cell, HighlightSpacing, Paragraph, Row, Table,
TableState,
},
Frame,
};
use soulseek_rs::DownloadStatus;
+1 -1
View File
@@ -3,5 +3,5 @@ mod results_pane;
mod searches_pane;
pub use downloads_pane::render_downloads_pane;
pub use results_pane::{render_results_pane, ResultsPaneParams};
pub use results_pane::{ResultsPaneParams, render_results_pane};
pub use searches_pane::render_searches_pane;
+3 -3
View File
@@ -1,15 +1,15 @@
use crate::models::FileDisplayData;
use crate::ui::{
border_style, border_type, format_bytes, header_style, highlight_style,
HIGHLIGHT_SYMBOL,
HIGHLIGHT_SYMBOL, border_style, border_type, format_bytes, header_style,
highlight_style,
};
use ratatui::{
Frame,
layout::Rect,
widgets::{
Block, Borders, Cell, HighlightSpacing, Paragraph, Row, Table,
TableState,
},
Frame,
};
use std::collections::HashSet;
+3 -3
View File
@@ -1,12 +1,12 @@
use crate::models::{SearchEntry, SearchStatus};
use crate::ui::{
border_style, border_type, header_style, highlight_style, success_style,
warning_style, HIGHLIGHT_SYMBOL,
HIGHLIGHT_SYMBOL, border_style, border_type, header_style, highlight_style,
success_style, warning_style,
};
use ratatui::{
Frame,
layout::Rect,
widgets::{Block, Borders, Cell, HighlightSpacing, Row, Table, TableState},
Frame,
};
pub fn render_searches_pane(