Skip to content

Commit

Permalink
fmt :(
Browse files Browse the repository at this point in the history
  • Loading branch information
hmerrilees committed Aug 20, 2023
1 parent ba5e56e commit ef2ef30
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
58 changes: 30 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # The feedback-oriented utility for a practice-oriented life.
//!
//! # UI demo + TLDR
//!
//!
//! ```bash
//! prac list
//! ```
Expand Down Expand Up @@ -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.
//!
Expand All @@ -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::*;
Expand All @@ -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,
Expand Down Expand Up @@ -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<Comepletion> for practice and raw
// Completion for task. Trying not to prematurely optimize.
}
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -216,7 +220,6 @@ struct Cli {
command: SubCommand,
}


// TODO: config edit command
#[derive(Subcommand)]
enum SubCommand {
Expand Down Expand Up @@ -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.
Expand All @@ -290,7 +293,6 @@ enum SubCommand {
},
}


fn main() -> Result<()> {
let state_path = State::get_path()?;

Expand All @@ -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\
Expand Down Expand Up @@ -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 } => {
Expand All @@ -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))
Expand All @@ -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() {
Expand All @@ -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!();
Expand Down
2 changes: 0 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize};

use anyhow::{Context, Result};


/// A unit of time.
#[derive(ValueEnum, Clone, Serialize, Deserialize)]
pub enum TimeUnit {
Expand All @@ -38,7 +37,6 @@ impl TimeUnit {
}
}


/// Write content to file
pub fn long_edit(content: Option<String>) -> Result<String> {
let editor = var("EDITOR").context("EDITOR environment variable not found.")?;
Expand Down

0 comments on commit ef2ef30

Please sign in to comment.