aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoronielfa <[email protected]>2020-07-23 23:56:38 +0100
committeronielfa <[email protected]>2020-07-23 23:56:38 +0100
commit7e44bbff6d7f572f5f92b3a6b0f1d5e523379ba4 (patch)
treeb80e0883bbd1bd02fa11f790c80c471a77800602
parent242d58264df4842464e12c70297608bc0833d632 (diff)
parentd7c303dda4750a432478c94b3ed41bca1352d839 (diff)
Merge branch 'master' into feature/larger-names
-rw-r--r--.github/workflows/main.yml39
-rw-r--r--Cargo.lock154
-rw-r--r--Cargo.toml7
-rw-r--r--src/app/impl_self.rs8
-rw-r--r--src/command.rs3
-rw-r--r--src/main.rs23
6 files changed, 210 insertions, 24 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c8ccbae..5c3e6f9 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -39,7 +39,7 @@ jobs:
39 && sudo apt-get install -y \ 39 && sudo apt-get install -y \
40 libdbus-1-dev 40 libdbus-1-dev
41 - name: Build 41 - name: Build
42 run: cargo build --all --release && strip target/release/dijo 42 run: cargo build -all --no-default-features --features unix --release && strip target/release/dijo
43 43
44 - name: Upload binaries to release 44 - name: Upload binaries to release
45 uses: svenstaro/upload-release-action@v1-release 45 uses: svenstaro/upload-release-action@v1-release
@@ -72,7 +72,7 @@ jobs:
72 override: true 72 override: true
73 73
74 - name: Build for mac 74 - name: Build for mac
75 run: cargo build --all --release && strip target/release/dijo 75 run: cargo build --all --no-default-features --features unix --release && strip target/release/dijo
76 76
77 - name: Upload binaries to release 77 - name: Upload binaries to release
78 uses: svenstaro/upload-release-action@v1-release 78 uses: svenstaro/upload-release-action@v1-release
@@ -82,3 +82,38 @@ jobs:
82 asset_name: dijo-x86_64-apple 82 asset_name: dijo-x86_64-apple
83 tag: ${{ github.ref }} 83 tag: ${{ github.ref }}
84 overwrite: true 84 overwrite: true
85
86 build-windows:
87 runs-on: windows-latest
88
89 steps:
90 - name: Checkout
91 uses: actions/checkout@v1
92 - name: Cache Rust dependencies
93 uses: actions/[email protected]
94 with:
95 path: target
96 key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
97 restore-keys: |
98 ${{ runner.OS }}-build-
99 - name: Install latest rust toolchain
100 uses: actions-rs/toolchain@v1
101 with:
102 toolchain: beta
103 target: x86_64-pc-windows-msvc
104 default: true
105 override: true
106
107 - name: Build for windows
108 run: |
109 cargo build --all --no-default-features --features windows --release
110 strip target/release/dijo
111
112 - name: Upload binaries to release
113 uses: svenstaro/upload-release-action@v1-release
114 with:
115 repo_token: ${{ secrets.GITHUB_TOKEN }}
116 file: target/release/dijo
117 asset_name: dijo-x86_64-windows
118 tag: ${{ github.ref }}
119 overwrite: true
diff --git a/Cargo.lock b/Cargo.lock
index bda3c1e..0488f71 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -125,6 +125,15 @@ dependencies = [
125] 125]
126 126
127[[package]] 127[[package]]
128name = "cloudabi"
129version = "0.0.3"
130source = "registry+https://github.com/rust-lang/crates.io-index"
131checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
132dependencies = [
133 "bitflags",
134]
135
136[[package]]
128name = "const-random" 137name = "const-random"
129version = "0.1.8" 138version = "0.1.8"
130source = "registry+https://github.com/rust-lang/crates.io-index" 139source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -152,12 +161,12 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
152 161
153[[package]] 162[[package]]
154name = "crossbeam-channel" 163name = "crossbeam-channel"
155version = "0.4.2" 164version = "0.4.3"
156source = "registry+https://github.com/rust-lang/crates.io-index" 165source = "registry+https://github.com/rust-lang/crates.io-index"
157checksum = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061" 166checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6"
158dependencies = [ 167dependencies = [
168 "cfg-if",
159 "crossbeam-utils", 169 "crossbeam-utils",
160 "maybe-uninit",
161] 170]
162 171
163[[package]] 172[[package]]
@@ -172,6 +181,31 @@ dependencies = [
172] 181]
173 182
174[[package]] 183[[package]]
184name = "crossterm"
185version = "0.17.7"
186source = "registry+https://github.com/rust-lang/crates.io-index"
187checksum = "6f4919d60f26ae233e14233cc39746c8c8bb8cd7b05840ace83604917b51b6c7"
188dependencies = [
189 "bitflags",
190 "crossterm_winapi",
191 "lazy_static",
192 "libc",
193 "mio 0.7.0",
194 "parking_lot",
195 "signal-hook",
196 "winapi 0.3.9",
197]
198
199[[package]]
200name = "crossterm_winapi"
201version = "0.6.1"
202source = "registry+https://github.com/rust-lang/crates.io-index"
203checksum = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c"
204dependencies = [
205 "winapi 0.3.9",
206]
207
208[[package]]
175name = "ctor" 209name = "ctor"
176version = "0.1.15" 210version = "0.1.15"
177source = "registry+https://github.com/rust-lang/crates.io-index" 211source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -190,6 +224,7 @@ dependencies = [
190 "ahash 0.3.8", 224 "ahash 0.3.8",
191 "cfg-if", 225 "cfg-if",
192 "crossbeam-channel", 226 "crossbeam-channel",
227 "crossterm",
193 "cursive_core", 228 "cursive_core",
194 "enumset", 229 "enumset",
195 "lazy_static", 230 "lazy_static",
@@ -260,7 +295,7 @@ dependencies = [
260 295
261[[package]] 296[[package]]
262name = "dijo" 297name = "dijo"
263version = "0.1.5" 298version = "0.2.1"
264dependencies = [ 299dependencies = [
265 "chrono", 300 "chrono",
266 "clap", 301 "clap",
@@ -522,6 +557,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
522checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" 557checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
523 558
524[[package]] 559[[package]]
560name = "lock_api"
561version = "0.3.4"
562source = "registry+https://github.com/rust-lang/crates.io-index"
563checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
564dependencies = [
565 "scopeguard",
566]
567
568[[package]]
525name = "log" 569name = "log"
526version = "0.4.11" 570version = "0.4.11"
527source = "registry+https://github.com/rust-lang/crates.io-index" 571source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -531,12 +575,6 @@ dependencies = [
531] 575]
532 576
533[[package]] 577[[package]]
534name = "maybe-uninit"
535version = "2.0.0"
536source = "registry+https://github.com/rust-lang/crates.io-index"
537checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
538
539[[package]]
540name = "mio" 578name = "mio"
541version = "0.6.22" 579version = "0.6.22"
542source = "registry+https://github.com/rust-lang/crates.io-index" 580source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -549,13 +587,27 @@ dependencies = [
549 "kernel32-sys", 587 "kernel32-sys",
550 "libc", 588 "libc",
551 "log", 589 "log",
552 "miow", 590 "miow 0.2.1",
553 "net2", 591 "net2",
554 "slab", 592 "slab",
555 "winapi 0.2.8", 593 "winapi 0.2.8",
556] 594]
557 595
558[[package]] 596[[package]]
597name = "mio"
598version = "0.7.0"
599source = "registry+https://github.com/rust-lang/crates.io-index"
600checksum = "6e9971bc8349a361217a8f2a41f5d011274686bd4436465ba51730921039d7fb"
601dependencies = [
602 "lazy_static",
603 "libc",
604 "log",
605 "miow 0.3.5",
606 "ntapi",
607 "winapi 0.3.9",
608]
609
610[[package]]
559name = "mio-extras" 611name = "mio-extras"
560version = "2.0.6" 612version = "2.0.6"
561source = "registry+https://github.com/rust-lang/crates.io-index" 613source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -563,7 +615,7 @@ checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
563dependencies = [ 615dependencies = [
564 "lazycell", 616 "lazycell",
565 "log", 617 "log",
566 "mio", 618 "mio 0.6.22",
567 "slab", 619 "slab",
568] 620]
569 621
@@ -580,6 +632,16 @@ dependencies = [
580] 632]
581 633
582[[package]] 634[[package]]
635name = "miow"
636version = "0.3.5"
637source = "registry+https://github.com/rust-lang/crates.io-index"
638checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e"
639dependencies = [
640 "socket2",
641 "winapi 0.3.9",
642]
643
644[[package]]
583name = "net2" 645name = "net2"
584version = "0.2.34" 646version = "0.2.34"
585source = "registry+https://github.com/rust-lang/crates.io-index" 647source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -602,13 +664,22 @@ dependencies = [
602 "fsevent-sys", 664 "fsevent-sys",
603 "inotify", 665 "inotify",
604 "libc", 666 "libc",
605 "mio", 667 "mio 0.6.22",
606 "mio-extras", 668 "mio-extras",
607 "walkdir", 669 "walkdir",
608 "winapi 0.3.9", 670 "winapi 0.3.9",
609] 671]
610 672
611[[package]] 673[[package]]
674name = "ntapi"
675version = "0.3.4"
676source = "registry+https://github.com/rust-lang/crates.io-index"
677checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2"
678dependencies = [
679 "winapi 0.3.9",
680]
681
682[[package]]
612name = "num" 683name = "num"
613version = "0.3.0" 684version = "0.3.0"
614source = "registry+https://github.com/rust-lang/crates.io-index" 685source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -687,6 +758,30 @@ dependencies = [
687] 758]
688 759
689[[package]] 760[[package]]
761name = "parking_lot"
762version = "0.10.2"
763source = "registry+https://github.com/rust-lang/crates.io-index"
764checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
765dependencies = [
766 "lock_api",
767 "parking_lot_core",
768]
769
770[[package]]
771name = "parking_lot_core"
772version = "0.7.2"
773source = "registry+https://github.com/rust-lang/crates.io-index"
774checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
775dependencies = [
776 "cfg-if",
777 "cloudabi",
778 "libc",
779 "redox_syscall",
780 "smallvec",
781 "winapi 0.3.9",
782]
783
784[[package]]
690name = "proc-macro-hack" 785name = "proc-macro-hack"
691version = "0.5.16" 786version = "0.5.16"
692source = "registry+https://github.com/rust-lang/crates.io-index" 787source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -694,9 +789,9 @@ checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
694 789
695[[package]] 790[[package]]
696name = "proc-macro2" 791name = "proc-macro2"
697version = "1.0.18" 792version = "1.0.19"
698source = "registry+https://github.com/rust-lang/crates.io-index" 793source = "registry+https://github.com/rust-lang/crates.io-index"
699checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" 794checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
700dependencies = [ 795dependencies = [
701 "unicode-xid", 796 "unicode-xid",
702] 797]
@@ -764,6 +859,12 @@ dependencies = [
764] 859]
765 860
766[[package]] 861[[package]]
862name = "scopeguard"
863version = "1.1.0"
864source = "registry+https://github.com/rust-lang/crates.io-index"
865checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
866
867[[package]]
767name = "serde" 868name = "serde"
768version = "1.0.114" 869version = "1.0.114"
769source = "registry+https://github.com/rust-lang/crates.io-index" 870source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -801,6 +902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
801checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed" 902checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed"
802dependencies = [ 903dependencies = [
803 "libc", 904 "libc",
905 "mio 0.7.0",
804 "signal-hook-registry", 906 "signal-hook-registry",
805] 907]
806 908
@@ -821,6 +923,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
821checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" 923checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
822 924
823[[package]] 925[[package]]
926name = "smallvec"
927version = "1.4.1"
928source = "registry+https://github.com/rust-lang/crates.io-index"
929checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
930
931[[package]]
932name = "socket2"
933version = "0.3.12"
934source = "registry+https://github.com/rust-lang/crates.io-index"
935checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918"
936dependencies = [
937 "cfg-if",
938 "libc",
939 "redox_syscall",
940 "winapi 0.3.9",
941]
942
943[[package]]
824name = "stable_deref_trait" 944name = "stable_deref_trait"
825version = "1.2.0" 945version = "1.2.0"
826source = "registry+https://github.com/rust-lang/crates.io-index" 946source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -840,9 +960,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
840 960
841[[package]] 961[[package]]
842name = "syn" 962name = "syn"
843version = "1.0.34" 963version = "1.0.35"
844source = "registry+https://github.com/rust-lang/crates.io-index" 964source = "registry+https://github.com/rust-lang/crates.io-index"
845checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" 965checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0"
846dependencies = [ 966dependencies = [
847 "proc-macro2", 967 "proc-macro2",
848 "quote", 968 "quote",
diff --git a/Cargo.toml b/Cargo.toml
index 3f297b8..6443a4b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "dijo" 2name = "dijo"
3version = "0.1.5" 3version = "0.2.1"
4authors = ["Akshay <[email protected]>"] 4authors = ["Akshay <[email protected]>"]
5edition = "2018" 5edition = "2018"
6description = "Scriptable, curses-based, digital habit tracker" 6description = "Scriptable, curses-based, digital habit tracker"
@@ -23,7 +23,10 @@ notify = "4.0"
23[dependencies.cursive] 23[dependencies.cursive]
24version = "0.15" 24version = "0.15"
25default-features = false 25default-features = false
26features = ["termion-backend"] 26
27[features]
28unix = ["cursive/termion-backend"]
29windows = ["cursive/crossterm-backend"]
27 30
28[dependencies.chrono] 31[dependencies.chrono]
29version = "0.4" 32version = "0.4"
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index cf0e97f..a806dc5 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -128,7 +128,7 @@ impl App {
128 let completed = total - remaining; 128 let completed = total - remaining;
129 129
130 let timestamp = if self.view_month_offset == 0 { 130 let timestamp = if self.view_month_offset == 0 {
131 format!("{}", Local::now().date().format("%d/%b/%y"),) 131 format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),)
132 } else { 132 } else {
133 let months = self.view_month_offset; 133 let months = self.view_month_offset;
134 format!("{}", format!("{} months ago", months),) 134 format!("{}", format!("{} months ago", months),)
@@ -217,6 +217,12 @@ impl App {
217 match result { 217 match result {
218 Ok(c) => match c { 218 Ok(c) => match c {
219 Command::Add(name, goal, auto) => { 219 Command::Add(name, goal, auto) => {
220 if let Some(_) = self.habits.iter().find(|x| x.name() == name) {
221 self.message.set_kind(MessageKind::Error);
222 self.message
223 .set_message(format!("Habit `{}` already exist", &name));
224 return;
225 }
220 let kind = if goal == Some(1) { "bit" } else { "count" }; 226 let kind = if goal == Some(1) { "bit" } else { "count" };
221 if kind == "count" { 227 if kind == "count" {
222 self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); 228 self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto)));
diff --git a/src/command.rs b/src/command.rs
index a893430..ae5be66 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -61,8 +61,7 @@ pub fn open_command_window(s: &mut Cursive) {
61 let completion = get_habit_completion(word, &habit_list); 61 let completion = get_habit_completion(word, &habit_list);
62 eprintln!("{:?} | {:?}", completion, contents); 62 eprintln!("{:?} | {:?}", completion, contents);
63 if let Some(c) = completion { 63 if let Some(c) = completion {
64 let cb = 64 let cb = view.set_content(format!("{}", contents) + &c[word.len()..]);
65 view.set_content(format!("{}", contents) + c.strip_prefix(word).unwrap());
66 return Some(EventResult::Consumed(Some(cb))); 65 return Some(EventResult::Consumed(Some(cb)));
67 }; 66 };
68 return None; 67 return None;
diff --git a/src/main.rs b/src/main.rs
index d96119e..609738e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,7 +12,13 @@ use crate::command::{open_command_window, Command};
12use crate::utils::{load_configuration_file, AppConfig}; 12use crate::utils::{load_configuration_file, AppConfig};
13 13
14use clap::{App as ClapApp, Arg}; 14use clap::{App as ClapApp, Arg};
15
16#[cfg(any(target_os = "linux", target_os = "macos"))]
15use cursive::termion; 17use cursive::termion;
18
19#[cfg(target_os = "windows")]
20use cursive::crossterm;
21
16use cursive::views::{LinearLayout, NamedView}; 22use cursive::views::{LinearLayout, NamedView};
17use lazy_static::lazy_static; 23use lazy_static::lazy_static;
18 24
@@ -33,6 +39,14 @@ fn main() {
33 .value_name("CMD") 39 .value_name("CMD")
34 .help("run a dijo command"), 40 .help("run a dijo command"),
35 ) 41 )
42 .arg(
43 Arg::with_name("list")
44 .short("l")
45 .long("list")
46 .takes_value(false)
47 .help("list dijo habits")
48 .conflicts_with("command"),
49 )
36 .get_matches(); 50 .get_matches();
37 if let Some(c) = matches.value_of("command") { 51 if let Some(c) = matches.value_of("command") {
38 let command = Command::from_string(c); 52 let command = Command::from_string(c);
@@ -49,8 +63,17 @@ fn main() {
49 "Commands other than `track-up` and `track-down` are currently not supported!" 63 "Commands other than `track-up` and `track-down` are currently not supported!"
50 ), 64 ),
51 } 65 }
66 } else if matches.is_present("list") {
67 for h in App::load_state().list_habits() {
68 println!("{}", h);
69 }
52 } else { 70 } else {
71 #[cfg(target_os = "windows")]
72 let mut s = crossterm().unwrap();
73
74 #[cfg(any(target_os = "linux", target_os = "macos"))]
53 let mut s = termion().unwrap(); 75 let mut s = termion().unwrap();
76
54 let app = App::load_state(); 77 let app = App::load_state();
55 let layout = NamedView::new( 78 let layout = NamedView::new(
56 "Frame", 79 "Frame",