Change weight to priority.
This commit is contained in:
parent
3995a47078
commit
0adf14e8d4
14
src/habit.rs
14
src/habit.rs
@ -26,21 +26,25 @@ pub struct Habit
|
||||
uid:String,
|
||||
name:String,
|
||||
bad:bool,
|
||||
weight:u8,
|
||||
priority:char,
|
||||
// Day 0 is Monday. Use number_days_from_monday() to determine index.
|
||||
days_active:[bool;7],
|
||||
}
|
||||
|
||||
impl Habit
|
||||
{
|
||||
pub fn new(name:String, bad:bool, weight:u8, days_active:[bool;7]) -> Self
|
||||
pub fn new(name:String, bad:bool, priority:char, days_active:[bool;7]) -> Self
|
||||
{
|
||||
if ![ 'H','L','M' ].contains(&priority)
|
||||
{
|
||||
panic!("Unknown priority {}", priority);
|
||||
}
|
||||
Self
|
||||
{
|
||||
uid: Uuid::new_v4().hyphenated().to_string(),
|
||||
name,
|
||||
bad,
|
||||
weight,
|
||||
priority,
|
||||
days_active,
|
||||
}
|
||||
}
|
||||
@ -80,10 +84,10 @@ impl Habit
|
||||
pub fn get_uid(&self) -> &String { &self.uid }
|
||||
pub fn get_name(&self) -> &String { &self.name }
|
||||
pub fn get_bad(&self) -> bool { self.bad }
|
||||
pub fn get_weight(&self) -> u8 { self.weight }
|
||||
pub fn get_priority(&self) -> char { self.priority }
|
||||
|
||||
pub fn set_name(&mut self, name:String) { self.name = name; }
|
||||
pub fn set_bad(&mut self, bad:bool) { self.bad = bad; }
|
||||
pub fn set_weight(&mut self, weight:u8) { self.weight = weight; }
|
||||
pub fn set_priority(&mut self, priority:char) { self.priority = priority; }
|
||||
pub fn set_days(&mut self, days:[bool;7]) { self.days_active = days; }
|
||||
}
|
||||
|
@ -126,10 +126,10 @@ impl HabitMgr
|
||||
return days_active;
|
||||
}
|
||||
|
||||
pub fn add(&mut self, name:String, bad:bool, weight:u8, days:String)
|
||||
pub fn add(&mut self, name:String, bad:bool, priority:char, days:String)
|
||||
{
|
||||
let days_active = HabitMgr::days_array_from_string(days);
|
||||
self.habits.push(Habit::new(name.clone(), bad, weight, days_active));
|
||||
self.habits.push(Habit::new(name.clone(), bad, priority, days_active));
|
||||
self.export_habits();
|
||||
|
||||
println!("New habit {} added.", &name);
|
||||
@ -150,13 +150,13 @@ impl HabitMgr
|
||||
println!("UID: {}", habit.get_uid());
|
||||
println!("Active Days: {}", habit.active_days_string());
|
||||
println!("Bad: {}", habit.get_bad());
|
||||
println!("Weight: {}", habit.get_weight());
|
||||
println!("Weight: {}", habit.get_priority());
|
||||
}
|
||||
|
||||
pub fn modify(&mut self, id:usize,
|
||||
name:Option<String>,
|
||||
toggle_bad:bool,
|
||||
weight:Option<u8>,
|
||||
priority:Option<char>,
|
||||
days:Option<String>)
|
||||
{
|
||||
if name.is_some()
|
||||
@ -168,9 +168,9 @@ impl HabitMgr
|
||||
let is_bad = self.habits[id].get_bad();
|
||||
self.habits[id].set_bad(!is_bad);
|
||||
}
|
||||
if weight.is_some()
|
||||
if priority.is_some()
|
||||
{
|
||||
self.habits[id].set_weight(weight.unwrap());
|
||||
self.habits[id].set_priority(priority.unwrap());
|
||||
}
|
||||
if days.is_some()
|
||||
{
|
||||
@ -192,16 +192,16 @@ impl HabitMgr
|
||||
}
|
||||
else
|
||||
{
|
||||
println!(" {0: <3} | {1: <5} | {2: <6} | {3}",
|
||||
"id", "bad", "weight", "name");
|
||||
println!(" {0: <3} | {1: <5} | {2: <8} | {3}",
|
||||
"id", "bad", "priority", "name");
|
||||
for (i, habit) in self.habits.iter().enumerate()
|
||||
{
|
||||
if all || habit.active_today()
|
||||
{
|
||||
println!(" {0: <3} | {1: <5} | {2: <6} | {3}",
|
||||
println!(" {0: <3} | {1: <5} | {2: <8} | {3}",
|
||||
i,
|
||||
habit.get_bad(),
|
||||
habit.get_weight(),
|
||||
habit.get_priority(),
|
||||
habit.get_name());
|
||||
}
|
||||
}
|
||||
|
20
src/main.rs
20
src/main.rs
@ -49,9 +49,11 @@ enum Command
|
||||
days:String,
|
||||
#[structopt(long, help = "Assign habit as a bad habit (negative points)")]
|
||||
bad:bool,
|
||||
#[structopt(short, long, help = "Weight/priority of the new habit",
|
||||
default_value = "5")]
|
||||
weight:u8,
|
||||
#[structopt(short,
|
||||
long,
|
||||
help = "Priority of the new habit (L, M, or H)",
|
||||
default_value = "M")]
|
||||
priority:char,
|
||||
},
|
||||
Commit { },
|
||||
#[structopt(alias = "del")]
|
||||
@ -76,8 +78,8 @@ enum Command
|
||||
id:usize,
|
||||
#[structopt(short, long, help = "New name for the habit")]
|
||||
name:Option<String>,
|
||||
#[structopt(short, long, help = "New weight of the habit")]
|
||||
weight:Option<u8>,
|
||||
#[structopt(short, long, help = "New priority for the habit (L, M, or H)")]
|
||||
priority:Option<char>,
|
||||
#[structopt(long, short, help = "New days the habit is active")]
|
||||
days:Option<String>,
|
||||
#[structopt(long, help = "Toggle the 'bad' value of the habit")]
|
||||
@ -116,16 +118,16 @@ fn main()
|
||||
Some(c) =>
|
||||
match c
|
||||
{
|
||||
Command::Add { name, days, bad, weight } =>
|
||||
hmgr.add(name, bad, weight, days),
|
||||
Command::Add { name, days, bad, priority } =>
|
||||
hmgr.add(name, bad, priority, days),
|
||||
Command::Delete { id } =>
|
||||
hmgr.delete(id),
|
||||
Command::Info { id } =>
|
||||
hmgr.habit_info(id),
|
||||
Command::List { all } =>
|
||||
hmgr.list(all),
|
||||
Command::Modify { id, name, weight, days, toggle_bad } =>
|
||||
hmgr.modify(id, name, toggle_bad, weight, days),
|
||||
Command::Modify { id, name, priority, days, toggle_bad } =>
|
||||
hmgr.modify(id, name, toggle_bad, priority, days),
|
||||
_ => todo!(),
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user