chore: formatting
This commit is contained in:
+16
-8
@@ -4,16 +4,16 @@ mod models;
|
||||
mod ui;
|
||||
|
||||
use clap::Parser;
|
||||
use cli::{parse_server_address, Cli, Commands};
|
||||
use cli::{Cli, Commands, parse_server_address};
|
||||
use color_eyre::Result;
|
||||
use config::SearchConfig;
|
||||
use soulseek_rs::{Client, ClientSettings, PeerAddress};
|
||||
use std::{
|
||||
env,
|
||||
sync::{atomic::AtomicBool, Arc},
|
||||
sync::{Arc, atomic::AtomicBool},
|
||||
time::Duration,
|
||||
};
|
||||
use ui::{launch_main_tui, show_multi_download_progress, FileSelector};
|
||||
use ui::{FileSelector, launch_main_tui, show_multi_download_progress};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
@@ -33,14 +33,22 @@ fn main() -> Result<()> {
|
||||
// Set LOG_FILE env var if provided via CLI
|
||||
if let Some(log_file) = &cli.log_file {
|
||||
// SAFETY: Called before any threads are spawned
|
||||
unsafe { env::set_var("LOG_FILE", log_file.to_string_lossy().to_string()) };
|
||||
unsafe {
|
||||
env::set_var("LOG_FILE", log_file.to_string_lossy().to_string())
|
||||
};
|
||||
}
|
||||
|
||||
let username = cli.username
|
||||
.ok_or_else(|| color_eyre::eyre::eyre!("Username required: use --username or set SOULSEEK_USERNAME env var"))?;
|
||||
let username = cli.username.ok_or_else(|| {
|
||||
color_eyre::eyre::eyre!(
|
||||
"Username required: use --username or set SOULSEEK_USERNAME env var"
|
||||
)
|
||||
})?;
|
||||
|
||||
let password = cli.password
|
||||
.ok_or_else(|| color_eyre::eyre::eyre!("Password required: use --password or set SOULSEEK_PASSWORD env var"))?;
|
||||
let password = cli.password.ok_or_else(|| {
|
||||
color_eyre::eyre::eyre!(
|
||||
"Password required: use --password or set SOULSEEK_PASSWORD env var"
|
||||
)
|
||||
})?;
|
||||
|
||||
let (server_host, server_port) = parse_server_address(&cli.server)?;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::models::FileDisplayData;
|
||||
use ratatui::{layout::Rect, widgets::TableState};
|
||||
use soulseek_rs::{types::Download, DownloadStatus};
|
||||
use soulseek_rs::{DownloadStatus, types::Download};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{mpsc::Receiver, mpsc::Sender, Arc};
|
||||
use std::sync::{Arc, mpsc::Receiver, mpsc::Sender};
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
||||
@@ -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') => {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user