Skip to content

Commit

Permalink
Fixed index bug
Browse files Browse the repository at this point in the history
Updated readme.md
  • Loading branch information
nimaaskarian committed Jan 23, 2024
1 parent 63e23d6 commit 93ad5cc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ A crossplatform to-do list app that uses and extends [calcurse](https://www.calc

[Getting started](#getting-started)
[Installation](#installation)
[Configuration](#configuration)
[Integrations](#third-party-integrations)
[Usage](#configuration)
</div>


Expand All @@ -22,9 +21,50 @@ cd c3
cargo build --release
```

If you use arch linux, You can install c3 from AUR. Commands using yay would be
```
If you use **Arch linux**, You can install c3 from AUR. Commands using yay would be
```bash
yay -S c3
```
### Using a pre-built release
You can check out [releases](https://github.com/nimaaskarian/c3/releases)
You can check out [releases](https://github.com/nimaaskarian/c3/releases).

## Usage
### Interactive mode
The default mode of the app is TUI mode. Keybinds are vim-like. Here they are:

| key | action |
|---|---|
| a | add todo to bottom|
| A | add todo to top|
| e | edit todo |
| E | edit todo (move cursor to start) |
| ! | toggle show done |
| 0-9 | set todo priority |
| j | go down in todo list |
| k | go up in todo list |
| g | go top of todo list |
| G | go bottom of todo list |
| J | increase todo priority |
| K | decrease todo priority |
| d | toggle daily |
| D | delete todo |
| > | add todo note |
| t | add todo dependency |
| l | go in depedency/add todo dependency |
| h | go back to parent |
| T | delete todo dependency/note |
| x | cut todo to clipboard |
| y | yank todo to clipboard |
| p | paste todo from clipboard |
| P | enable module |
| / | search todo |
| n | search next |
| N | search previous |
| w | write changes to file |
| R | read from file (discard changes)|
#### Modules
TUI mode has a section called module. You can develop modules, and assign methods to Module trait methods.
A very simple example has been done by default for [potato-c](https://github.com/nimaaskarian/potato-c).

Keybinds that modules can use are **space, H, L, comma, period, +, -, s, r**

6 changes: 0 additions & 6 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ pub fn run(args: Args) -> io::Result<()> {
let operation = app.update_return_operation()?;
match operation {
Operation::Restart => restart(&mut terminal)?,
Operation::Redraw => {
app.fix_index();
terminal.draw(|frame| {
app.ui(frame, &mut list_state)
})?;
}
Operation::Nothing =>{},
}
}
Expand Down
35 changes: 15 additions & 20 deletions src/tui/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// vim:fileencoding=utf-8:foldmethod=marker
// std{{{
use std::{io::{self}, path::PathBuf};
use std::{io::{self, Write}, path::PathBuf, fs::File};
//}}}
// lib{{{
use tui_textarea::{Input, TextArea, CursorMove};
Expand All @@ -21,7 +21,6 @@ use crate::Args;
pub enum Operation {
Nothing,
Restart,
Redraw,
}

pub struct App<'a>{
Expand Down Expand Up @@ -190,12 +189,14 @@ impl<'a>App<'a>{
let was_done = self.todo().unwrap().done();
self.mut_todo().unwrap().toggle_done();
self.fix_done_undone();
let index = if was_done {
self.current_list().undone.len()-1
} else {
self.current_list().len()-1
};
self.index = self.mut_current_list().reorder(index);
if self.show_done {
let index = if was_done {
self.current_list().undone.len()-1
} else {
self.current_list().len()-1
};
self.index = self.mut_current_list().reorder(index);
}
}

#[inline]
Expand Down Expand Up @@ -231,10 +232,13 @@ impl<'a>App<'a>{
#[inline]
pub fn fix_index(&mut self) {
let size = self.len();
let mut file = File::create("log").unwrap();
writeln!(file, "{}", self.index);
self.index = match size {
0 => 0,
_ => self.index.min(size-1),
};
writeln!(file, "{}", self.index);
}

#[inline]
Expand Down Expand Up @@ -669,8 +673,8 @@ impl<'a>App<'a>{
if self.text_mode {
return self.update_editor();
} else {
self.fix_index();
self.update_no_editor()?;
self.fix_index();
}
Ok(Operation::Nothing)
}
Expand All @@ -693,10 +697,7 @@ impl<'a>App<'a>{
if let Key(key) = event::read()? {
if key.kind == event::KeyEventKind::Press {
match key.code {
Char('x') => {
self.cut_todo();
return Ok(Operation::Redraw)
}
Char('x') => self.cut_todo(),
Char('d') => self.toggle_current_daily(),
Char('!') => self.toggle_show_done(),
Char('y') => self.yank_todo(),
Expand All @@ -723,16 +724,10 @@ impl<'a>App<'a>{
Char('t') => self.add_dependency(),
Char('D') => {
self.delete_todo();
return Ok(Operation::Redraw)
}
Char('R') => self.read(),
Char('T') => self.remove_current_dependent(),
KeyCode::Enter => {
self.toggle_current_done();
if !self.show_done {
return Ok(Operation::Redraw)
}
},
KeyCode::Enter => self.toggle_current_done(),
Char('n') => self.search_next(),
Char('N') => self.search_prev(),
Char('a') => self.prepend_prompt(),
Expand Down

0 comments on commit 93ad5cc

Please sign in to comment.