From 9eeb5aebd891eecadae575f6a27509c018beca54 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 19 Jul 2020 23:11:06 -0700 Subject: Disable default ncurses backend from cursive Cursive includes the ncurses backend by default, which requires building it and overall causes a bunch of unnecessary complications. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 0240b65..6e94652 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ notify = "4.0" [dependencies.cursive] version = "0.15" +default-features = false features = ["termion-backend"] [dependencies.chrono] -- cgit v1.2.3 From a0b6e884e39c858855db28377f094c9466002274 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 20 Jul 2020 14:42:29 +0530 Subject: add MSRV to installation section --- readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c407fae..fbca787 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,10 @@ much like a certain text editor. Get `dijo` by running the following at the nearest prompt: -``` +```shell +# dijo requires rustc >= v1.42 +$ rustup update + $ cargo install dijo ``` -- cgit v1.2.3 From 8b91a7c0b3d9bd4fac3b140f5bc8a40ac324289a Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 20 Jul 2020 19:31:23 +0530 Subject: bump to v0.1.4: remove ncurses as dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6e94652..9cf3639 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dijo" -version = "0.1.3" +version = "0.1.4" authors = ["Akshay "] edition = "2018" description = "Scriptable, curses-based, digital habit tracker" -- cgit v1.2.3 From 2a3be003015bac9c6a13549029b9fb4595e88384 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 20 Jul 2020 21:13:45 +0530 Subject: allow "untracking" of habits, closes #18 --- Cargo.lock | 44 +------------------------------------------- src/habit/bit.rs | 17 ++++++++++++++--- src/habit/count.rs | 7 +++++-- src/habit/prelude.rs | 1 + 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63d34ea..ade0cc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -91,12 +91,6 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "cc" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" - [[package]] name = "cfg-if" version = "0.1.10" @@ -201,10 +195,7 @@ dependencies = [ "lazy_static", "libc", "log", - "maplit", - "ncurses", "signal-hook", - "term_size", "termion", "unicode-segmentation", "unicode-width", @@ -269,7 +260,7 @@ dependencies = [ [[package]] name = "dijo" -version = "0.1.3" +version = "0.1.4" dependencies = [ "chrono", "clap", @@ -539,12 +530,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - [[package]] name = "maybe-uninit" version = "2.0.0" @@ -594,17 +579,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "ncurses" -version = "5.99.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15699bee2f37e9f8828c7b35b2bc70d13846db453f2d507713b758fabe536b82" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "net2" version = "0.2.34" @@ -712,12 +686,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "pkg-config" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" - [[package]] name = "proc-macro-hack" version = "0.5.16" @@ -881,16 +849,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "term_size" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "termion" version = "1.5.5" diff --git a/src/habit/bit.rs b/src/habit/bit.rs index 3386182..8fa14c2 100644 --- a/src/habit/bit.rs +++ b/src/habit/bit.rs @@ -100,11 +100,22 @@ impl Habit for Bit { fn goal(&self) -> u32 { return 1; } - fn modify(&mut self, date: NaiveDate, _: TrackEvent) { + fn modify(&mut self, date: NaiveDate, event: TrackEvent) { if let Some(val) = self.stats.get_mut(&date) { - *val = (val.0 ^ true).into(); + match event { + TrackEvent::Increment => *val = (val.0 ^ true).into(), + TrackEvent::Decrement => { + if val.0 { + *val = false.into(); + } else { + self.stats.remove(&date); + } + } + } } else { - self.insert_entry(date, CustomBool(true)); + if event == TrackEvent::Increment { + self.insert_entry(date, CustomBool(true)); + } } } fn set_view_month_offset(&mut self, offset: u32) { diff --git a/src/habit/count.rs b/src/habit/count.rs index 1bdf920..d351758 100644 --- a/src/habit/count.rs +++ b/src/habit/count.rs @@ -84,12 +84,15 @@ impl Habit for Count { if *val > 0 { *val -= 1 } else { - *val = 0 + self.stats.remove(&date); }; } } } else { - self.insert_entry(date, 1); + match event { + TrackEvent::Increment => self.insert_entry(date, 1), + _ => {} + }; } } fn set_view_month_offset(&mut self, offset: u32) { diff --git a/src/habit/prelude.rs b/src/habit/prelude.rs index 19b00a7..8335d6c 100644 --- a/src/habit/prelude.rs +++ b/src/habit/prelude.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use std::default; use std::fmt; +#[derive(Debug, PartialEq)] pub enum TrackEvent { Increment, Decrement, -- cgit v1.2.3 From 552d29f9809f20b3c970b2464512847f7d141c66 Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Mon, 20 Jul 2020 21:01:48 -0300 Subject: Fix broken link --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index fbca787..714234e 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,7 @@ much like a certain text editor. - **vim like command mode**: add with `:add`, delete with `:delete` and above all, quit with `:q`!. - **fully scriptable**: [configure `dijo` to - track your `git` commits](./Auto-Habits)! + track your `git` commits](https://github.com/NerdyPepper/dijo/wiki/Auto-Habits)! ### Install -- cgit v1.2.3 From 76a6e78ccbea125ab5b8c06ff254260759d3140c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 11:24:42 +0530 Subject: switch to local time over utc time --- src/app/impl_self.rs | 4 ++-- src/views.rs | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 744f906..2450bff 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -118,7 +118,7 @@ impl App { } pub fn status(&self) -> StatusLine { - let today = chrono::Local::now().naive_utc().date(); + let today = chrono::Local::now().naive_local().date(); let remaining = self.habits.iter().map(|h| h.remaining(today)).sum::(); let total = self.habits.iter().map(|h| h.goal()).sum::(); let completed = total - remaining; @@ -207,7 +207,7 @@ impl App { .iter_mut() .find(|x| x.name() == name && x.is_auto()); if let Some(h) = target_habit { - h.modify(Local::now().naive_utc().date(), event); + h.modify(Local::now().naive_local().date(), event); } }; match result { diff --git a/src/views.rs b/src/views.rs index 24c8a4d..da077ac 100644 --- a/src/views.rs +++ b/src/views.rs @@ -43,7 +43,7 @@ where let strikethrough = Style::from(Effect::Strikethrough); let goal_status = - self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_utc().date()); + self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_local().date()); printer.with_style( Style::merge(&[ @@ -77,12 +77,20 @@ where .collect::>(); for (week, line_nr) in days.chunks(7).zip(2..) { let weekly_goal = self.goal() * week.len() as u32; - let is_this_week = week.contains(&Local::now().naive_utc().date()); + let is_this_week = week.contains(&Local::now().naive_local().date()); let remaining = week.iter().map(|&i| self.remaining(i)).sum::(); let completions = weekly_goal - remaining; let full = CONFIGURATION.view_width - 8; - let bars_to_fill = if weekly_goal > 0 {(completions * full as u32) / weekly_goal} else {0}; - let percentage = if weekly_goal > 0 {(completions as f64 * 100.) / weekly_goal as f64} else {0.0}; + let bars_to_fill = if weekly_goal > 0 { + (completions * full as u32) / weekly_goal + } else { + 0 + }; + let percentage = if weekly_goal > 0 { + (completions as f64 * 100.) / weekly_goal as f64 + } else { + 0.0 + }; printer.with_style(future_style, |p| { p.print((4, line_nr), &"─".repeat(full)); }); @@ -141,7 +149,7 @@ where } fn on_event(&mut self, e: Event) -> EventResult { - let now = Local::now().naive_utc().date(); + let now = Local::now().naive_local().date(); if self.is_auto() { return EventResult::Ignored; } -- cgit v1.2.3 From 4f76460efa869317bd7065b4770c16d0146a92da Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 20:33:22 +0530 Subject: add help command --- src/app/impl_self.rs | 23 +++++++++++++++++++++++ src/command.rs | 13 ++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 2450bff..95f1871 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -230,6 +230,29 @@ impl App { Command::TrackDown(name) => { _track(&name, TrackEvent::Decrement); } + Command::Help(input) => { + if let Some(topic) = input.as_ref().map(String::as_ref) { + self.message.set_message( + match topic { + "a" | "add" => "add [goal] (alias: a)", + "aa" | "add-auto" => "add-auto [goal] (alias: aa)", + "d" | "delete" => "delete (alias: d)", + "mprev" | "month-prev" => "month-prev (alias: mprev)", + "mnext" | "month-next" => "month-next (alias: mnext)", + "tup" | "track-up" => "track-up (alias: tup)", + "tdown" | "track-down" => "track-down (alias: tdown)", + "q" | "quit" => "quit", + "h"|"?" | "help" => "help [|commands|keys] (aliases: h, ?)", + "cmds" | "commands" => "add, add-auto, delete, month-{prev,next}, track-{up,down}, help, quit", + "keys" => "TODO", // TODO (view?) + _ => "unknown command or help topic.", + } + ) + } else { + // TODO (view?) + self.message.set_message("help |commands|keys") + } + } Command::Quit => self.save_state(), Command::MonthNext => self.sift_forward(), Command::MonthPrev => self.sift_backward(), diff --git a/src/command.rs b/src/command.rs index f856b00..29908f4 100644 --- a/src/command.rs +++ b/src/command.rs @@ -59,15 +59,16 @@ pub enum Command { Delete(String), TrackUp(String), TrackDown(String), + Help(Option), Quit, Blank, } #[derive(Debug)] pub enum CommandLineError { - InvalidCommand(String), - InvalidArg(u32), // position - NotEnoughArgs(String, u32), + InvalidCommand(String), // command name + InvalidArg(u32), // position + NotEnoughArgs(String, u32), // command name, required no. of args } impl std::error::Error for CommandLineError {} @@ -134,6 +135,12 @@ impl Command { } return Ok(Command::TrackDown(args[0].to_string())); } + "h" | "?" | "help" => { + if args.is_empty() { + return Ok(Command::Help(None)); + } + return Ok(Command::Help(Some(args[0].to_string()))); + } "mprev" | "month-prev" => return Ok(Command::MonthPrev), "mnext" | "month-next" => return Ok(Command::MonthNext), "q" | "quit" => return Ok(Command::Quit), -- cgit v1.2.3 From 9102dc72be19f87ec9e2893a35f5020957135c1c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 20:47:05 +0530 Subject: bump to v0.1.5 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ade0cc4..bda3c1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ dependencies = [ [[package]] name = "dijo" -version = "0.1.4" +version = "0.1.5" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 9cf3639..3f297b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dijo" -version = "0.1.4" +version = "0.1.5" authors = ["Akshay "] edition = "2018" description = "Scriptable, curses-based, digital habit tracker" -- cgit v1.2.3 From 9dfe454cd8bc816522446e7e3b9f45630c886112 Mon Sep 17 00:00:00 2001 From: Guillaume Hormiere Date: Wed, 22 Jul 2020 00:38:01 +0200 Subject: Add list command for shell script purpose Usage dijo -l for printing the habit names list Add check on habit add to avoid duplicate habits --- src/app/impl_self.rs | 21 ++++++++++++++++++++- src/main.rs | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 95f1871..38162ee 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -33,8 +33,27 @@ impl App { }; } + pub fn list_habit(&self) -> Vec { + let mut habits_names: Vec = vec![]; + for h in self.habits.iter() { + habits_names.push(h.name()) + } + return habits_names; + } + pub fn add_habit(&mut self, h: Box) { - self.habits.push(h); + if self + .habits + .iter() + .filter(|hab| hab.name() == h.name()) + .count() + > 0 + { + self.message + .set_message(format!("Habit `{}` allready exist", h.name())) + } else { + self.habits.push(h); + } } pub fn delete_by_name(&mut self, name: &str) { diff --git a/src/main.rs b/src/main.rs index d96119e..050a296 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,14 @@ fn main() { .value_name("CMD") .help("run a dijo command"), ) + .arg( + Arg::with_name("list") + .short("l") + .long("list") + .takes_value(false) + .help("list dijo habits") + .conflicts_with("command"), + ) .get_matches(); if let Some(c) = matches.value_of("command") { let command = Command::from_string(c); @@ -49,6 +57,12 @@ fn main() { "Commands other than `track-up` and `track-down` are currently not supported!" ), } + } else if matches.is_present("list") { + let app = App::load_state(); + let _habit_names = app.list_habit(); + for h in _habit_names { + println!("{}", h); + } } else { let mut s = termion().unwrap(); let app = App::load_state(); -- cgit v1.2.3 From 3f64deb152c31f2a04612d9c525537a72605d678 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 22 Jul 2020 21:00:38 +0530 Subject: remove `d` keybind, add tab completion --- src/app/impl_self.rs | 4 +++ src/app/impl_view.rs | 8 ------ src/command.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 95f1871..7eae853 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -37,6 +37,10 @@ impl App { self.habits.push(h); } + pub fn list_habits(&self) -> Vec { + self.habits.iter().map(|x| x.name()).collect::>() + } + pub fn delete_by_name(&mut self, name: &str) { let old_len = self.habits.len(); self.habits.retain(|h| h.name() != name); diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index 892b00c..b8c4589 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs @@ -102,14 +102,6 @@ impl View for App { self.set_focus(Absolute::Down); return EventResult::Consumed(None); } - Event::Char('d') => { - if self.habits.is_empty() { - return EventResult::Consumed(None); - } - self.habits.remove(self.focus); - self.focus = self.focus.checked_sub(1).unwrap_or(0); - return EventResult::Consumed(None); - } Event::Char('w') => { // helper bind to test write to file let j = serde_json::to_string_pretty(&self.habits).unwrap(); diff --git a/src/command.rs b/src/command.rs index 29908f4..2f6b48a 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,21 +1,75 @@ use std::fmt; +use std::rc::Rc; +use cursive::event::{Event, EventResult, Key}; use cursive::theme::{BaseColor, Color, ColorStyle}; use cursive::view::Resizable; -use cursive::views::{EditView, LinearLayout, TextView}; +use cursive::views::{EditView, LinearLayout, OnEventView, TextView}; use cursive::Cursive; use crate::{app::App, CONFIGURATION}; +static COMMANDS: &'static [&'static str] = &[ + "add", + "add-auto", + "delete", + "track-up", + "track-down", + "month-prev", + "month-next", + "quit", + "help", +]; + +fn get_command_completion(prefix: &str) -> Option { + let first_match = COMMANDS.iter().filter(|&x| x.starts_with(prefix)).next(); + return first_match.map(|&x| x.into()); +} + +fn get_habit_completion(prefix: &str, habit_names: &[String]) -> Option { + let first_match = habit_names.iter().filter(|&x| x.starts_with(prefix)).next(); + eprintln!("{:?}| {:?}", prefix, first_match); + return first_match.map(|x| x.into()); +} + pub fn open_command_window(s: &mut Cursive) { - let command_window = EditView::new() - .filler(" ") - .on_submit(call_on_app) - .style(ColorStyle::new( - Color::Dark(BaseColor::Black), - Color::Dark(BaseColor::White), - )) - .fixed_width(CONFIGURATION.view_width * CONFIGURATION.grid_width); + let habit_list: Vec = s + .call_on_name("Main", |view: &mut App| { + return view.list_habits(); + }) + .unwrap(); + let style = ColorStyle::new(Color::Dark(BaseColor::Black), Color::Dark(BaseColor::White)); + let command_window = OnEventView::new( + EditView::new() + .filler(" ") + .on_submit(call_on_app) + .style(style), + ) + .on_event_inner( + Event::Key(Key::Tab), + move |view: &mut EditView, _: &Event| { + let contents = view.get_content(); + if !contents.contains(" ") { + let completion = get_command_completion(&*contents); + if let Some(c) = completion { + let cb = view.set_content(c); + return Some(EventResult::Consumed(Some(cb))); + }; + return None; + } else { + let word = contents.split(' ').last().unwrap(); + let completion = get_habit_completion(word, &habit_list); + eprintln!("{:?} | {:?}", completion, contents); + if let Some(c) = completion { + let cb = + view.set_content(format!("{}", contents) + c.strip_prefix(word).unwrap()); + return Some(EventResult::Consumed(Some(cb))); + }; + return None; + } + }, + ) + .fixed_width(CONFIGURATION.view_width * CONFIGURATION.grid_width); s.call_on_name("Frame", |view: &mut LinearLayout| { let mut commandline = LinearLayout::horizontal() .child(TextView::new(":")) -- cgit v1.2.3 From 23e85aab0571f9c7214532a18a490ba6b6573f0e Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 22 Jul 2020 21:51:41 +0530 Subject: remove unused import --- src/command.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/command.rs b/src/command.rs index 2f6b48a..850261c 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,5 +1,4 @@ use std::fmt; -use std::rc::Rc; use cursive::event::{Event, EventResult, Key}; use cursive::theme::{BaseColor, Color, ColorStyle}; -- cgit v1.2.3 From c421750d739f008902822a0254ccdff93556dca6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 22 Jul 2020 22:03:14 +0530 Subject: add action automatically release binaries on tag --- .github/workflows/main.yml | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c8ccbae --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,84 @@ +name: Rust + +on: + push: + tags: + - '*' + +jobs: + rustfmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: rustup component add rustfmt + - run: cargo fmt -- --check + + build-linux: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + # cache the build assets so they dont recompile every time. + - name: Cache Rust dependencies + uses: actions/cache@v1.0.1 + with: + path: target + key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.OS }}-build- + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: beta + default: true + override: true + - name: Install system dependencies + run: | + sudo apt-get update \ + && sudo apt-get install -y \ + libdbus-1-dev + - name: Build + run: cargo build --all --release && strip target/release/dijo + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/release/dijo + asset_name: dijo-x86_64-linux + tag: ${{ github.ref }} + overwrite: true + + build-apple: + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Cache Rust dependencies + uses: actions/cache@v1.0.1 + with: + path: target + key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.OS }}-build- + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: beta + target: x86_64-apple-darwin + default: true + override: true + + - name: Build for mac + run: cargo build --all --release && strip target/release/dijo + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/release/dijo + asset_name: dijo-x86_64-apple + tag: ${{ github.ref }} + overwrite: true -- cgit v1.2.3 From 5c910bc6cf193725575ef6146dcc8620e7a4a800 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 22 Jul 2020 22:08:50 +0530 Subject: remove debug key binds, add :write command --- src/app/impl_self.rs | 2 +- src/app/impl_view.rs | 11 ----------- src/command.rs | 3 +++ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 7eae853..cf0e97f 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -257,7 +257,7 @@ impl App { self.message.set_message("help |commands|keys") } } - Command::Quit => self.save_state(), + Command::Quit | Command::Write => self.save_state(), Command::MonthNext => self.sift_forward(), Command::MonthPrev => self.sift_backward(), Command::Blank => {} diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index b8c4589..0dfd20b 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs @@ -102,17 +102,6 @@ impl View for App { self.set_focus(Absolute::Down); return EventResult::Consumed(None); } - Event::Char('w') => { - // helper bind to test write to file - let j = serde_json::to_string_pretty(&self.habits).unwrap(); - let mut file = File::create("foo.txt").unwrap(); - file.write_all(j.as_bytes()).unwrap(); - return EventResult::Consumed(None); - } - Event::Char('q') => { - self.save_state(); - return EventResult::with_cb(|s| s.quit()); - } Event::Char('v') => { if self.habits.is_empty() { return EventResult::Consumed(None); diff --git a/src/command.rs b/src/command.rs index 850261c..38d48e9 100644 --- a/src/command.rs +++ b/src/command.rs @@ -17,6 +17,7 @@ static COMMANDS: &'static [&'static str] = &[ "month-prev", "month-next", "quit", + "write", "help", ]; @@ -113,6 +114,7 @@ pub enum Command { TrackUp(String), TrackDown(String), Help(Option), + Write, Quit, Blank, } @@ -197,6 +199,7 @@ impl Command { "mprev" | "month-prev" => return Ok(Command::MonthPrev), "mnext" | "month-next" => return Ok(Command::MonthNext), "q" | "quit" => return Ok(Command::Quit), + "w" | "write" => return Ok(Command::Write), "" => return Ok(Command::Blank), s => return Err(CommandLineError::InvalidCommand(s.into())), } -- cgit v1.2.3 From a0c57162b2026e37220e31a39d821c2a2e31cc51 Mon Sep 17 00:00:00 2001 From: Guillaume Hormiere Date: Wed, 22 Jul 2020 22:26:19 +0200 Subject: Use immutable vector instead of mutable one and change the message kind to Error Apply code review --- src/app/impl_self.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 38162ee..8a84cb2 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -34,10 +34,7 @@ impl App { } pub fn list_habit(&self) -> Vec { - let mut habits_names: Vec = vec![]; - for h in self.habits.iter() { - habits_names.push(h.name()) - } + let habits_names = self.habits.iter().map(|x| x.name()).collect::>(); return habits_names; } @@ -49,6 +46,7 @@ impl App { .count() > 0 { + self.message.set_kind(MessageKind::Error); self.message .set_message(format!("Habit `{}` allready exist", h.name())) } else { -- cgit v1.2.3 From f5940ea5fc507ec34d686a888a1aa1aba50be277 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 10:06:34 +0530 Subject: fix tiemzones in statusline --- src/app/impl_self.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index cf0e97f..1ed19e6 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -128,7 +128,7 @@ impl App { let completed = total - remaining; let timestamp = if self.view_month_offset == 0 { - format!("{}", Local::now().date().format("%d/%b/%y"),) + format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),) } else { let months = self.view_month_offset; format!("{}", format!("{} months ago", months),) -- cgit v1.2.3 From 59b40932d4602fc7bf84f123930f9a0eb187f4a1 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 10:07:21 +0530 Subject: bump to v0.2.0! --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bda3c1e..a299289 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ dependencies = [ [[package]] name = "dijo" -version = "0.1.5" +version = "0.2.0" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 3f297b8..f215503 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dijo" -version = "0.1.5" +version = "0.2.0" authors = ["Akshay "] edition = "2018" description = "Scriptable, curses-based, digital habit tracker" -- cgit v1.2.3 From b0b6c04a052955834f0603df79db7a0a517a9b9d Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 13:19:15 +0530 Subject: move duplicate check to command parsing block --- src/app/impl_self.rs | 25 +++++++------------------ src/main.rs | 4 +--- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 1dfe268..a806dc5 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -33,25 +33,8 @@ impl App { }; } - pub fn list_habit(&self) -> Vec { - let habits_names = self.habits.iter().map(|x| x.name()).collect::>(); - return habits_names; - } - pub fn add_habit(&mut self, h: Box) { - if self - .habits - .iter() - .filter(|hab| hab.name() == h.name()) - .count() - > 0 - { - self.message.set_kind(MessageKind::Error); - self.message - .set_message(format!("Habit `{}` allready exist", h.name())) - } else { - self.habits.push(h); - } + self.habits.push(h); } pub fn list_habits(&self) -> Vec { @@ -234,6 +217,12 @@ impl App { match result { Ok(c) => match c { Command::Add(name, goal, auto) => { + if let Some(_) = self.habits.iter().find(|x| x.name() == name) { + self.message.set_kind(MessageKind::Error); + self.message + .set_message(format!("Habit `{}` already exist", &name)); + return; + } let kind = if goal == Some(1) { "bit" } else { "count" }; if kind == "count" { self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); diff --git a/src/main.rs b/src/main.rs index 050a296..5523073 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,9 +58,7 @@ fn main() { ), } } else if matches.is_present("list") { - let app = App::load_state(); - let _habit_names = app.list_habit(); - for h in _habit_names { + for h in App::load_state().list_habits() { println!("{}", h); } } else { -- cgit v1.2.3 From 7322949561fdbdc36a811b1368222fb5a2bf050a Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 20 Jul 2020 11:38:20 +0530 Subject: switch to crossterm backend --- Cargo.lock | 180 +++++++++++++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 2 +- src/main.rs | 4 +- 3 files changed, 139 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a299289..25e21e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,15 @@ dependencies = [ "vec_map", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + [[package]] name = "const-random" version = "0.1.8" @@ -152,12 +161,12 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "crossbeam-channel" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061" +checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6" dependencies = [ + "cfg-if", "crossbeam-utils", - "maybe-uninit", ] [[package]] @@ -171,6 +180,31 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crossterm" +version = "0.17.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f4919d60f26ae233e14233cc39746c8c8bb8cd7b05840ace83604917b51b6c7" +dependencies = [ + "bitflags", + "crossterm_winapi", + "lazy_static", + "libc", + "mio 0.7.0", + "parking_lot", + "signal-hook", + "winapi 0.3.9", +] + +[[package]] +name = "crossterm_winapi" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "ctor" version = "0.1.15" @@ -190,13 +224,13 @@ dependencies = [ "ahash 0.3.8", "cfg-if", "crossbeam-channel", + "crossterm", "cursive_core", "enumset", "lazy_static", "libc", "log", "signal-hook", - "termion", "unicode-segmentation", "unicode-width", ] @@ -521,6 +555,15 @@ version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" +[[package]] +name = "lock_api" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.11" @@ -530,12 +573,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "mio" version = "0.6.22" @@ -549,12 +586,26 @@ dependencies = [ "kernel32-sys", "libc", "log", - "miow", + "miow 0.2.1", "net2", "slab", "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9971bc8349a361217a8f2a41f5d011274686bd4436465ba51730921039d7fb" +dependencies = [ + "lazy_static", + "libc", + "log", + "miow 0.3.5", + "ntapi", + "winapi 0.3.9", +] + [[package]] name = "mio-extras" version = "2.0.6" @@ -563,7 +614,7 @@ checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", "log", - "mio", + "mio 0.6.22", "slab", ] @@ -579,6 +630,16 @@ dependencies = [ "ws2_32-sys", ] +[[package]] +name = "miow" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" +dependencies = [ + "socket2", + "winapi 0.3.9", +] + [[package]] name = "net2" version = "0.2.34" @@ -602,12 +663,21 @@ dependencies = [ "fsevent-sys", "inotify", "libc", - "mio", + "mio 0.6.22", "mio-extras", "walkdir", "winapi 0.3.9", ] +[[package]] +name = "ntapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "num" version = "0.3.0" @@ -671,12 +741,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "numtoa" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" - [[package]] name = "owning_ref" version = "0.4.1" @@ -686,6 +750,30 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "parking_lot" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec", + "winapi 0.3.9", +] + [[package]] name = "proc-macro-hack" version = "0.5.16" @@ -694,9 +782,9 @@ checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] @@ -716,15 +804,6 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -[[package]] -name = "redox_termios" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -dependencies = [ - "redox_syscall", -] - [[package]] name = "redox_users" version = "0.3.4" @@ -763,6 +842,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "serde" version = "1.0.114" @@ -801,6 +886,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed" dependencies = [ "libc", + "mio 0.7.0", "signal-hook-registry", ] @@ -820,6 +906,24 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "smallvec" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" + +[[package]] +name = "socket2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi 0.3.9", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -840,27 +944,15 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "syn" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "termion" -version = "1.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905" -dependencies = [ - "libc", - "numtoa", - "redox_syscall", - "redox_termios", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index f215503..c587196 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ notify = "4.0" [dependencies.cursive] version = "0.15" default-features = false -features = ["termion-backend"] +features = ["crossterm-backend"] [dependencies.chrono] version = "0.4" diff --git a/src/main.rs b/src/main.rs index 5523073..3e35ebc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use crate::command::{open_command_window, Command}; use crate::utils::{load_configuration_file, AppConfig}; use clap::{App as ClapApp, Arg}; -use cursive::termion; +use cursive::crossterm; use cursive::views::{LinearLayout, NamedView}; use lazy_static::lazy_static; @@ -62,7 +62,7 @@ fn main() { println!("{}", h); } } else { - let mut s = termion().unwrap(); + let mut s = crossterm().unwrap(); let app = App::load_state(); let layout = NamedView::new( "Frame", -- cgit v1.2.3 From d1d1aeb3d5aaa75f262467c5e683e76ce7a844ab Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 23 Jul 2020 11:48:56 +0300 Subject: add windows to github actions --- .github/workflows/main.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c8ccbae..e2995b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -82,3 +82,38 @@ jobs: asset_name: dijo-x86_64-apple tag: ${{ github.ref }} overwrite: true + + build-windows: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Cache Rust dependencies + uses: actions/cache@v1.0.1 + with: + path: target + key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.OS }}-build- + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: beta + target: x86_64-pc-windows-msvc + default: true + override: true + + - name: Build for windows + run: | + cargo build --all --release + strip target/release/dijo + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/release/dijo + asset_name: dijo-x86_64-windows + tag: ${{ github.ref }} + overwrite: true -- cgit v1.2.3