diff --git a/.gitignore b/.gitignore index 860aa41..5a61e45 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ result/**/* #.idea/ # .direnv + +# ignore (possible) sound files +**/*.{mp3,wav} diff --git a/.rustfmt.toml b/.rustfmt.toml index 44148a2..49013dd 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1 +1,2 @@ +style_edition = "2024" reorder_imports = true diff --git a/Cargo.toml b/Cargo.toml index 576f3af..6c790fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,9 @@ name = "timr-tui" version = "1.1.0" description = "TUI to organize your time: Pomodoro, Countdown, Timer." -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +# Reminder: Always keep `channel` in `rust-toolchain.toml` in sync with `rust-version`. +rust-version = "1.85.0" homepage = "https://github.com/sectore/timr-tui" repository = "https://github.com/sectore/timr-tui" readme = "README.md" diff --git a/flake.lock b/flake.lock index 41861cc..6834ce2 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "crane": { "locked": { - "lastModified": 1738652123, - "narHash": "sha256-zdZek5FXK/k95J0vnLF0AMnYuZl4AjARq83blKuJBYY=", + "lastModified": 1739936662, + "narHash": "sha256-x4syUjNUuRblR07nDPeLDP7DpphaBVbUaSoeZkFbGSk=", "owner": "ipetkov", "repo": "crane", - "rev": "c7e015a5fcefb070778c7d91734768680188a9cd", + "rev": "19de14aaeb869287647d9461cbd389187d8ecdb7", "type": "github" }, "original": { @@ -23,11 +23,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1738650687, - "narHash": "sha256-1tvCUR1+/F3IT1K4QHTcEO+vsip/P1iluPIttX57Ry8=", + "lastModified": 1740378829, + "narHash": "sha256-cwmm7F73aQFJY6YN1roNibNKwxT6FlfXkG3MEbpSp7Q=", "owner": "nix-community", "repo": "fenix", - "rev": "37a1f29ebf98fbbac667730edc5dab4ebe2e3954", + "rev": "92823f1b0c919d7e2d806956aaf98e90f3761ab7", "type": "github" }, "original": { @@ -56,11 +56,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1738546358, - "narHash": "sha256-nLivjIygCiqLp5QcL7l56Tca/elVqM9FG1hGd9ZSsrg=", + "lastModified": 1740367490, + "narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c6e957d81b96751a3d5967a0fd73694f303cc914", + "rev": "0196c0175e9191c474c26ab5548db27ef5d34b05", "type": "github" }, "original": { @@ -81,11 +81,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1738591430, - "narHash": "sha256-Q4tPO6rH/q41IZG+NGy/Pjd2RW/bRDVjVjBh9LaVWE4=", + "lastModified": 1740329432, + "narHash": "sha256-eKQ7aBkNvF5AhUpyJ1cW450jxomZ4gTIaYir5qsNl7Y=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "13c17db07b1201e3c460b4cc0ee49ac4d0ace0e5", + "rev": "6d68c475c7aaf7534251182662456a4bf4216dfe", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 49ac421..0e67c40 100644 --- a/flake.nix +++ b/flake.nix @@ -18,31 +18,32 @@ }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - toolchain = with fenix.packages.${system}; - combine [ - minimal.rustc - minimal.cargo - targets.x86_64-pc-windows-gnu.latest.rust-std - targets.x86_64-unknown-linux-musl.latest.rust-std - ]; + + toolchain = + fenix.packages.${system}.fromToolchainFile + { + file = ./rust-toolchain.toml; + # sha256 = nixpkgs.lib.fakeSha256; + sha256 = "sha256-AJ6LX/Q/Er9kS15bn9iflkUwcgYqRQxiOIL2ToVAXaU="; + }; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; - # Common build inputs for both native and cross compilation commonArgs = { src = craneLib.cleanCargoSource ./.; - cargoArtifacts = craneLib.buildDepsOnly { - src = craneLib.cleanCargoSource ./.; - }; strictDeps = true; doCheck = false; # skip tests during nix build }; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + # Native build timr = craneLib.buildPackage commonArgs; # Linux build w/ statically linked binaries staticLinuxBuild = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; }); @@ -75,14 +76,10 @@ windows = windowsBuild; }; - # Development shell with all necessary tools - devShell = with nixpkgs.legacyPackages.${system}; - mkShell { - buildInputs = with fenix.packages.${system}.stable; + devShells.default = with nixpkgs.legacyPackages.${system}; + craneLib.devShell { + packages = [ - rust-analyzer - clippy - rustfmt toolchain pkgs.just pkgs.nixd @@ -96,7 +93,7 @@ ]; inherit (commonArgs) src; - RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + ALSA_PLUGIN_DIR = if stdenv.isLinux then "${pkgs.pipewire}/lib/alsa-lib/" diff --git a/justfile b/justfile index b75e628..eac8df2 100644 --- a/justfile +++ b/justfile @@ -6,32 +6,42 @@ default: @just --list alias b := build -alias f := format -alias l := lint -alias t := test -alias r := run # build app build: cargo build +alias t := test + # run tests test: cargo test +alias f := format + # format files format: just --fmt cargo fmt +alias l := lint + # lint lint: cargo clippy --no-deps +alias r := run + # run app run: cargo run +alias rs := run-sound + +# run app while sound feature is enabled. It expects a path to a sound file. +run-sound path: + cargo run --features sound -- --sound={{ path }} + # demos alias dp := demo-pomodoro diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..19e1540 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,6 @@ +[toolchain] +# Reminder: Always keep `rust-version` in `Cargo.toml` in sync with `channel`. +channel = "1.85.0" +components = ["clippy", "rustfmt", "rust-src", "rust-analyzer"] +targets = ["x86_64-pc-windows-gnu", "x86_64-unknown-linux-musl"] +profile = "minimal" diff --git a/src/common.rs b/src/common.rs index a05da49..656bb97 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,8 +1,8 @@ use clap::ValueEnum; use ratatui::symbols::shade; use serde::{Deserialize, Serialize}; -use time::format_description; use time::OffsetDateTime; +use time::format_description; #[derive( Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default, Serialize, Deserialize, diff --git a/src/config.rs b/src/config.rs index 9434f3c..be58afe 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,5 @@ use crate::constants::APP_NAME; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::{Result, eyre}; use directories::ProjectDirs; use std::fs; use std::path::PathBuf; diff --git a/src/duration.rs b/src/duration.rs index 816096f..8275cd7 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -1,6 +1,6 @@ use color_eyre::{ - eyre::{ensure, eyre}, Report, + eyre::{ensure, eyre}, }; use std::fmt; use std::time::Duration; diff --git a/src/events.rs b/src/events.rs index 3321488..8bc231c 100644 --- a/src/events.rs +++ b/src/events.rs @@ -3,7 +3,7 @@ use futures::{Stream, StreamExt}; use std::{pin::Pin, time::Duration}; use tokio::sync::mpsc; use tokio::time::interval; -use tokio_stream::{wrappers::IntervalStream, StreamMap}; +use tokio_stream::{StreamMap, wrappers::IntervalStream}; use crate::common::ClockTypeId; use crate::constants::{FPS_VALUE_MS, TICK_VALUE_MS}; diff --git a/src/logging.rs b/src/logging.rs index 0d8942c..83795da 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::{Result, eyre}; use std::fs; use std::path::PathBuf; use tracing::level_filters::LevelFilter; diff --git a/src/terminal.rs b/src/terminal.rs index a6d7509..cc6f3e3 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -5,7 +5,7 @@ use crossterm::{ cursor, execute, terminal::{EnterAlternateScreen, LeaveAlternateScreen}, }; -use ratatui::{backend::CrosstermBackend, Terminal as RatatuiTerminal}; +use ratatui::{Terminal as RatatuiTerminal, backend::CrosstermBackend}; pub type Terminal = RatatuiTerminal>; diff --git a/src/widgets/clock.rs b/src/widgets/clock.rs index 8a06fe7..56a96b4 100644 --- a/src/widgets/clock.rs +++ b/src/widgets/clock.rs @@ -15,7 +15,7 @@ use crate::{ events::{AppEvent, AppEventTx}, utils::center_horizontal, widgets::clock_elements::{ - Colon, Digit, Dot, COLON_WIDTH, DIGIT_HEIGHT, DIGIT_SPACE_WIDTH, DIGIT_WIDTH, DOT_WIDTH, + COLON_WIDTH, Colon, DIGIT_HEIGHT, DIGIT_SPACE_WIDTH, DIGIT_WIDTH, DOT_WIDTH, Digit, Dot, }, }; diff --git a/src/widgets/edit_time.rs b/src/widgets/edit_time.rs index 9a709bd..c91ccb2 100644 --- a/src/widgets/edit_time.rs +++ b/src/widgets/edit_time.rs @@ -9,7 +9,7 @@ use ratatui::{ use crate::{ common::Style, - widgets::clock_elements::{Colon, Digit, COLON_WIDTH, DIGIT_SPACE_WIDTH, DIGIT_WIDTH}, + widgets::clock_elements::{COLON_WIDTH, Colon, DIGIT_SPACE_WIDTH, DIGIT_WIDTH, Digit}, }; use super::clock_elements::DIGIT_HEIGHT;