summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoronielfa <onielfadev@gmail.com>2020-07-24 00:56:38 +0200
committeronielfa <onielfadev@gmail.com>2020-07-24 00:56:38 +0200
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:
&& sudo apt-get install -y \
libdbus-1-dev
- name: Build
- run: cargo build --all --release && strip target/release/dijo
+ run: cargo build -all --no-default-features --features unix --release && strip target/release/dijo
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v1-release
@@ -72,7 +72,7 @@ jobs:
override: true
- name: Build for mac
- run: cargo build --all --release && strip target/release/dijo
+ run: cargo build --all --no-default-features --features unix --release && strip target/release/dijo
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v1-release
@@ -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 --no-default-features --features windows --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
diff --git a/Cargo.lock b/Cargo.lock
index bda3c1e..0488f71 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -125,6 +125,15 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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]]
@@ -172,6 +181,31 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -190,6 +224,7 @@ dependencies = [
"ahash 0.3.8",
"cfg-if",
"crossbeam-channel",
+ "crossterm",
"cursive_core",
"enumset",
"lazy_static",
@@ -260,7 +295,7 @@ dependencies = [
[[package]]
name = "dijo"
-version = "0.1.5"
+version = "0.2.1"
dependencies = [
"chrono",
"clap",
@@ -522,6 +557,15 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -531,12 +575,6 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -549,13 +587,27 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -563,7 +615,7 @@ checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
dependencies = [
"lazycell",
"log",
- "mio",
+ "mio 0.6.22",
"slab",
]
@@ -580,6 +632,16 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -602,13 +664,22 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -687,6 +758,30 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -694,9 +789,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",
]
@@ -764,6 +859,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -801,6 +902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed"
dependencies = [
"libc",
+ "mio 0.7.0",
"signal-hook-registry",
]
@@ -821,6 +923,24 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -840,9 +960,9 @@ 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",
diff --git a/Cargo.toml b/Cargo.toml
index 3f297b8..6443a4b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "dijo"
-version = "0.1.5"
+version = "0.2.1"
authors = ["Akshay <nerdy@peppe.rs>"]
edition = "2018"
description = "Scriptable, curses-based, digital habit tracker"
@@ -23,7 +23,10 @@ notify = "4.0"
[dependencies.cursive]
version = "0.15"
default-features = false
-features = ["termion-backend"]
+
+[features]
+unix = ["cursive/termion-backend"]
+windows = ["cursive/crossterm-backend"]
[dependencies.chrono]
version = "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 {
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),)
@@ -217,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/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) {
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());
+ let cb = view.set_content(format!("{}", contents) + &c[word.len()..]);
return Some(EventResult::Consumed(Some(cb)));
};
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};
use crate::utils::{load_configuration_file, AppConfig};
use clap::{App as ClapApp, Arg};
+
+#[cfg(any(target_os = "linux", target_os = "macos"))]
use cursive::termion;
+
+#[cfg(target_os = "windows")]
+use cursive::crossterm;
+
use cursive::views::{LinearLayout, NamedView};
use lazy_static::lazy_static;
@@ -33,6 +39,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,8 +63,17 @@ fn main() {
"Commands other than `track-up` and `track-down` are currently not supported!"
),
}
+ } else if matches.is_present("list") {
+ for h in App::load_state().list_habits() {
+ println!("{}", h);
+ }
} else {
+ #[cfg(target_os = "windows")]
+ let mut s = crossterm().unwrap();
+
+ #[cfg(any(target_os = "linux", target_os = "macos"))]
let mut s = termion().unwrap();
+
let app = App::load_state();
let layout = NamedView::new(
"Frame",