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 2023-11-22 15:44:25 +01:00
parent 574cee8895
commit 5cda67a4cd
5 changed files with 98 additions and 14 deletions

43
Cargo.lock generated
View file

@ -138,10 +138,20 @@ dependencies = [
] ]
[[package]] [[package]]
name = "todo-system" name = "termcolor"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
dependencies = [
"winapi-util",
]
[[package]]
name = "todos"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"termcolor",
] ]
[[package]] [[package]]
@ -156,6 +166,37 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"

View file

@ -1,5 +1,5 @@
[package] [package]
name = "todo-system" name = "todos"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
authors = ["Samuel Štancl <samuel@archte.ch>"] authors = ["Samuel Štancl <samuel@archte.ch>"]
@ -9,3 +9,4 @@ description = "An intuitive system for organizing TODOs in code"
[dependencies] [dependencies]
clap = { version = "4.4.8", features = ["derive"] } clap = { version = "4.4.8", features = ["derive"] }
termcolor = "1.4.0"

View file

@ -136,3 +136,16 @@ Notes:
- `node_modules/` (for npm) and `vendor/` (for composer) are ignored by default - `node_modules/` (for npm) and `vendor/` (for composer) are ignored by default
- paths starting with `.` are **always** ignored - paths starting with `.` are **always** ignored
- `--exclude`s are relative to the current working directory, not passed paths (including default excludes mentioned above). If you're running the script for another folder and want to exclude folders there, type out the path in `--exclude` - `--exclude`s are relative to the current working directory, not passed paths (including default excludes mentioned above). If you're running the script for another folder and want to exclude folders there, type out the path in `--exclude`
To omit ANSI formatting and get raw markdown output, set `NO_COLOR=1` or `TERM=dumb`.
### Installation
There are no downloadable builds at the moment. To compile the tool manually:
1. Set up Rust locally https://www.rust-lang.org/tools/install
2. Clone the repo
3. `cargo build --release`
4. The binary (`todos`) will appear will `target/release`. Add it to your PATH or create a bash alias:
```sh
alias todos="/path/to/todos"
```

View file

@ -1,7 +1,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::{io, fs}; use std::io::{self, Write};
use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use clap::Parser; use clap::Parser;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use std::cmp::Ordering::{Less, Equal, Greater};
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
struct Location { struct Location {
@ -25,14 +28,36 @@ enum EntryData {
impl Entry { impl Entry {
fn render(&self) { fn render(&self) {
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);
if self.text.len() > 0 { if self.text.len() > 0 {
println!("- [ ] {} ({}:{})", self.text, self.location.file.to_string_lossy(), self.location.line); write_ansi(&mut stdout, Color::Blue, self.text.as_str(), true);
write_ansi(&mut stdout, Color::Ansi256(243), format!(" ({})", location).as_str(), false);
} else { } else {
println!("- [ ] {}:{}", self.location.file.to_string_lossy(), self.location.line); write_ansi(&mut stdout, Color::Cyan, &location.as_str(), true);
} }
write!(&mut stdout, "\n").unwrap();
} }
} }
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();
write!(stdout, "{text}").unwrap();
stdout.reset().unwrap();
}
struct Stats { struct Stats {
visited_folders: usize, visited_folders: usize,
visited_files: usize, visited_files: usize,
@ -175,6 +200,8 @@ fn render(entries: Vec<Entry>) {
let mut category_entries: HashMap<String, Vec<Entry>> = HashMap::new(); let mut category_entries: HashMap<String, Vec<Entry>> = HashMap::new();
let mut generic_entries: Vec<Entry> = Vec::new(); let mut generic_entries: Vec<Entry> = Vec::new();
let mut stdout = StandardStream::stdout(ColorChoice::Auto);
for entry in entries { for entry in entries {
match entry.data { match entry.data {
EntryData::Priority(priority) => { EntryData::Priority(priority) => {
@ -199,14 +226,15 @@ fn render(entries: Vec<Entry>) {
} }
} }
print!("# TODOs\n\n"); write_ansi(&mut stdout, Color::Yellow, "# TODOs", true);
write!(stdout, "\n\n").unwrap();
let mut priority_keys = priority_entries.keys().collect::<Vec<&isize>>(); let mut priority_keys = priority_entries.keys().collect::<Vec<&isize>>();
priority_keys.sort_by(|a, b| a.partial_cmp(b).unwrap()); priority_keys.sort_by(|a, b| a.partial_cmp(b).unwrap());
for priority in priority_keys { for priority in priority_keys {
let priority_notation = match priority.cmp(&0) { let priority_notation = match priority.cmp(&0) {
std::cmp::Ordering::Less => { Less => {
let mut str = "todo0".to_string(); let mut str = "todo0".to_string();
// todo0 -> 0 // todo0 -> 0
@ -216,11 +244,12 @@ fn render(entries: Vec<Entry>) {
str str
}, },
std::cmp::Ordering::Equal => "todo0".to_string(), Equal => "todo0".to_string(),
std::cmp::Ordering::Greater => format!("todo{}", priority), Greater => format!("todo{}", priority),
}; };
println!("## {}", priority_notation); write_ansi(&mut stdout, Color::Red, format!("## {}", &priority_notation).as_str(), true);
write!(stdout, "\n").unwrap();
for item in priority_entries.get(priority).unwrap() { for item in priority_entries.get(priority).unwrap() {
item.render(); item.render();
@ -233,7 +262,8 @@ fn render(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 {
println!("## {}", category); write_ansi(&mut stdout, Color::Green, format!("## {}", &category).as_str(), true);
write!(stdout, "\n").unwrap();
for item in category_entries.get(category).unwrap() { for item in category_entries.get(category).unwrap() {
item.render(); item.render();
@ -242,7 +272,8 @@ fn render(entries: Vec<Entry>) {
println!(""); println!("");
} }
println!("## Other"); write_ansi(&mut stdout, Color::White, "## Other", true);
write!(stdout, "\n").unwrap();
generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap()); generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap());

View file

@ -2,5 +2,3 @@
- README.md - README.md
- todo.md - todo.md
- Output format?
- termcolor + --no-ansi