From 976ea0282d373c4d08187a78a7b46a09d66f7918 Mon Sep 17 00:00:00 2001 From: nc Date: Wed, 5 Aug 2020 23:56:06 -0400 Subject: revert --- src/app/impl_self.rs | 11 +++++------ src/app/impl_view.rs | 13 ++++--------- src/app/mod.rs | 4 +--- src/main.rs | 4 ---- 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::*; use std::path::PathBuf; use std::sync::mpsc::channel; use std::time::Duration; -use std::sync::{RwLock, Arc}; use chrono::Local; use cursive::direction::Absolute; @@ -30,7 +29,7 @@ impl App { _file_watcher: watcher, file_event_recv: rx, view_month_offset: 0, - message: Arc::new(RwLock::new("Type :add to get started, Ctrl-L to dismiss".into())), + message: "Type :add to get started, Ctrl-L to dismiss".into(), }; } @@ -42,7 +41,7 @@ impl App { let old_len = self.habits.len(); self.habits.retain(|h| h.name() != name); if old_len == self.habits.len() { - self.message.write().unwrap() + self.message .set_message(format!("Could not delete habit `{}`", name)) } } @@ -115,7 +114,7 @@ impl App { } pub fn clear_message(&mut self) { - self.message.write().unwrap().clear(); + self.message.clear(); } pub fn status(&self) -> StatusLine { @@ -237,8 +236,8 @@ impl App { Command::Blank => {} }, Err(e) => { - self.message.write().unwrap().set_message(e.to_string()); - self.message.write().unwrap().set_kind(MessageKind::Error); + self.message.set_message(e.to_string()); + self.message.set_kind(MessageKind::Error); } } } 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 { printer.print(offset, &status.1); // right status offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 1); - printer.with_style(Color::from(self.message.read().unwrap().kind()), |p| { - p.print(offset, self.message.read().unwrap().contents()) + printer.with_style(Color::from(self.message.kind()), |p| { + p.print(offset, self.message.contents()) }); } @@ -85,7 +85,6 @@ impl View for App { if self.habits.is_empty() { return EventResult::Ignored; } - let m = self.message.clone(); match e { Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { self.set_focus(Absolute::Right); @@ -162,12 +161,8 @@ impl View for App { return EventResult::Consumed(None); } Event::CtrlChar('l') => { - self.message.write().unwrap().clear(); - self.message.write().unwrap().set_kind(MessageKind::Info); - return EventResult::Consumed(None); - } - Event::CtrlChar('c') => { - m.write().unwrap().set_message("Use the :q command to quit"); + self.message.clear(); + self.message.set_kind(MessageKind::Info); return EventResult::Consumed(None); } 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}; use crate::habit::HabitWrapper; -use std::sync::{RwLock, Arc}; - mod impl_self; mod impl_view; mod message; @@ -22,7 +20,7 @@ pub struct App { file_event_recv: Receiver, focus: usize, view_month_offset: u32, - pub message: Arc>, + message: Message, } impl 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() { } else { let mut s = termion().unwrap(); let app = App::load_state(); - - // prevent Ctrl-C from killing the app and allow the app to override it. - s.clear_global_callbacks(cursive::event::Event::CtrlChar('c')); - let layout = NamedView::new( "Frame", LinearLayout::vertical().child(NamedView::new("Main", app)), -- cgit v1.2.3