summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkshay <nerdy@peppe.rs>2020-07-19 14:56:39 +0530
committerAkshay <nerdy@peppe.rs>2020-07-19 14:56:39 +0530
commit8a1dd86155823455e71ca0f73673214073a8a269 (patch)
tree41ecaffa397d4f86bb55d57b266dd6a65e19f2e0
parent9c858841c7566e79c0e05a6295e5f9bc86468d16 (diff)
add startup hint, fix watcher panics
-rw-r--r--Cargo.toml2
-rw-r--r--src/app/impl_self.rs20
-rw-r--r--src/app/impl_view.rs16
-rw-r--r--src/app/message.rs12
-rw-r--r--src/theme.rs2
5 files changed, 24 insertions, 28 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 4333b9b..4791c0b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,8 +11,6 @@ keywords = ["tracker", "event-tracker", "tui", "journal"]
categories = ["date-and-time", "command-line-interface"]
license = "MIT"
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
[dependencies]
serde_json = "1.0"
lazy_static = "1.4.0"
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index 2b115a0..744f906 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -16,24 +16,20 @@ use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode};
use crate::utils;
use crate::CONFIGURATION;
-use crate::app::{App, Message, MessageKind, StatusLine};
+use crate::app::{App, MessageKind, StatusLine};
impl App {
pub fn new() -> Self {
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap();
- watcher
- .watch(utils::auto_habit_file(), RecursiveMode::Recursive)
- .unwrap_or_else(|e| {
- panic!("Unable to start file watcher: {}", e);
- });
+ watcher.watch(utils::auto_habit_file(), RecursiveMode::Recursive);
return App {
habits: vec![],
focus: 0,
_file_watcher: watcher,
file_event_recv: rx,
view_month_offset: 0,
- message: Message::default(),
+ message: "Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into(),
};
}
@@ -147,15 +143,9 @@ impl App {
pub fn max_size(&self) -> Vec2 {
let grid_width = CONFIGURATION.grid_width;
- let width = {
- if self.habits.len() > 0 {
- grid_width * CONFIGURATION.view_width
- } else {
- 0
- }
- };
+ let width = grid_width * CONFIGURATION.view_width;
let height = {
- if self.habits.len() > 0 {
+ if !self.habits.is_empty() {
(CONFIGURATION.view_height as f64
* (self.habits.len() as f64 / grid_width as f64).ceil())
as usize
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs
index 0a6bce6..892b00c 100644
--- a/src/app/impl_view.rs
+++ b/src/app/impl_view.rs
@@ -5,7 +5,7 @@ use std::path::PathBuf;
use cursive::direction::{Absolute, Direction};
use cursive::event::{Event, EventResult, Key};
-use cursive::theme::{Color, Style};
+use cursive::theme::Color;
use cursive::view::View;
use cursive::{Printer, Vec2};
use notify::DebouncedEvent;
@@ -48,23 +48,16 @@ impl View for App {
let grid_width = CONFIGURATION.grid_width;
let view_width = CONFIGURATION.view_width;
let view_height = CONFIGURATION.view_height;
- let width = {
- if self.habits.len() > 0 {
- grid_width * (view_width + 2)
- } else {
- 0
- }
- };
+ let width = grid_width * (view_width + 2);
let height = {
if self.habits.len() > 0 {
(view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil())
as usize
- + 2 // to acoomodate statusline and message line
} else {
0
}
};
- Vec2::new(width, height)
+ Vec2::new(width, height + 2)
}
fn take_focus(&mut self, _: Direction) -> bool {
@@ -89,6 +82,9 @@ impl View for App {
}
_ => {}
};
+ if self.habits.is_empty() {
+ return EventResult::Ignored;
+ }
match e {
Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => {
self.set_focus(Absolute::Right);
diff --git a/src/app/message.rs b/src/app/message.rs
index 34d3293..65f0a5c 100644
--- a/src/app/message.rs
+++ b/src/app/message.rs
@@ -17,6 +17,18 @@ impl From<MessageKind> for Color {
}
}
+impl<T> From<T> for Message
+where
+ T: AsRef<str>,
+{
+ fn from(item: T) -> Self {
+ return Message {
+ msg: item.as_ref().to_string(),
+ kind: MessageKind::Info,
+ };
+ }
+}
+
pub struct Message {
msg: String,
kind: MessageKind,
diff --git a/src/theme.rs b/src/theme.rs
index f29b273..4194777 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -1,6 +1,6 @@
use cursive::theme::Color::*;
use cursive::theme::PaletteColor::*;
-use cursive::theme::{BaseColor, BorderStyle, ColorStyle, Palette, Theme};
+use cursive::theme::{BaseColor, BorderStyle, Palette, Theme};
pub fn pallete_gen() -> Palette {
let mut p = Palette::default();