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

View file

@ -1,14 +1,14 @@
use std::fs::canonicalize;
use std::path::PathBuf;
use clap::{Parser, ArgAction};
use crate::entries::Entry;
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 render;
pub mod scan;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
@ -66,10 +66,10 @@ fn main() {
let mut path = root_dir.clone();
path.push(exclude);
if path.exists() {
if let Ok(realpath) = canonicalize(path) {
excludes.push(Exclude::Path(realpath));
}
if path.exists()
&& let Ok(realpath) = canonicalize(path)
{
excludes.push(Exclude::Path(realpath));
}
}
@ -100,9 +100,9 @@ fn main() {
if args.verbose > 0 {
eprint!("\n\n");
stats.print();
eprintln!("Paths ({}): {:?}", &paths.len(), &paths);
eprintln!("Excludes ({}): {:?}", &excludes.len(), &excludes);
eprintln!("todo.md: {:?}", &todos_path);
eprintln!("readme.md: {:?}", &readme_path);
eprintln!("Paths ({}): {:?}", paths.len(), paths);
eprintln!("Excludes ({}): {:?}", excludes.len(), excludes);
eprintln!("todo.md: {:?}", todos_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::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use std::cmp::Ordering::{Less, Equal, Greater};
use crate::entries::{Entry, EntryData};
@ -10,11 +10,20 @@ impl Entry {
let mut stdout = StandardStream::stdout(ColorChoice::Auto);
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::Ansi256(243), format!(" ({})", location).as_str(), false);
write_ansi(
&mut stdout,
Color::Ansi256(243),
format!(" ({})", location).as_str(),
false,
);
} else {
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) {
stdout.set_color(
ColorSpec::new()
.set_fg(Some(color))
.set_bold(bold)
).unwrap();
stdout
.set_color(ColorSpec::new().set_fg(Some(color)).set_bold(bold))
.unwrap();
write!(stdout, "{text}").unwrap();
@ -46,21 +52,19 @@ pub fn render_entries(entries: Vec<Entry>) {
for entry in entries {
match entry.data {
EntryData::Priority(priority) => {
if ! priority_entries.contains_key(&priority) {
priority_entries.insert(priority, vec![]);
}
priority_entries.entry(priority).or_default();
let vec = priority_entries.get_mut(&priority).unwrap();
vec.push(entry);
},
}
EntryData::Category(ref category) => {
if ! category_entries.contains_key(category) {
if !category_entries.contains_key(category) {
category_entries.insert(category.clone(), vec![]);
}
let vec = category_entries.get_mut(category).unwrap();
vec.push(entry);
},
}
EntryData::Generic => {
generic_entries.push(entry);
}
@ -81,15 +85,24 @@ 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.unsigned_abs()]).unwrap().as_str());
str.push_str(
String::from_utf8(vec![b'0'; priority.unsigned_abs()])
.unwrap()
.as_str(),
);
str
},
}
Equal => "todo0".to_string(),
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();
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());
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();
for item in category_entries.get(category).unwrap() {
@ -113,7 +131,7 @@ pub fn render_entries(entries: Vec<Entry>) {
println!();
}
if generic_entries.len() > 0 {
if !generic_entries.is_empty() {
write_ansi(&mut stdout, Color::White, "## Other", true);
writeln!(stdout).unwrap();

File diff suppressed because it is too large Load diff