1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2026-08-06 04:24:04 +00:00
This commit is contained in:
Zykino 2026-07-30 00:25:52 +02:00 committed by GitHub
commit dc074f3cac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 720 additions and 499 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "todos" name = "todos"
version = "0.1.1" version = "0.1.1"
edition = "2021" edition = "2024"
authors = ["Samuel Štancl <samuel@archte.ch>"] authors = ["Samuel Štancl <samuel@archte.ch>"]
description = "An intuitive system for organizing TODOs in code" description = "An intuitive system for organizing TODOs in code"

View file

@ -1,14 +1,14 @@
use std::fs::canonicalize; use std::fs::canonicalize;
use std::path::PathBuf; use std::path::PathBuf;
use clap::{Parser, ArgAction};
use crate::entries::Entry; use crate::entries::Entry;
use crate::render::render_entries; use crate::render::render_entries;
use crate::scan::{Stats, scan_dir, scan_todo_file, scan_readme_file, Exclude}; use crate::scan::{Exclude, Stats, scan_dir, scan_readme_file, scan_todo_file};
use clap::{ArgAction, Parser};
pub mod scan;
pub mod render;
pub mod entries; pub mod entries;
pub mod render;
pub mod scan;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -66,12 +66,12 @@ fn main() {
let mut path = root_dir.clone(); let mut path = root_dir.clone();
path.push(exclude); path.push(exclude);
if path.exists() { if path.exists()
if let Ok(realpath) = canonicalize(path) { && let Ok(realpath) = canonicalize(path)
{
excludes.push(Exclude::Path(realpath)); excludes.push(Exclude::Path(realpath));
} }
} }
}
let mut todos_path = root_dir.clone(); let mut todos_path = root_dir.clone();
todos_path.push(&args.todos); todos_path.push(&args.todos);
@ -100,9 +100,9 @@ fn main() {
if args.verbose > 0 { if args.verbose > 0 {
eprint!("\n\n"); eprint!("\n\n");
stats.print(); stats.print();
eprintln!("Paths ({}): {:?}", &paths.len(), &paths); eprintln!("Paths ({}): {:?}", paths.len(), paths);
eprintln!("Excludes ({}): {:?}", &excludes.len(), &excludes); eprintln!("Excludes ({}): {:?}", excludes.len(), excludes);
eprintln!("todo.md: {:?}", &todos_path); eprintln!("todo.md: {:?}", todos_path);
eprintln!("readme.md: {:?}", &readme_path); eprintln!("readme.md: {:?}", readme_path);
} }
} }

View file

