diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e1a9e..e53f990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.15] - + +### Changed + +- Refactored the logic for lising the trash items and removed the redundant block for lising the items in table + ## [0.1.14] - 2025-10-06 ### Changed - Update dependencies to latest versions -### Fixed +### Fixed + - Fixed the linting issues in the codebase ## [0.1.13] - 2025-09-18 diff --git a/flake.nix b/flake.nix index 7eaeca8..7628222 100644 --- a/flake.nix +++ b/flake.nix @@ -6,23 +6,32 @@ naersk.url = "github:nix-community/naersk"; }; - outputs = { nixpkgs, naersk, ... }: + outputs = + { nixpkgs, naersk, ... }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; naerskLib = pkgs.callPackage naersk { }; - in { + in + { packages.${system}.default = naerskLib.buildPackage { src = ./.; nativeBuildInputs = [ pkgs.pkg-config ]; }; devShells.${system}.default = pkgs.mkShell { - buildInputs = with pkgs; [ rustc cargo clippy rustfmt rust-analyzer ]; + buildInputs = with pkgs; [ + rustc + cargo + clippy + rustfmt + rust-analyzer + ]; nativeBuildInputs = [ pkgs.pkg-config ]; # env.RUST_SRC_PATH = # "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }; formatter = pkgs.rustfmt; + DIRENV_LOG_FORMAT = ""; }; } diff --git a/src/main.rs b/src/main.rs index 913addd..a9fa664 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ impl List { } } -fn list_specific_trash(seconds: i64) -> Result<(), trash::Error> { +fn list_specific_trash(seconds: i64) -> Result, trash::Error> { let mut list: Vec = vec![]; let entries = os_limited::list()?; let now = Local::now().timestamp(); @@ -48,39 +48,33 @@ fn list_specific_trash(seconds: i64) -> Result<(), trash::Error> { )); } } - let mut table = Table::new(&list); - table.with(Style::rounded()); - table.modify(Columns::first(), Alignment::right()); - println!("{table}"); - Ok(()) + Ok(list) } -fn list_trash() { +fn list_trash() -> Result, trash::Error> { let mut list: Vec = vec![]; - match os_limited::list() { - Ok(trash) => { - for entry in trash { - let time_deleted = Local - .timestamp_opt(entry.time_deleted, 0) - .single() - .map(|dt| dt.format("%Y-%m-%d %H:%M:%S").to_string()) - .unwrap_or_else(|| "Unknown time".to_string()); - - list.push(List::new( - entry.name.to_string_lossy().to_string(), - entry.original_path().to_string_lossy().to_string(), - time_deleted, - )) - } - let mut table = Table::new(&list); - table.with(Style::rounded()); - table.modify(Columns::first(), Alignment::right()); - println!("{table}"); - } - Err(e) => { - eprintln!("{}", format!("Failed to list trash entries: {e}").red()) - } + let trash = os_limited::list()?; + for entry in trash { + let time_deleted = Local + .timestamp_opt(entry.time_deleted, 0) + .single() + .map(|dt| dt.format("%Y-%m-%d %H:%M:%S").to_string()) + .unwrap_or_else(|| "Unknown time".to_string()); + + list.push(List::new( + entry.name.to_string_lossy().to_string(), + entry.original_path().to_string_lossy().to_string(), + time_deleted, + )) } + Ok(list) +} + +fn display_table(list: Vec) { + let mut table = Table::new(&list); + table.with(Style::rounded()); + table.modify(Columns::first(), Alignment::right()); + println!("{table}"); } fn tidy_trash(days: i64) -> Result<(), trash::Error> { @@ -244,11 +238,16 @@ fn main() { if args.is_list() { let seconds = args.get_time_list() * 86400; if seconds == 0 { - list_trash(); + match list_trash() { + Ok(list) => display_table(list), + Err(e) => eprintln!("{}", format!("Failed to list trash entries: {e}").red()), + } + return; } else { - if let Err(e) = list_specific_trash(seconds) { - eprintln!("{}", format!("Failed to list trash entries: {e}").red()); + match list_specific_trash(seconds) { + Ok(list) => display_table(list), + Err(e) => eprintln!("{}", format!("Failed to list trash entries: {e}").red()), } return; }