Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Jul 24, 2024
2 parents 3733e76 + 003ccb2 commit 1a37eb3
Show file tree
Hide file tree
Showing 20 changed files with 888 additions and 712 deletions.
42 changes: 29 additions & 13 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "c3"
version = "1.1.0"
version = "1.2.0"
edition = "2021"

[dependencies]
Expand All @@ -11,6 +11,7 @@ crossterm = "0.27.0"
tui-textarea = "0.4.0"
chrono = "0.4.31"
clap = { version = "4.4.18", features = ["derive", "string"] }
clap_complete = "4.5.9"

[profile.release]
codegen-units = 1
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The default mode of the app is TUI mode. Keybinds are vim-like. Here they are:
|---|---|
| a | add todo to bottom|
| A | add todo to top|
| space | toggle todo done |
| e | edit todo |
| E | edit todo (move cursor to start) |
| ! | toggle show done |
Expand All @@ -63,27 +64,26 @@ The default mode of the app is TUI mode. Keybinds are vim-like. Here they are:
| i | increase day done |
| I | increase day done |
| t | add todo dependency |
| l | go in depedency/add todo dependency |
| l, enter | 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 current list for todo |
| ? | search the whole tree for todo |
| ? | search the whole tree for todo (tree search) |
| Tab | tree search next |
| o | open nnn file picker to choose a file to append to current list |
| O | open nnn file picker to choose a file to output current list to |
| Ctrl+o | open nnn file picker to choose a file to open |
| 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**
Keybinds that modules can use are **C, c, H, L, comma, period, +, -, s, r**

### Non interactive mode
For command line arguments and such, run `c3 -h` to see full usage.
42 changes: 20 additions & 22 deletions patches/jalali-date.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
diff --git a/Cargo.lock b/Cargo.lock
index c40a47c..0988fcc 100644
index 314718e..286bd3f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -124,7 +124,9 @@ dependencies = [
@@ -124,8 +124,10 @@ dependencies = [
"clap",
"clap_complete",
"crossterm",
"home",
+ "jalali-date",
Expand Down Expand Up @@ -78,39 +79,40 @@ index c40a47c..0988fcc 100644
name = "scopeguard"
version = "1.2.0"
diff --git a/Cargo.toml b/Cargo.toml
index 2da7de8..266ecb1 100644
index 1e9f2ec..4e69d4a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,6 +11,8 @@ crossterm = "0.27.0"
tui-textarea = "0.4.0"
chrono = "0.4.31"
clap = { version = "4.4.18", features = ["derive", "string"] }
clap_complete = "4.5.9"
+jalali-date = "0.2.0"
+scanf = "1.2.1"

[profile.release]
codegen-units = 1
diff --git a/src/date.rs b/src/date.rs
index 16c5eda..8d89a33 100644
index 2c5aa57..12d7d3e 100644
--- a/src/date.rs
+++ b/src/date.rs
@@ -1,5 +1,7 @@
-use chrono::{Local ,NaiveDate, Duration};
+use chrono::{Datelike, Duration, Local, NaiveDate};
use chrono::format::ParseError;
-use chrono::{Duration, Local, NaiveDate};
+use chrono::{Datelike, Duration, Local, NaiveDate};
+use jalali_date::{jalali_to_gregorian, to_jalali, JalaliDate};
+use scanf::sscanf;
const FORMAT: &str = "%Y-%m-%d";

pub type Type = NaiveDate;
@@ -9,9 +11,43 @@ pub fn parse(date_string: &str) -> Result<Type, ParseError> {
@@ -9,9 +11,42 @@ pub fn parse(date_string: &str) -> Result<Type, ParseError> {
NaiveDate::parse_from_str(date_string, FORMAT)
}

+#[inline]
+fn jalali_to_georgian_naive(j_year: i32, j_month: i32, j_day: i32) -> Option<Type> {
+ let g_date = jalali_to_gregorian(j_year, j_month, j_day);
+ NaiveDate::from_ymd_opt(g_date.year , g_date.month as u32, g_date.day as u32)
+ NaiveDate::from_ymd_opt(g_date.year, g_date.month as u32, g_date.day as u32)
+}
+
+#[inline]
Expand All @@ -130,26 +132,25 @@ index 16c5eda..8d89a33 100644
+ let mut j_month = 0;
+ let mut j_day = 0;
+ match date_string {
+ _ if sscanf!(date_string,"{}-{}-{}", j_year, j_month, j_day).is_ok() => {
+ _ if sscanf!(date_string, "{}-{}-{}", j_year, j_month, j_day).is_ok() => {
+ if let Some(date) = jalali_to_georgian_naive(j_year, j_month, j_day) {
+ return Ok(date)
+ return Ok(date);
+ }
+ }
+ _ if sscanf!(date_string,"{}-{}", j_month, j_day).is_ok() => {
+
+ _ if sscanf!(date_string, "{}-{}", j_month, j_day).is_ok() => {
+ let current_j_date = naive_to_jalali(current());
+ if let Some(date) = jalali_to_georgian_naive(current_j_date.year as i32, j_month, j_day) {
+ return Ok(date)
+ if let Some(date) = jalali_to_georgian_naive(current_j_date.year as i32, j_month, j_day)
+ {
+ return Ok(date);
+ }
+
+ }
+ _ =>{},
+ _ => {}
+ }
+ Err(Error::ParseFailed)
}

#[inline]
@@ -27,11 +63,18 @@ pub fn format(input: Option<Type>) -> String {
@@ -27,9 +62,15 @@ pub fn format(input: Option<Type>) -> String {
}
}

Expand All @@ -158,15 +159,12 @@ index 16c5eda..8d89a33 100644
pub fn display(input: Option<Type>) -> String {
- format(input)
+ match input {
+ Some(date)=> {
+ Some(date) => {
+ let j_date = naive_to_jalali(date);
+ format!("{}-{:0>2}-{:0>2}", j_date.year, j_date.month, j_date.day)
+ },
+ }
+ None => String::new(),
+ }
}

+
#[inline]
pub fn diff_days(first: Option<Type>, next: Option<Type>) -> i64 {
match (first, next) {
18 changes: 0 additions & 18 deletions shell-completions/c3.fish

This file was deleted.

Loading

0 comments on commit 1a37eb3

Please sign in to comment.