@ -1,7 +1,7 @@
use std::io::Write; use std::cmp::Ordering::{Equal, Greater, Less};
use std::collections::HashMap; use std::collections::HashMap;
use std::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use std::cmp::Ordering::{Less, Equal, Greater};
use crate::entries::{Entry, EntryData}; use crate::entries::{Entry, EntryData};
@ -10,11 +10,20 @@ impl Entry {
let mut stdout = StandardStream::stdout(ColorChoice::Auto); let mut stdout = StandardStream::stdout(ColorChoice::Auto);
write_ansi(&mut stdout, Color::Ansi256(243), "- [ ] ", false); write_ansi(&mut stdout, Color::Ansi256(243), "- [ ] ", false);
let location = format!("{}:{}", self.location.file.to_string_lossy(), self.location.line); let location = format!(
"{}:{}",
self.location.file.to_string_lossy(),
self.location.line
);
if !self.text.is_empty() { if !self.text.is_empty() {
write_ansi(&mut stdout, Color::Blue, self.text.as_str(), true); write_ansi(&mut stdout, Color::Blue, self.text.as_str(), true);
write_ansi(&mut stdout, Color::Ansi256(243), format!(" ({})", location).as_str(), false); write_ansi(
&mut stdout,
Color::Ansi256(243),
format!(" ({})", location).as_str(),
false,
);
} else { } else {
write_ansi(&mut stdout, Color::Cyan, location.as_str(), true); write_ansi(&mut stdout, Color::Cyan, location.as_str(), true);
} }
@ -23,13 +32,10 @@ impl Entry {
} }
} }
pub fn write_ansi(stdout: &mut StandardStream, color: Color, text: &str, bold: bool) { pub fn write_ansi(stdout: &mut StandardStream, color: Color, text: &str, bold: bool) {
stdout.set_color( stdout
ColorSpec::new() .set_color(ColorSpec::new().set_fg(Some(color)).set_bold(bold))
.set_fg(Some(color)) .unwrap();
.set_bold(bold)
).unwrap();
write!(stdout, "{text}").unwrap(); write!(stdout, "{text}").unwrap();
@ -46,13 +52,11 @@ pub fn render_entries(entries: Vec<Entry>) {
for entry in entries { for entry in entries {
match entry.data { match entry.data {
EntryData::Priority(priority) => { EntryData::Priority(priority) => {
if ! priority_entries.contains_key(&priority) { priority_entries.entry(priority).or_default();
priority_entries.insert(priority, vec![]);
}
let vec = priority_entries.get_mut(&priority).unwrap(); let vec = priority_entries.get_mut(&priority).unwrap();
vec.push(entry); vec.push(entry);
}, }
EntryData::Category(ref category) => { EntryData::Category(ref category) => {
if !category_entries.contains_key(category) { if !category_entries.contains_key(category) {
category_entries.insert(category.clone(), vec![]); category_entries.insert(category.clone(), vec![]);
@ -60,7 +64,7 @@ pub fn render_entries(entries: Vec<Entry>) {
let vec = category_entries.get_mut(category).unwrap(); let vec = category_entries.get_mut(category).unwrap();
vec.push(entry); vec.push(entry);
}, }
EntryData::Generic => { EntryData::Generic => {
generic_entries.push(entry); generic_entries.push(entry);
} }
@ -81,15 +85,24 @@ pub fn render_entries(entries: Vec<Entry>) {
// todo0 -> 0 // todo0 -> 0
// todo00 -> -1 // todo00 -> -1
// Therefore: 'todo0' + priority.abs() * '0' // Therefore: 'todo0' + priority.abs() * '0'
str.push_str(String::from_utf8(vec![b'0'; priority.unsigned_abs()]).unwrap().as_str()); str.push_str(
String::from_utf8(vec![b'0'; priority.unsigned_abs()])
.unwrap()
.as_str(),
);
str str
}, }
Equal => "todo0".to_string(), Equal => "todo0".to_string(),
Greater => format!("todo{}", priority), Greater => format!("todo{}", priority),
}; };
write_ansi(&mut stdout, Color::Red, format!("## {}", &priority_notation).as_str(), true); write_ansi(
&mut stdout,
Color::Red,
format!("## {}", priority_notation).as_str(),
true,
);
writeln!(stdout).unwrap(); writeln!(stdout).unwrap();
for item in priority_entries.get(priority).unwrap() { for item in priority_entries.get(priority).unwrap() {
@ -103,7 +116,12 @@ pub fn render_entries(entries: Vec<Entry>) {
category_keys.sort_by(|a, b| a.partial_cmp(b).unwrap()); category_keys.sort_by(|a, b| a.partial_cmp(b).unwrap());
for category in category_keys { for category in category_keys {
write_ansi(&mut stdout, Color::Green, format!("## {}", &category).as_str(), true); write_ansi(
&mut stdout,
Color::Green,
format!("## {}", category).as_str(),
true,
);
writeln!(stdout).unwrap(); writeln!(stdout).unwrap();
for item in category_entries.get(category).unwrap() { for item in category_entries.get(category).unwrap() {
@ -113,7 +131,7 @@ pub fn render_entries(entries: Vec<Entry>) {
println!(); println!();
} }
if generic_entries.len() > 0 { if !generic_entries.is_empty() {
write_ansi(&mut stdout, Color::White, "## Other", true); write_ansi(&mut stdout, Color::White, "## Other", true);
writeln!(stdout).unwrap(); writeln!(stdout).unwrap();

File diff suppressed because it is too large Load diff