mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-12-31 13:42:44 +00:00
Compare commits
No commits in common. "161362fc1f801d19921524458c2ce3194e31ed09" and "46486a340934e6f24a85181e7f472177c3200403" have entirely different histories.
161362fc1f
...
46486a3409
5
.github/workflows/rust.yml
vendored
5
.github/workflows/rust.yml
vendored
@ -16,8 +16,9 @@ jobs:
|
|||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: cargo fmt -- --check
|
run: cargo fmt -- --check
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release
|
run: cargo build --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test
|
run: cargo test --verbose
|
||||||
- name: Run clippy
|
- name: Run clippy
|
||||||
run: cargo clippy -- -D warnings
|
run: cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
|||||||
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -432,8 +432,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "filecaster"
|
name = "filecaster"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cc97921cbd5451445637b91a0237b3c9316fa550ea7ff166a40be7ce5afad335"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"filecaster-derive",
|
"filecaster-derive",
|
||||||
"merge",
|
"merge",
|
||||||
@ -443,8 +441,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "filecaster-derive"
|
name = "filecaster-derive"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f5c7bc432f529eac3ec2d60812e05c1eae39fde9d7434fe59e64c03c27da882"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"merge",
|
"merge",
|
||||||
"proc-macro-error2",
|
"proc-macro-error2",
|
||||||
|
|||||||
@ -6,7 +6,9 @@ license = "GPLv3"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
filecaster = { version = "0.2", features = ["derive", "merge"] }
|
filecaster = { version = "0.2", features = [
|
||||||
|
"merge",
|
||||||
|
], path = "../filecaster/filecaster/" }
|
||||||
color-eyre = "0.6"
|
color-eyre = "0.6"
|
||||||
crossterm = "0.29"
|
crossterm = "0.29"
|
||||||
derive_more = { version = "2.0", features = ["display"] }
|
derive_more = { version = "2.0", features = ["display"] }
|
||||||
|
|||||||
@ -43,3 +43,4 @@ mod tests {
|
|||||||
assert_eq!(file_size.to_string(), "1.00 GB");
|
assert_eq!(file_size.to_string(), "1.00 GB");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,3 +43,4 @@ mod tests {
|
|||||||
assert_eq!(net_speed.to_string(), "1.00 GB/s");
|
assert_eq!(net_speed.to_string(), "1.00 GB/s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -157,4 +157,4 @@ mod tests {
|
|||||||
let display = UnitDisplay::new(&unit, &["B", "KB", "MB"]);
|
let display = UnitDisplay::new(&unit, &["B", "KB", "MB"]);
|
||||||
assert_eq!(display.to_string(), "512 B");
|
assert_eq!(display.to_string(), "512 B");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,8 +17,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
const DEFAULT_CONFIG_STR: &str = include_str!("../../config/default.toml");
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, FromFile)]
|
#[derive(Debug, Clone, FromFile)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub keybinds: KeybindsConfig,
|
pub keybinds: KeybindsConfig,
|
||||||
@ -27,23 +25,12 @@ pub struct Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Load configuration with fallback to embedded defaults.
|
|
||||||
///
|
|
||||||
/// Merge order:
|
|
||||||
/// 1. Embedded defaults
|
|
||||||
/// 2. System-wide config (`/etc/xdg/traxor/config.toml`)
|
|
||||||
/// 3. User config (`~/.config/traxor/config.toml`)
|
|
||||||
///
|
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error if:
|
/// TODO: add error types
|
||||||
/// - The embedded default config cannot be parsed (should never happen unless corrupted at build time).
|
|
||||||
/// - The system-wide or user config file cannot be read due to I/O errors.
|
|
||||||
/// - The TOML in any config file is invalid and cannot be parsed.
|
|
||||||
#[tracing::instrument(name = "Loading configuration")]
|
#[tracing::instrument(name = "Loading configuration")]
|
||||||
pub fn load() -> Result<Self> {
|
pub fn load() -> Result<Self> {
|
||||||
let mut cfg_file = toml::from_str::<ConfigFile>(DEFAULT_CONFIG_STR)
|
let mut cfg_file = ConfigFile::default();
|
||||||
.context("Failed to parse embedded default config")?;
|
|
||||||
|
|
||||||
let candidates = [
|
let candidates = [
|
||||||
("system-wide", PathBuf::from("/etc/xdg/traxor/config.toml")),
|
("system-wide", PathBuf::from("/etc/xdg/traxor/config.toml")),
|
||||||
|
|||||||
65
src/main.rs
65
src/main.rs
@ -1,11 +1,7 @@
|
|||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use ratatui::{Terminal, backend::CrosstermBackend};
|
use ratatui::{Terminal, backend::CrosstermBackend};
|
||||||
use std::{io, sync::Arc};
|
use std::io;
|
||||||
use tokio::{
|
use tracing::{debug, trace};
|
||||||
sync::Mutex,
|
|
||||||
time::{self, Duration},
|
|
||||||
};
|
|
||||||
use tracing::{trace, warn};
|
|
||||||
use traxor::{
|
use traxor::{
|
||||||
app::App,
|
app::App,
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -19,54 +15,38 @@ use traxor::{
|
|||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
|
||||||
|
debug!("Loading configuration...");
|
||||||
let config = Config::load()?;
|
let config = Config::load()?;
|
||||||
|
debug!("Configuration loaded.");
|
||||||
|
|
||||||
|
// Setup the logger.
|
||||||
setup_logger(&config)?;
|
setup_logger(&config)?;
|
||||||
|
|
||||||
// Wrap App in Arc<Mutex<>> so we can share it between UI and updater
|
// Create an application.
|
||||||
let app = Arc::new(Mutex::new(App::new(config)?));
|
let mut app = App::new(config)?;
|
||||||
|
|
||||||
// Clone for updater task
|
// Initialize the terminal user interface.
|
||||||
let app_clone = app.clone();
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let mut interval = time::interval(Duration::from_secs(2));
|
|
||||||
loop {
|
|
||||||
interval.tick().await;
|
|
||||||
|
|
||||||
let mut app = app_clone.lock().await;
|
|
||||||
if let Err(e) = app.torrents.update().await {
|
|
||||||
warn!("Failed to update torrents: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// TUI setup
|
|
||||||
let backend = CrosstermBackend::new(io::stderr());
|
let backend = CrosstermBackend::new(io::stderr());
|
||||||
let terminal = Terminal::new(backend)?;
|
let terminal = Terminal::new(backend)?;
|
||||||
let events = EventHandler::new(250); // Update time in ms
|
let events = EventHandler::new(250); // Update time in ms
|
||||||
let mut tui = Tui::new(terminal, events);
|
let mut tui = Tui::new(terminal, events);
|
||||||
tui.init()?;
|
tui.init()?;
|
||||||
|
|
||||||
// Main loop
|
// Start the main loop.
|
||||||
loop {
|
while app.running {
|
||||||
{
|
// Render the user interface.
|
||||||
let app_guard = app.lock().await;
|
tui.draw(&mut app)?;
|
||||||
if !app_guard.running {
|
// Handle events.
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut app_guard = app.lock().await;
|
|
||||||
tui.draw(&mut app_guard)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
match tui.events.next()? {
|
match tui.events.next()? {
|
||||||
Event::Tick => {}
|
Event::Tick => {
|
||||||
|
trace!(target: "app", "Event::Tick");
|
||||||
|
app.tick().await?;
|
||||||
|
}
|
||||||
Event::Key(key_event) => {
|
Event::Key(key_event) => {
|
||||||
let mut app_guard = app.lock().await;
|
trace!(target: "app", "Event::Key: {:?}", key_event);
|
||||||
if let Some(action) = get_action(key_event, &mut app_guard).await? {
|
if let Some(action) = get_action(key_event, &mut app).await? {
|
||||||
update(&mut app_guard, action).await?;
|
trace!(target: "app", "Action: {:?}", action);
|
||||||
|
update(&mut app, action).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse_event) => {
|
Event::Mouse(mouse_event) => {
|
||||||
@ -78,6 +58,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit the user interface.
|
||||||
tui.exit()?;
|
tui.exit()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,10 +67,10 @@ fn make_row<'a>(
|
|||||||
highlight: Style,
|
highlight: Style,
|
||||||
) -> Row<'a> {
|
) -> Row<'a> {
|
||||||
let cells = fields.iter().map(|&field| {
|
let cells = fields.iter().map(|&field| {
|
||||||
if let Some(id) = torrent.id
|
if let Some(id) = torrent.id {
|
||||||
&& selected.contains(&id)
|
if selected.contains(&id) {
|
||||||
{
|
return field.value(torrent).set_style(highlight);
|
||||||
return field.value(torrent).set_style(highlight);
|
}
|
||||||
}
|
}
|
||||||
field.value(torrent).into()
|
field.value(torrent).into()
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use ratatui::Terminal;
|
|
||||||
use ratatui::backend::TestBackend;
|
use ratatui::backend::TestBackend;
|
||||||
|
use ratatui::Terminal;
|
||||||
use traxor::event::EventHandler;
|
use traxor::event::EventHandler;
|
||||||
use traxor::tui::Tui;
|
use traxor::tui::Tui;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user