Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
739f76fa90 | |||
1a10f620b4 | |||
323c2fba18 | |||
3c6cc462f3 |
8 changed files with 74 additions and 35 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
@ -651,6 +651,12 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
|
@ -976,10 +982,16 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.164"
|
||||
name = "ryu"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
|
||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.179"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a5bf42b8d227d4abf38a1ddb08602e229108a517cd4e5bb28f9c7eaafdce5c0"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
@ -996,15 +1008,26 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.164"
|
||||
version = "1.0.179"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
|
||||
checksum = "741e124f5485c7e60c03b043f79f320bff3527f4bbf12cf3831750dc46a0ec2c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_repr"
|
||||
version = "0.1.16"
|
||||
|
@ -1170,6 +1193,7 @@ dependencies = [
|
|||
"notify-rust",
|
||||
"serde",
|
||||
"serde_cbor",
|
||||
"serde_json",
|
||||
"signal-hook",
|
||||
"thiserror",
|
||||
]
|
||||
|
|
|
@ -14,5 +14,6 @@ libc = "0.2.147"
|
|||
notify-rust = "4.8.0"
|
||||
serde = { version = "1.0.164", features = ["derive"] }
|
||||
serde_cbor = "0.11.2"
|
||||
serde_json = "1.0.105"
|
||||
signal-hook = "0.3.17"
|
||||
thiserror = "1.0.44"
|
||||
|
|
37
flake.lock
37
flake.lock
|
@ -2,14 +2,16 @@
|
|||
"nodes": {
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1686572087,
|
||||
"narHash": "sha256-jXTut7ZSYqLEgm/nTk7TuVL2ExahTip605bLINklAnQ=",
|
||||
"lastModified": 1692351612,
|
||||
"narHash": "sha256-KTGonidcdaLadRnv9KFgwSMh1ZbXoR/OBmPjeNMhFwU=",
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"rev": "8507af04eb40c5520bd35d9ce6f9d2342cea5ad1",
|
||||
"rev": "78789c30d64dea2396c9da516bbcc8db3a475207",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -21,24 +23,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1685677062,
|
||||
"narHash": "sha256-zoHF7+HNwNwne2XEomphbdc4Y8tdWT16EUxUTXpOKpQ=",
|
||||
"path": "/nix/store/dnqwkazyg92hzya7400klxlk072g3zsk-source",
|
||||
"rev": "95be94370d09f97f6af6a1df1eb9649b5260724e",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1687103638,
|
||||
"narHash": "sha256-dwy/TK6Db5W7ivcgmcxUykhFwodIg0jrRzOFt7H5NUc=",
|
||||
"lastModified": 1692934111,
|
||||
"narHash": "sha256-9EEE59v/esKNMR5zKbLRV9NoRPYvERw5jHQOnfr47bk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "91430887645a0953568da2f3e9a3a3bb0a0378ac",
|
||||
"rev": "1e44a037bbf4fcaba041436e65e87be88f3f495b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -51,7 +40,7 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
|
@ -75,11 +64,11 @@
|
|||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1687171271,
|
||||
"narHash": "sha256-BJlq+ozK2B1sJDQXS3tzJM5a+oVZmi1q0FlBK/Xqv7M=",
|
||||
"lastModified": 1692799911,
|
||||
"narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "abfb11bd1aec8ced1c9bb9adfe68018230f4fb3c",
|
||||
"rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
{
|
||||
inputs = {
|
||||
naersk.url = "github:nix-community/naersk/master";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
naersk.url = "github:nix-community/naersk/master";
|
||||
naersk.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, utils, naersk }:
|
||||
|
|
|
@ -12,9 +12,13 @@ use std::time::Duration;
|
|||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
|
||||
#[arg(short, long)]
|
||||
#[clap(default_value_t = format!("{}/timers.socket", run_path()))]
|
||||
pub socket: String,
|
||||
|
||||
#[arg(long)]
|
||||
pub json: bool
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
|
|
|
@ -48,6 +48,10 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
}
|
||||
};
|
||||
let answer = send_command(&args.socket, daemon_command)?;
|
||||
print!("{}", answer);
|
||||
if args.json {
|
||||
println!("{}", serde_json::to_string(&answer)?)
|
||||
} else {
|
||||
print!("{}", answer);
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -19,10 +19,11 @@ impl Display for Pomodoro {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Pomodoro ({}, {}, {}) currently {} with {} remaining.",
|
||||
"Pomodoro ({}, {}, {}) currently {} {} with {} remaining.\n",
|
||||
humantime::format_duration(self.work),
|
||||
humantime::format_duration(self.pause),
|
||||
humantime::format_duration(self.long_pause),
|
||||
self.timer.state,
|
||||
self.status,
|
||||
humantime::format_duration(self.timer.remaining())
|
||||
)
|
||||
|
|
21
src/timer.rs
21
src/timer.rs
|
@ -11,7 +11,7 @@ pub struct Timer {
|
|||
#[serde(with = "approx_instant")]
|
||||
start: Instant,
|
||||
duration: Duration,
|
||||
state: State,
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
|
@ -20,6 +20,16 @@ pub enum State {
|
|||
Paused,
|
||||
}
|
||||
|
||||
impl Display for State {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let string = match self {
|
||||
State::Running => "running",
|
||||
State::Paused => "paused",
|
||||
};
|
||||
write!(f, "{}", string)
|
||||
}
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
/// Create a new [`Timer`] with the supplied name and duration
|
||||
/// The timer is instantly started.
|
||||
|
@ -72,10 +82,16 @@ impl Timer {
|
|||
|
||||
impl Display for Timer {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
let state_message = match self.state {
|
||||
State::Running => "has",
|
||||
State::Paused => "is paused and has",
|
||||
};
|
||||
|
||||
write!(
|
||||
f,
|
||||
"{} has {} remaining.",
|
||||
"'{}' {} {} remaining.",
|
||||
self.name,
|
||||
state_message,
|
||||
humantime::format_duration(self.remaining())
|
||||
)
|
||||
}
|
||||
|
@ -107,4 +123,3 @@ mod approx_instant {
|
|||
Ok(instant)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue