mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-10-21 20:10:35 +00:00
fix(log): decrease log size
This commit is contained in:
parent
b988880c41
commit
b563c7ea24
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -342,6 +342,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2045,6 +2046,7 @@ dependencies = [
|
||||
"color-eyre",
|
||||
"crossterm 0.29.0",
|
||||
"derive_macro",
|
||||
"derive_more",
|
||||
"dirs",
|
||||
"merge",
|
||||
"ratatui",
|
||||
@ -2102,6 +2104,12 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.9.0"
|
||||
|
||||
@ -6,9 +6,10 @@ license = "GPLv3"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
derive_macro = { path = "derive_macro" }
|
||||
color-eyre = "0.6"
|
||||
crossterm = "0.29"
|
||||
derive_macro = { path = "derive_macro" }
|
||||
derive_more = { version = "2.0", features = ["display"] }
|
||||
dirs = "6.0"
|
||||
merge = "0.2"
|
||||
ratatui = { version = "0.29" }
|
||||
|
||||
@ -1,20 +1,39 @@
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
use derive_more::Display;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Display)]
|
||||
pub enum Action {
|
||||
#[display("Quit")]
|
||||
Quit,
|
||||
#[display("Next Tab")]
|
||||
NextTab,
|
||||
#[display("Previous Tab")]
|
||||
PrevTab,
|
||||
#[display("Next Torrent")]
|
||||
NextTorrent,
|
||||
#[display("Previous Torrent")]
|
||||
PrevTorrent,
|
||||
#[display("Switch to Tab {}", _0)]
|
||||
SwitchTab(u8),
|
||||
#[display("Toggle Help")]
|
||||
ToggleHelp,
|
||||
#[display("Toggle Torrent")]
|
||||
ToggleTorrent,
|
||||
#[display("Toggle All Torrents")]
|
||||
ToggleAll,
|
||||
#[display("Pause All Torrents")]
|
||||
PauseAll,
|
||||
#[display("Start All Torrents")]
|
||||
StartAll,
|
||||
#[display("Move Torrent(-s)")]
|
||||
Move,
|
||||
#[display("Delete Torrent(-s) (force: {})", _0)]
|
||||
Delete(bool),
|
||||
#[display("Rename Torrent")]
|
||||
Rename,
|
||||
#[display("Select")]
|
||||
Select,
|
||||
#[display("Submit")]
|
||||
Submit,
|
||||
#[display("Cancel")]
|
||||
Cancel,
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use derive_macro::FromFile;
|
||||
use merge::{option::overwrite_none, Merge};
|
||||
use merge::{Merge, option::overwrite_none};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Merge)]
|
||||
|
||||
@ -9,6 +9,7 @@ use log::{LogConfig, LogConfigFile};
|
||||
use merge::{Merge, option::overwrite_none};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, Merge)]
|
||||
pub struct ConfigFile {
|
||||
@ -28,28 +29,39 @@ pub struct Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
#[tracing::instrument(name = "Loading configuration")]
|
||||
pub fn load() -> Result<Self> {
|
||||
let mut config = ConfigFile::default();
|
||||
|
||||
// Load system-wide config
|
||||
let system_config_path = PathBuf::from("/etc/xdg/traxor/config.toml");
|
||||
if system_config_path.exists() {
|
||||
info!("Loading system-wide config from: {:?}", system_config_path);
|
||||
let config_str = std::fs::read_to_string(&system_config_path)?;
|
||||
let system_config = toml::from_str::<ConfigFile>(&config_str)?;
|
||||
config.merge(system_config);
|
||||
info!("Successfully loaded system-wide config.");
|
||||
} else {
|
||||
warn!("System-wide config not found at: {:?}", system_config_path);
|
||||
}
|
||||
|
||||
// Load user-specific config
|
||||
let user_config_path = Self::get_config_path()?;
|
||||
if user_config_path.exists() {
|
||||
info!("Loading user-specific config from: {:?}", user_config_path);
|
||||
let config_str = std::fs::read_to_string(&user_config_path)?;
|
||||
let user_config = toml::from_str::<ConfigFile>(&config_str)?;
|
||||
config.merge(user_config);
|
||||
info!("Successfully loaded user-specific config.");
|
||||
} else {
|
||||
warn!("User-specific config not found at: {:?}", user_config_path);
|
||||
}
|
||||
|
||||
debug!("Configuration loaded successfully.");
|
||||
Ok(config.into())
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "Getting config path")]
|
||||
fn get_config_path() -> Result<PathBuf> {
|
||||
let config_dir = std::env::var("XDG_CONFIG_HOME")
|
||||
.map(PathBuf::from)
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
use crate::app::{App, action::Action};
|
||||
use color_eyre::Result;
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use tracing::{Level, event, info_span};
|
||||
use tracing::{debug, info};
|
||||
|
||||
#[tracing::instrument(name = "Handling input", skip(app))]
|
||||
async fn handle_input(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<Action>> {
|
||||
match key_event.code {
|
||||
KeyCode::Enter => Ok(Some(Action::Submit)),
|
||||
@ -26,15 +27,13 @@ async fn handle_input(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<A
|
||||
}
|
||||
|
||||
/// Handles the key events of [`App`].
|
||||
#[tracing::instrument]
|
||||
#[tracing::instrument(name = "Getting action", skip(app))]
|
||||
pub async fn get_action(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<Action>> {
|
||||
if app.input_mode {
|
||||
return handle_input(key_event, app).await;
|
||||
}
|
||||
|
||||
let span = info_span!("get_action");
|
||||
let _enter = span.enter();
|
||||
event!(Level::INFO, "handling key event: {:?}", key_event);
|
||||
debug!("handling key event: {:?}", key_event);
|
||||
|
||||
let keybinds = &app.config.keybinds;
|
||||
|
||||
@ -65,11 +64,9 @@ pub async fn get_action(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option
|
||||
}
|
||||
|
||||
/// Handles the updates of [`App`].
|
||||
#[tracing::instrument]
|
||||
#[tracing::instrument(name = "Update", skip(app))]
|
||||
pub async fn update(app: &mut App<'_>, action: Action) -> Result<()> {
|
||||
let span = info_span!("update");
|
||||
let _enter = span.enter();
|
||||
event!(Level::INFO, "updating app with action: {:?}", action);
|
||||
info!("updating app with action: {}", action);
|
||||
match action {
|
||||
Action::Quit => app.quit(),
|
||||
Action::NextTab => app.next_tab(),
|
||||
|
||||
19
src/main.rs
19
src/main.rs
@ -1,6 +1,7 @@
|
||||
use color_eyre::Result;
|
||||
use ratatui::{Terminal, backend::CrosstermBackend};
|
||||
use std::io;
|
||||
use tracing::{debug, trace};
|
||||
use traxor::{
|
||||
app::App,
|
||||
config::Config,
|
||||
@ -14,8 +15,9 @@ use traxor::{
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
// Load configuration.
|
||||
debug!("Loading configuration...");
|
||||
let config = Config::load()?;
|
||||
debug!("Configuration loaded.");
|
||||
|
||||
// Setup the logger.
|
||||
setup_logger(&config)?;
|
||||
@ -36,14 +38,23 @@ async fn main() -> Result<()> {
|
||||
tui.draw(&mut app)?;
|
||||
// Handle events.
|
||||
match tui.events.next()? {
|
||||
Event::Tick => app.tick().await?,
|
||||
Event::Tick => {
|
||||
trace!(target: "app", "Event::Tick");
|
||||
app.tick().await?;
|
||||
}
|
||||
Event::Key(key_event) => {
|
||||
trace!(target: "app", "Event::Key: {:?}", key_event);
|
||||
if let Some(action) = get_action(key_event, &mut app).await? {
|
||||
trace!(target: "app", "Action: {:?}", action);
|
||||
update(&mut app, action).await?;
|
||||
}
|
||||
}
|
||||
Event::Mouse(_) => {}
|
||||
Event::Resize(_, _) => {}
|
||||
Event::Mouse(mouse_event) => {
|
||||
trace!(target: "app", "Event::Mouse: {:?}", mouse_event);
|
||||
}
|
||||
Event::Resize(x, y) => {
|
||||
trace!(target: "app", "Event::Resize: ({}, {})", x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user