From ef2ef30ab91f9f42d98ecf53d8375f36a75951bc Mon Sep 17 00:00:00 2001 From: Henry Merrilees Date: Sun, 20 Aug 2023 02:37:53 -0700 Subject: [PATCH] fmt :( --- src/main.rs | 58 +++++++++++++++++++++++++++------------------------- src/utils.rs | 2 -- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main.rs b/src/main.rs index e8d4a46..51b9305 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ //! # The feedback-oriented utility for a practice-oriented life. //! //! # UI demo + TLDR -//! +//! //! ```bash //! prac list //! ``` @@ -34,13 +34,13 @@ //! ## What's so special about prac? //! Not much, and that's on purpose, but there are a few key differences: //! - Rather than "events" being triggered by the clock/calendar, which are not privileged to your -//! psychological state, the proc lifecycle starts when the user gets stuck in their current task -//! or otherwise decides it's time to do something new. This avoids flow-breaking interruptions +//! psychological state, the proc lifecycle starts when the user gets stuck in their current task +//! or otherwise decides it's time to do something new. This avoids flow-breaking interruptions //! while encoraging the user to become more in tune with their own needs and psychological rhythms. //! - Rather than on a scheduled interval, items run on time elapsed since prior log. E.g. a //! daily task period begins when you log it, and ends within 24 hours (plus a default 2-hr grace period). //! Time does not displace your agency, rather time-since-last-log for each practice is displayed -//! as a fraction of the period set for each. This information can be incorporated into the final decision entirely on the users terms. +//! as a fraction of the period set for each. This information can be incorporated into the final decision entirely on the users terms. //! - Tracking is dead-simple, intentionally adding no functionality that is not possible with pen //! and paper. Time is tracked is a sum total of self-reported increments. Logging is done in plain-text. //! @@ -52,13 +52,13 @@ //! - With elapsed-time periods, an overrun is no big deal, nothing stacks up, just log it when you //! get to it and you'll start again with a full period. //! - You also are not "penalized" for overachieving / finishing early... just make sure you are working at a -//! pace sustainable to finish within the next period which you have just moved forward. +//! pace sustainable to finish within the next period which you have just moved forward. //! - If you find yourself regularly finishing very early/late, no big deal! Just take it as a sign //! that you need to adjust the period of your feedback cycle! //! //! //! -//! +//! use clap::{Parser, Subcommand}; use serde::{Deserialize, Serialize}; use skim::prelude::*; @@ -79,7 +79,7 @@ mod utils; use utils::TimeUnit; // TODO, config edit command - /// Configuration state. +/// Configuration state. #[derive(Serialize, Deserialize)] struct Config { grace_period: GracePeriod, @@ -113,16 +113,16 @@ struct State { #[derive(Serialize, Deserialize)] struct Practice { - created: SystemTime, + created: SystemTime, // last time logged - logged: SystemTime, + logged: SystemTime, // how often you wish to repeat practice - period: Duration, + period: Duration, // unique id of practice, will be used for retrieval - name: String, + name: String, // take notes - notes: String, - cumulative: Duration, + notes: String, + cumulative: Duration, // TODO maybe a Completion struct? then a body enum {practice, Task} that contains Vec for practice and raw // Completion for task. Trying not to prematurely optimize. } @@ -194,16 +194,20 @@ impl State { Ok(path) } else if let Ok(practice_home) = var("PRAC_HOME") { let practice_home = PathBuf::from(practice_home); - std::fs::create_dir_all(&practice_home).context("$PRAC_HOME specified but could not be created.")?; + std::fs::create_dir_all(&practice_home) + .context("$PRAC_HOME specified but could not be created.")?; let path = practice_home.join("prac.json"); Ok(path) } else if let Some(data_home) = dirs::data_dir() { let default_dir = data_home.join("prac"); - std::fs::create_dir_all(&default_dir).with_context(|| format!("could not create {}", default_dir.display()))?; + std::fs::create_dir_all(&default_dir) + .with_context(|| format!("could not create {}", default_dir.display()))?; let path = default_dir.join("prac.json"); Ok(path) } else { - let path = dirs::home_dir().context("could not find home directory")?.join(".prac.json"); + let path = dirs::home_dir() + .context("could not find home directory")? + .join(".prac.json"); Ok(path) } } @@ -216,7 +220,6 @@ struct Cli { command: SubCommand, } - // TODO: config edit command #[derive(Subcommand)] enum SubCommand { @@ -265,7 +268,7 @@ enum SubCommand { Reset, /// Show state file location. /// - /// State is stored in $PRACTICE_PATH, $PRACTICE_HOME/prac.json, [dirs::data_dir]/prac/prac.json + /// State is stored in $PRACTICE_PATH, $PRACTICE_HOME/prac.json, [dirs::data_dir]/prac/prac.json /// or [dirs::home_dir]/.prac.json, searched in that order. /// /// It's a good idea to vcs your state file. @@ -290,7 +293,6 @@ enum SubCommand { }, } - fn main() -> Result<()> { let state_path = State::get_path()?; @@ -317,7 +319,7 @@ fn main() -> Result<()> { time_unit: unit, } => { let notes = notes.unwrap_or_else(|| { - let placeholder = if state.routines.is_empty() { + let placeholder = if state.routines.is_empty() { Some("\ When you complete a practice, you should log it with `prac log`.\n\ Come back to these practice notes and view this page later in your `$EDITOR` with `prac notes`. \n\ @@ -355,7 +357,9 @@ fn main() -> Result<()> { let body = utils::long_edit(Some(practice.notes.clone()))?; practice.notes = body; } else { - println!("Good job! It's a good idea to make notes on your progress with `prac notes`."); + println!( + "Good job! It's a good idea to make notes on your progress with `prac notes`." + ); } } SubCommand::Notes { name } => { @@ -371,9 +375,8 @@ fn main() -> Result<()> { // Confirm // TODO this is terrible let options = SkimOptionsBuilder::default().build().unwrap(); - let items = SkimItemReader::default().of_bufread(Cursor::new( - [&confirm, "Abort"].join("\n") - )); + let items = + SkimItemReader::default().of_bufread(Cursor::new([&confirm, "Abort"].join("\n"))); // TODO figure out what these errors acutally are let selected_items = Skim::run_with(&options, Some(items)) @@ -393,9 +396,8 @@ fn main() -> Result<()> { return Ok(()); } else { practice.remove(); - print !("Removed {}", name); + print!("Removed {}", name); } - } SubCommand::List { cumulative, period } => { if state.routines.is_empty() { @@ -408,8 +410,8 @@ fn main() -> Result<()> { .map(|name| name.len()) .max() .unwrap_or(0) - .min(30); // TODO magic number - + .min(30); // TODO magic number + let term_width = termsize::get().context("failed to obtain termsize")?.cols; println!(); diff --git a/src/utils.rs b/src/utils.rs index 456525b..d073de3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize}; use anyhow::{Context, Result}; - /// A unit of time. #[derive(ValueEnum, Clone, Serialize, Deserialize)] pub enum TimeUnit { @@ -38,7 +37,6 @@ impl TimeUnit { } } - /// Write content to file pub fn long_edit(content: Option) -> Result { let editor = var("EDITOR").context("EDITOR environment variable not found.")?;