summaryrefslogtreecommitdiffstats
path: root/src/app/impl_self.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r--src/app/impl_self.rs42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index abf5209..d5f93ff 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -6,7 +6,7 @@ use std::path::PathBuf;
use std::sync::mpsc::channel;
use std::time::Duration;
-use chrono::Local;
+use chrono::{Local, NaiveDate};
use cursive::direction::Absolute;
use cursive::Vec2;
use notify::{watcher, RecursiveMode, Watcher};
@@ -27,7 +27,6 @@ impl App {
focus: 0,
_file_watcher: watcher,
file_event_recv: rx,
- view_month_offset: 0,
cursor: Cursor::new(),
message: Message::startup(),
};
@@ -54,42 +53,42 @@ impl App {
if self.habits.is_empty() {
return ViewMode::Day;
}
- return self.habits[self.focus].view_mode();
+ return self.habits[self.focus].inner_data_ref().view_mode();
}
pub fn set_mode(&mut self, mode: ViewMode) {
if !self.habits.is_empty() {
- self.habits[self.focus].set_view_mode(mode);
+ self.habits[self.focus]
+ .inner_data_mut_ref()
+ .set_view_mode(mode);
}
}
- pub fn set_view_month_offset(&mut self, offset: u32) {
- self.view_month_offset = offset;
+ pub fn sift_backward(&mut self) {
+ self.cursor.month_backward();
for v in self.habits.iter_mut() {
- v.set_view_month_offset(offset);
+ v.inner_data_mut_ref().cursor.month_backward();
}
}
- pub fn sift_backward(&mut self) {
- self.view_month_offset += 1;
+ pub fn sift_forward(&mut self) {
+ self.cursor.month_forward();
for v in self.habits.iter_mut() {
- v.set_view_month_offset(self.view_month_offset);
+ v.inner_data_mut_ref().cursor.month_forward();
}
}
- pub fn sift_forward(&mut self) {
- if self.view_month_offset > 0 {
- self.view_month_offset -= 1;
- for v in self.habits.iter_mut() {
- v.set_view_month_offset(self.view_month_offset);
- }
+ pub fn reset_cursor(&mut self) {
+ self.cursor.reset();
+ for v in self.habits.iter_mut() {
+ v.inner_data_mut_ref().cursor.reset();
}
}
pub fn move_cursor(&mut self, d: Absolute) {
- self.cursor.do_move(d);
+ self.cursor.small_seek(d);
for v in self.habits.iter_mut() {
- v.move_cursor(d);
+ v.inner_data_mut_ref().move_cursor(d);
}
}
@@ -133,11 +132,12 @@ impl App {
let total = self.habits.iter().map(|h| h.goal()).sum::<u32>();
let completed = total - remaining;
- let timestamp = if self.view_month_offset == 0 {
+ let timestamp = if self.cursor.0 == today {
format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),)
} else {
- let months = self.view_month_offset;
- format!("{}", format!("{} month(s) ago", months),)
+ let since = NaiveDate::signed_duration_since(today, self.cursor.0).num_days();
+ let plural = if since == 1 { "" } else { "s" };
+ format!("{} ({} day{} ago)", self.cursor.0, since, plural)
};
StatusLine {