Skip to content

Commit

Permalink
feat: Fix bug with undo command
Browse files Browse the repository at this point in the history
  • Loading branch information
fromtheeast710 committed Nov 26, 2024
1 parent 4b1a1fd commit ad67077
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 51 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/lstodo.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ From there you can either use:
## Help

```
LsTodo v0.1.0
LsTodo v0.1.2
Usage: lstodo [COMMAND] [ARGUMENTS]
Commands:
[h]elp show this help message
[l]ist list all tasks
[a]dd [TASK] add new task(s)
[d]one [INDEX] mark task(s) as done
[u]ndo [INDEX] mark task(s) as undone
[r]emove [INDEX] remove task(s)
[s]ort sort completed and uncompleted tasks
[n]ote [d/i/e/u/h] [INDEX] highlight important task
[c]hange [INDEX] [TASK] change the content of a task
[m]ove [INDEX] [INDEX] switch the position of two tasks
reset remove all tasks";
reset remove all tasks
```
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ e:

# cargo build release binary
cb:
cargo build --frozen --release --all-features
cargo clean && cargo build --frozen --release --all-features

# remove the target dir
cc:
Expand Down
12 changes: 12 additions & 0 deletions lstodo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[ ] Develop WatcherRS
[ ] Basic car movement in ROS
[ ] Apply Pytorch and OpenCV for car
[ ] Finish CS242 to create koi lang
[ ] Finish Turing Complete tutorial
[ ] Finish HackerRank 1 week kit
[ ] Get started with KR260 and Verilog
[ ] Take notes for Category Theory
[ ] RC Car + Pi4 + NATS.rs + Grafana setup
[d] Setup homeserver with NixOS
[d] Finish Rustlings tutorial
[d] Polish portfolio site
98 changes: 50 additions & 48 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,20 @@ impl LsTodo {
let mut buffer = BufWriter::new(file);

for (p, l) in self.lstodo.iter().enumerate() {
if l.len() > 5 {
if args.contains(&(p + 1).to_string()) {
if &l[..4] == "[d] " {
let l = format!("[ ] {}\n", &l[4..]);

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
} else {
let l = format!("[d] {}\n", &l[4..]);
if args.contains(&(p + 1).to_string()) {
if &l[..4] == "[d] " {
let l = format!("[ ] {}\n", &l[4..]);

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
} else if &l[..4] == "[ ] " || &l[..4] == "[d] " {
let l = format!("{l}\n");
buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
} else {
let l = format!("[d] {}\n", &l[4..]);

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
} else if &l[..4] == "[ ] " || &l[..4] == "[d] " {
let l = format!("{l}\n");

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
}
}
Expand All @@ -191,18 +189,26 @@ impl LsTodo {
process::exit(1)
}

let file = OpenOptions::new().write(true).open(&self.lstodo_path).expect(&OPEN_ERR);
let file = OpenOptions::new()
.write(true)
.truncate(true)
.open(&self.lstodo_path)
.expect(&OPEN_ERR);

let mut buffer = BufWriter::new(file);

for (p, l) in self.lstodo.iter().enumerate() {
if args.contains(&(p + 1).to_string()) {
continue;
}
if &l[..4] != "[ ] " {
let l = format!("[ ] {}\n", &l[4..]);

let l = format!("{l}\n");
buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
} else {
let l = format!("{l}\n");

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
}
}

Expand All @@ -215,24 +221,22 @@ impl LsTodo {
let mut emer = String::new();

for l in self.lstodo.iter() {
if l.len() > 5 {
if &l[..4] == "[ ] " {
let l = format!("{l}\n");
if &l[..4] == "[ ] " {
let l = format!("{l}\n");

todo.push_str(&l)
} else if &l[..4] == "[d] " {
let l = format!("{l}\n");
todo.push_str(&l)
} else if &l[..4] == "[d] " {
let l = format!("{l}\n");

done.push_str(&l)
} else if &l[..4] == "[i] " {
let l = format!("{l}\n");
done.push_str(&l)
} else if &l[..4] == "[i] " {
let l = format!("{l}\n");

impo.push_str(&l)
} else if &l[..4] == "[e] " {
let l = format!("{l}\n");
impo.push_str(&l)
} else if &l[..4] == "[e] " {
let l = format!("{l}\n");

emer.push_str(&l)
}
emer.push_str(&l)
}
}

Expand Down Expand Up @@ -262,25 +266,23 @@ impl LsTodo {
let mut buffer = BufWriter::new(file);

for (p, l) in self.lstodo.iter().enumerate() {
if l.len() > 5 {
if args.contains(&(p + 1).to_string()) {
let l = match args[0].as_str() {
"d" => format!("[d] {}\n", &l[4..]),
"i" => format!("[i] {}\n", &l[4..]),
"e" => format!("[e] {}\n", &l[4..]),
"u" => format!("[ ] {}\n", &l[4..]),
_ => {
eprintln!("Invalid note! Use h to see help!");
process::exit(1)
}
};
if args.contains(&(p + 1).to_string()) {
let l = match args[0].as_str() {
"d" => format!("[d] {}\n", &l[4..]),
"i" => format!("[i] {}\n", &l[4..]),
"e" => format!("[e] {}\n", &l[4..]),
"u" => format!("[ ] {}\n", &l[4..]),
_ => {
eprintln!("Invalid note! Use h to see help!");
process::exit(1)
}
};

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
} else {
let l = format!("{l}\n");
buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
} else {
let l = format!("{l}\n");

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
buffer.write_all(l.as_bytes()).expect(&WRITE_ERR)
}
}
}
Expand Down

0 comments on commit ad67077

Please sign in to comment.