1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2025-12-12 09:04:03 +00:00
This commit is contained in:
Samuel Štancl 2024-03-12 18:45:53 +01:00
parent b4a74cb633
commit 9fe36adf20
2 changed files with 20 additions and 25 deletions

View file

@ -12,14 +12,14 @@ impl Entry {
let location = format!("{}:{}", self.location.file.to_string_lossy(), self.location.line);
if self.text.len() > 0 {
if ! self.text.is_empty() {
write_ansi(&mut stdout, Color::Blue, self.text.as_str(), true);
write_ansi(&mut stdout, Color::Ansi256(243), format!(" ({})", location).as_str(), false);
} else {
write_ansi(&mut stdout, Color::Cyan, &location.as_str(), true);
write_ansi(&mut stdout, Color::Cyan, location.as_str(), true);
}
write!(&mut stdout, "\n").unwrap();
writeln!(&mut stdout).unwrap();
}
}
@ -81,7 +81,7 @@ pub fn render_entries(entries: Vec<Entry>) {
// todo0 -> 0
// todo00 -> -1
// Therefore: 'todo0' + priority.abs() * '0'
str.push_str(String::from_utf8(vec![b'0'; priority.abs() as usize]).unwrap().as_str());
str.push_str(String::from_utf8(vec![b'0'; priority.unsigned_abs()]).unwrap().as_str());
str
},
@ -90,13 +90,13 @@ pub fn render_entries(entries: Vec<Entry>) {
};
write_ansi(&mut stdout, Color::Red, format!("## {}", &priority_notation).as_str(), true);
write!(stdout, "\n").unwrap();
writeln!(stdout).unwrap();
for item in priority_entries.get(priority).unwrap() {
item.render();
}
println!("");
println!();
}
let mut category_keys = category_entries.keys().collect::<Vec<&String>>();
@ -104,17 +104,17 @@ pub fn render_entries(entries: Vec<Entry>) {
for category in category_keys {
write_ansi(&mut stdout, Color::Green, format!("## {}", &category).as_str(), true);
write!(stdout, "\n").unwrap();
writeln!(stdout).unwrap();
for item in category_entries.get(category).unwrap() {
item.render();
}
println!("");
println!();
}
write_ansi(&mut stdout, Color::White, "## Other", true);
write!(stdout, "\n").unwrap();
writeln!(stdout).unwrap();
generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap());

View file

@ -79,25 +79,25 @@ fn parse_priority(word: &str) -> Option<isize> {
let priority_substr = lowercase_word.split("todo").nth(1).unwrap();
if priority_substr.len() == 1 {
return Some(priority_substr.to_string().parse::<isize>().unwrap());
Some(priority_substr.to_string().parse::<isize>().unwrap())
} else if priority_substr.chars().all(|ch| ch == '0') {
// todo0: 1 - 1 = 0
// todo00: 1 - 2 = -1
return Some(1 - priority_substr.len() as isize);
Some(1 - priority_substr.len() as isize)
} else {
return None; // invalid syntax like todo11
None // invalid syntax like todo11
}
}
/// Remove closing tags, comments, and whitespace
fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str {
return line.split_once(delimiter_word).unwrap().1
line.split_once(delimiter_word).unwrap().1
.trim()
.trim_end_matches("*/")
.trim_end_matches("-->")
.trim_end_matches("--}}")
.trim_end_matches("/>")
.trim();
.trim()
}
pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec<PathBuf>) {
@ -114,7 +114,7 @@ pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec<PathBu
}
if line.trim() == "*" {
if let Ok(realpath) = canonicalize(&base_dir) {
if let Ok(realpath) = canonicalize(base_dir) {
excludes.push(realpath);
}
@ -217,10 +217,9 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
}
pub fn scan_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
match std::fs::read_to_string(path) {
Ok(str) => scan_string(str, path.to_path_buf(), entries),
Err(_) => (),
};
if let Ok(str) = std::fs::read_to_string(path) {
scan_string(str, path.to_path_buf(), entries);
}
Ok(())
}
@ -237,7 +236,7 @@ pub fn scan_dir(dir: &Path, entries: &mut Vec<Entry>, excludes: &mut Vec<PathBuf
// so the exclude would not affect anything inside the for loop. For that reason, we re-check if
// `dir` hasn't become excluded after running `add_excludes_from_gitignore`.
for exclude in &*excludes {
if canonicalize(dir.to_path_buf()).unwrap() == *exclude {
if canonicalize(dir).unwrap() == *exclude {
return Ok(());
}
}
@ -347,11 +346,7 @@ pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()>
let section = line.split_once("# ").unwrap().1;
let cleaned_section = section.to_lowercase().trim_end_matches(':').trim().to_string();
if cleaned_section == "todo" || cleaned_section == "todos" {
in_todo_section = true;
} else {
in_todo_section = false;
}
in_todo_section = cleaned_section == "todo" || cleaned_section == "todos";
continue;
}