Skip to content

Commit

Permalink
correct text sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Aug 22, 2023
1 parent cd0bafa commit 5648620
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 144 deletions.
19 changes: 9 additions & 10 deletions tuffous-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use std::{
io::{Read, Write},
};
use tuffous_core::{
get_version,
util::{parse_date, parse_date_and_time},
Todo, TodoInstance,
version, Todo, TodoInstance,
};

pub fn main() {
Expand Down Expand Up @@ -108,7 +107,7 @@ fn cli() -> Command {
Command::new("tuffous")
.about(format!(
"A powerful to-do manager in CLI. version {}",
get_version()
version()
))
.subcommand_required(false)
.arg_required_else_help(true)
Expand Down Expand Up @@ -255,18 +254,18 @@ impl TodoScanner {

pub fn apply_filters(&mut self, matches: &ArgMatches) {
self.cache.clear();
for todo_id in self.instance.get_todos() {
for todo_id in self.instance.todos() {
if !self.cache.contains(&todo_id)
&& Self::match_filters(matches, self.instance.get(todo_id).unwrap(), true)
{
self.cache.push(todo_id);
for father_todo_id in self.instance.get_all_deps(todo_id) {
for father_todo_id in self.instance.all_deps(todo_id) {
if !self.cache.contains(&father_todo_id) {
self.cache.push(father_todo_id);
}
}

for child_todo_id in self.instance.get_children(todo_id) {
for child_todo_id in self.instance.children(todo_id) {
if !self.cache.contains(&child_todo_id)
&& Self::match_filters(matches, self.instance.get(todo_id).unwrap(), false)
{
Expand Down Expand Up @@ -478,18 +477,18 @@ impl TodoScanner {
format!(
"{}{}",
format_todo(todo),
if self.instance.get_children_once(id).is_empty() {
if self.instance.children_once(id).is_empty() {
String::new()
} else {
format!(
" ({}/{})",
self.instance.get_weight(id, true),
self.instance.get_weight(id, false)
self.instance.weight(id, true),
self.instance.weight(id, false)
)
}
),
));
for child in self.instance.get_children_once(id) {
for child in self.instance.children_once(id) {
if range.contains(&child) {
for mut i in self.as_tree(child, range) {
i.string = format!(" {}", i.string);
Expand Down
58 changes: 28 additions & 30 deletions tuffous-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

pub mod util;

pub fn get_version() -> String {
pub fn version() -> String {
String::from("0.1")
}

Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct TodoMetaData {
}

impl Todo {
pub fn get_id(&self) -> u64 {
pub fn id(&self) -> u64 {
self.id
}

Expand All @@ -74,18 +74,17 @@ impl Todo {
}
}

pub fn get_creation_date(&self) -> &NaiveDateTime {
pub fn creation_date(&self) -> &NaiveDateTime {
&self.creation_date
}

pub fn write_to_file(&self, path: &str) {
let p = format!("{path}/.tuffous/todos/{}.json", self.get_id());
let p = format!("{path}/.tuffous/todos/{}.json", self.id());

let Ok(mut file) = File::create(p) else { return };
crate::util::destroy(
file.write(serde_json::to_string(self).unwrap().as_bytes())
.unwrap(),
);
let _ = file
.write(serde_json::to_string(self).unwrap().as_bytes())
.unwrap();
}

pub fn read_from_file<P: AsRef<Path>>(path: P) -> Option<Self> {
Expand Down Expand Up @@ -180,46 +179,46 @@ impl TodoInstance {
}

pub fn get(&self, id: u64) -> Option<&Todo> {
self.todos.iter().find(|&todo| todo.get_id() == id)
self.todos.iter().find(|&todo| todo.id() == id)
}

pub fn get_mut(&mut self, id: u64) -> Option<&mut Todo> {
self.todos.iter_mut().find(|todo| todo.get_id() == id)
self.todos.iter_mut().find(|todo| todo.id() == id)
}

pub fn get_todos(&self) -> Vec<u64> {
pub fn todos(&self) -> Vec<u64> {
let mut vec = Vec::new();
for todo in &self.todos {
vec.push(todo.get_id());
vec.push(todo.id());
}
vec
}

pub fn get_children(&self, id: u64) -> Vec<u64> {
pub fn children(&self, id: u64) -> Vec<u64> {
let mut vec = Vec::new();
for todo in &self.todos {
if self.get_all_deps(todo.id).contains(&id) {
vec.push(todo.get_id());
if self.all_deps(todo.id).contains(&id) {
vec.push(todo.id());
}
}
vec
}

pub fn get_children_once(&self, id: u64) -> Vec<u64> {
pub fn children_once(&self, id: u64) -> Vec<u64> {
let mut vec = Vec::new();
for todo in &self.todos {
if todo.dependents.contains(&id) {
vec.push(todo.get_id());
vec.push(todo.id());
}
}
vec
}

pub fn child_able(&self, father: u64, child: u64) -> bool {
pub fn is_child_able(&self, father: u64, child: u64) -> bool {
if father == child {
return false;
}
!(self.get_all_deps(father).contains(&child) || self.get_children(father).contains(&child))
!(self.all_deps(father).contains(&child) || self.children(father).contains(&child))
}

pub fn replace(&mut self, replacement: Todo) -> bool {
Expand All @@ -237,7 +236,7 @@ impl TodoInstance {
}

pub fn child(&mut self, father: u64, child: u64) {
if !self.child_able(father, child) {
if !self.is_child_able(father, child) {
panic!("Can't child the target child")
}

Expand All @@ -247,13 +246,13 @@ impl TodoInstance {
}
}

pub fn get_all_deps(&self, id: u64) -> Vec<u64> {
pub fn all_deps(&self, id: u64) -> Vec<u64> {
let mut vec = Vec::new();
if let Some(target) = self.get(id) {
for dep in &target.dependents {
if let Some(todo) = self.get(*dep) {
vec.push(todo.get_id());
for t in self.get_all_deps(*dep) {
vec.push(todo.id());
for t in self.all_deps(*dep) {
vec.push(t);
}
}
Expand All @@ -265,7 +264,7 @@ impl TodoInstance {
}

pub fn refresh(&mut self) {
let todos = self.get_todos();
let todos = self.todos();
for todo_id in &todos {
if let Some(todo) = self.get_mut(*todo_id) {
// Remove broken deps
Expand Down Expand Up @@ -304,7 +303,7 @@ impl TodoInstance {
let mut remove = false;

for todo in self.todos.iter().enumerate() {
if todo.1.get_id() == id {
if todo.1.id() == id {
rm = todo.0;
remove = true;
}
Expand All @@ -316,16 +315,15 @@ impl TodoInstance {
fs::remove_file(format!("{}/.tuffous/todos/{}.json", self.path, id)).unwrap();
}

pub fn get_weight(&self, id: u64, completed: bool) -> u32 {
pub fn weight(&self, id: u64, completed: bool) -> u32 {
let mut base = 0;
if self.get_children_once(id).is_empty() && (self.get(id).unwrap().completed || !completed)
{
if self.children_once(id).is_empty() && (self.get(id).unwrap().completed || !completed) {
base += self.get(id).unwrap().weight
}

for child in self.get_children_once(id) {
for child in self.children_once(id) {
if self.get(child).unwrap().completed || !completed {
base += self.get_weight(child, completed);
base += self.weight(child, completed);
}
}

Expand Down
6 changes: 2 additions & 4 deletions tuffous-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn vec_none_match<T>(vec: &Vec<T>, predicate: &dyn Fn(&T) -> bool) -> bool {
true
}

pub fn get_month_str(month: u32) -> String {
pub fn month_str(month: u32) -> String {
match month {
1 => String::from("Jan"),
2 => String::from("Feb"),
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn join_str_with(vec: Vec<&str>, with: &str) -> String {
string
}

pub fn get_progression_char(percent: u32) -> char {
pub fn progression_char(percent: u32) -> char {
if percent == 0 {
'󰝦'
} else if percent > 0 && percent <= 13 {
Expand All @@ -127,5 +127,3 @@ pub fn get_progression_char(percent: u32) -> char {
unreachable!()
}
}

pub fn destroy<T>(_obj: T) {}
2 changes: 1 addition & 1 deletion tuffous-gui/src/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn icon(unicode: char) -> Text<'static> {
.font(ICONS)
.width(20)
.horizontal_alignment(alignment::Horizontal::Center)
.size(20)
.size(18)
}

pub struct TagStyle;
Expand Down
9 changes: 3 additions & 6 deletions tuffous-gui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ConfigInstance {

impl ConfigInstance {
pub fn get() -> Self {
if let Some(c) = Self::read_from_file(Self::get_path()) {
if let Some(c) = Self::read_from_file(Self::path()) {
c
} else {
Self::default()
Expand All @@ -26,13 +26,10 @@ impl ConfigInstance {
}

pub fn write(&self) {
tuffous_core::util::destroy(fs::write(
Self::get_path(),
serde_json::to_string(&self).unwrap(),
));
let _ = fs::write(Self::path(), serde_json::to_string(&self).unwrap());
}

fn get_path() -> String {
fn path() -> String {
String::from("./.tuffous/config_gui.json")
}
}
Expand Down
Loading

0 comments on commit 5648620

Please sign in to comment.