aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornc <[email protected]>2020-08-06 04:56:06 +0100
committernc <[email protected]>2020-08-06 04:56:06 +0100
commit976ea0282d373c4d08187a78a7b46a09d66f7918 (patch)
tree6d613a1b59ca277a82c8a688ec029774d10f31d5 /src
parentee9be05579d87ca99f153d20995af3273385b564 (diff)
revert
Diffstat (limited to 'src')
-rw-r--r--src/app/impl_self.rs11
-rw-r--r--src/app/impl_view.rs13
-rw-r--r--src/app/mod.rs4
-rw-r--r--src/main.rs4
4 files changed, 10 insertions, 22 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index c2a24cf..744f906 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -5,7 +5,6 @@ use std::io::prelude::*;
5use std::path::PathBuf; 5use std::path::PathBuf;
6use std::sync::mpsc::channel; 6use std::sync::mpsc::channel;
7use std::time::Duration; 7use std::time::Duration;
8use std::sync::{RwLock, Arc};
9 8
10use chrono::Local; 9use chrono::Local;
11use cursive::direction::Absolute; 10use cursive::direction::Absolute;
@@ -30,7 +29,7 @@ impl App {
30 _file_watcher: watcher, 29 _file_watcher: watcher,
31 file_event_recv: rx, 30 file_event_recv: rx,
32 view_month_offset: 0, 31 view_month_offset: 0,
33 message: Arc::new(RwLock::new("Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into())), 32 message: "Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into(),
34 }; 33 };
35 } 34 }
36 35
@@ -42,7 +41,7 @@ impl App {
42 let old_len = self.habits.len(); 41 let old_len = self.habits.len();
43 self.habits.retain(|h| h.name() != name); 42 self.habits.retain(|h| h.name() != name);
44 if old_len == self.habits.len() { 43 if old_len == self.habits.len() {
45 self.message.write().unwrap() 44 self.message
46 .set_message(format!("Could not delete habit `{}`", name)) 45 .set_message(format!("Could not delete habit `{}`", name))
47 } 46 }
48 } 47 }
@@ -115,7 +114,7 @@ impl App {
115 } 114 }
116 115
117 pub fn clear_message(&mut self) { 116 pub fn clear_message(&mut self) {
118 self.message.write().unwrap().clear(); 117 self.message.clear();
119 } 118 }
120 119
121 pub fn status(&self) -> StatusLine { 120 pub fn status(&self) -> StatusLine {
@@ -237,8 +236,8 @@ impl App {
237 Command::Blank => {} 236 Command::Blank => {}
238 }, 237 },
239 Err(e) => { 238 Err(e) => {
240 self.message.write().unwrap().set_message(e.to_string()); 239 self.message.set_message(e.to_string());
241 self.message.write().unwrap().set_kind(MessageKind::Error); 240 self.message.set_kind(MessageKind::Error);
242 } 241 }
243 } 242 }
244 } 243 }
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs
index 1261208..892b00c 100644
--- a/src/app/impl_view.rs
+++ b/src/app/impl_view.rs
@@ -39,8 +39,8 @@ impl View for App {
39 printer.print(offset, &status.1); // right status 39 printer.print(offset, &status.1); // right status
40 40
41 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 1); 41 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 1);
42 printer.with_style(Color::from(self.message.read().unwrap().kind()), |p| { 42 printer.with_style(Color::from(self.message.kind()), |p| {
43 p.print(offset, self.message.read().unwrap().contents()) 43 p.print(offset, self.message.contents())
44 }); 44 });
45 } 45 }
46 46
@@ -85,7 +85,6 @@ impl View for App {
85 if self.habits.is_empty() { 85 if self.habits.is_empty() {
86 return EventResult::Ignored; 86 return EventResult::Ignored;
87 } 87 }
88 let m = self.message.clone();
89 match e { 88 match e {
90 Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { 89 Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => {
91 self.set_focus(Absolute::Right); 90 self.set_focus(Absolute::Right);
@@ -162,12 +161,8 @@ impl View for App {
162 return EventResult::Consumed(None); 161 return EventResult::Consumed(None);
163 } 162 }
164 Event::CtrlChar('l') => { 163 Event::CtrlChar('l') => {
165 self.message.write().unwrap().clear(); 164 self.message.clear();
166 self.message.write().unwrap().set_kind(MessageKind::Info); 165 self.message.set_kind(MessageKind::Info);
167 return EventResult::Consumed(None);
168 }
169 Event::CtrlChar('c') => {
170 m.write().unwrap().set_message("Use the :q command to quit");
171 return EventResult::Consumed(None); 166 return EventResult::Consumed(None);
172 } 167 }
173 168
diff --git a/src/app/mod.rs b/src/app/mod.rs
index bce6e79..2aecb33 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -5,8 +5,6 @@ use notify::{DebouncedEvent, RecommendedWatcher};
5 5
6use crate::habit::HabitWrapper; 6use crate::habit::HabitWrapper;
7 7
8use std::sync::{RwLock, Arc};
9
10mod impl_self; 8mod impl_self;
11mod impl_view; 9mod impl_view;
12mod message; 10mod message;
@@ -22,7 +20,7 @@ pub struct App {
22 file_event_recv: Receiver<DebouncedEvent>, 20 file_event_recv: Receiver<DebouncedEvent>,
23 focus: usize, 21 focus: usize,
24 view_month_offset: u32, 22 view_month_offset: u32,
25 pub message: Arc<RwLock<Message>>, 23 message: Message,
26} 24}
27 25
28impl Default for App { 26impl Default for App {
diff --git a/src/main.rs b/src/main.rs
index 3ec964a..d96119e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,10 +52,6 @@ fn main() {
52 } else { 52 } else {
53 let mut s = termion().unwrap(); 53 let mut s = termion().unwrap();
54 let app = App::load_state(); 54 let app = App::load_state();
55
56 // prevent Ctrl-C from killing the app and allow the app to override it.
57 s.clear_global_callbacks(cursive::event::Event::CtrlChar('c'));
58
59 let layout = NamedView::new( 55 let layout = NamedView::new(
60 "Frame", 56 "Frame",
61 LinearLayout::vertical().child(NamedView::new("Main", app)), 57 LinearLayout::vertical().child(NamedView::new("Main", app)),