mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 03:07:18 +02:00
Add force option to update
This commit is contained in:
parent
c133206990
commit
b5fb8f3dae
2 changed files with 35 additions and 35 deletions
68
src/app.rs
68
src/app.rs
|
@ -187,7 +187,7 @@ impl TTApp {
|
||||||
app.filter.insert(c, 1);
|
app.filter.insert(c, 1);
|
||||||
}
|
}
|
||||||
app.get_context()?;
|
app.get_context()?;
|
||||||
app.update()?;
|
app.update(true)?;
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,8 +755,8 @@ impl TTApp {
|
||||||
(tasks, headers)
|
(tasks, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) -> Result<(), Box<dyn Error>> {
|
pub fn update(&mut self, force: bool) -> Result<(), Box<dyn Error>> {
|
||||||
if self.tasks_changed_since(self.last_export)? {
|
if force || self.tasks_changed_since(self.last_export)? {
|
||||||
self.last_export = Some(std::time::SystemTime::now());
|
self.last_export = Some(std::time::SystemTime::now());
|
||||||
self.task_report_table.export_headers()?;
|
self.task_report_table.export_headers()?;
|
||||||
let _ = self.export_tasks();
|
let _ = self.export_tasks();
|
||||||
|
@ -1467,7 +1467,7 @@ impl TTApp {
|
||||||
match self.mode {
|
match self.mode {
|
||||||
AppMode::TaskReport => match input {
|
AppMode::TaskReport => match input {
|
||||||
Key::Ctrl('c') | Key::Char('q') => self.should_quit = true,
|
Key::Ctrl('c') | Key::Char('q') => self.should_quit = true,
|
||||||
Key::Char('r') => self.update()?,
|
Key::Char('r') => self.update(true)?,
|
||||||
Key::End | Key::Char('G') => self.task_report_bottom(),
|
Key::End | Key::Char('G') => self.task_report_bottom(),
|
||||||
Key::Home => self.task_report_top(),
|
Key::Home => self.task_report_top(),
|
||||||
Key::Char('g') => {
|
Key::Char('g') => {
|
||||||
|
@ -1480,28 +1480,28 @@ impl TTApp {
|
||||||
Key::PageDown | Key::Char('J') => self.task_report_next_page(),
|
Key::PageDown | Key::Char('J') => self.task_report_next_page(),
|
||||||
Key::PageUp | Key::Char('K') => self.task_report_previous_page(),
|
Key::PageUp | Key::Char('K') => self.task_report_previous_page(),
|
||||||
Key::Char('d') => match self.task_done() {
|
Key::Char('d') => match self.task_done() {
|
||||||
Ok(_) => self.update()?,
|
Ok(_) => self.update(true)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
self.error = e;
|
self.error = e;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Key::Char('x') => match self.task_delete() {
|
Key::Char('x') => match self.task_delete() {
|
||||||
Ok(_) => self.update()?,
|
Ok(_) => self.update(true)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
self.error = e;
|
self.error = e;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Key::Char('s') => match self.task_start_or_stop() {
|
Key::Char('s') => match self.task_start_or_stop() {
|
||||||
Ok(_) => self.update()?,
|
Ok(_) => self.update(true)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
self.error = e;
|
self.error = e;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Key::Char('u') => match self.task_undo() {
|
Key::Char('u') => match self.task_undo() {
|
||||||
Ok(_) => self.update()?,
|
Ok(_) => self.update(true)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
self.error = e;
|
self.error = e;
|
||||||
|
@ -1512,7 +1512,7 @@ impl TTApp {
|
||||||
let r = self.task_edit();
|
let r = self.task_edit();
|
||||||
events.resume_key_capture(terminal);
|
events.resume_key_capture(terminal);
|
||||||
match r {
|
match r {
|
||||||
Ok(_) => self.update()?,
|
Ok(_) => self.update(true)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
self.error = e;
|
self.error = e;
|
||||||
|
@ -1590,7 +1590,7 @@ impl TTApp {
|
||||||
Key::Char('\n') => match self.task_modify() {
|
Key::Char('\n') => match self.task_modify() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.mode = AppMode::TaskReport;
|
self.mode = AppMode::TaskReport;
|
||||||
self.update()?;
|
self.update(true)?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
|
@ -1607,7 +1607,7 @@ impl TTApp {
|
||||||
Key::Char('\n') => match self.task_subprocess() {
|
Key::Char('\n') => match self.task_subprocess() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.mode = AppMode::TaskReport;
|
self.mode = AppMode::TaskReport;
|
||||||
self.update()?;
|
self.update(true)?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
|
@ -1624,7 +1624,7 @@ impl TTApp {
|
||||||
Key::Char('\n') => match self.task_log() {
|
Key::Char('\n') => match self.task_log() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.mode = AppMode::TaskReport;
|
self.mode = AppMode::TaskReport;
|
||||||
self.update()?;
|
self.update(true)?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
|
@ -1641,7 +1641,7 @@ impl TTApp {
|
||||||
Key::Char('\n') => match self.task_annotate() {
|
Key::Char('\n') => match self.task_annotate() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.mode = AppMode::TaskReport;
|
self.mode = AppMode::TaskReport;
|
||||||
self.update()?;
|
self.update(true)?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
|
@ -1658,7 +1658,7 @@ impl TTApp {
|
||||||
Key::Char('\n') => match self.task_add() {
|
Key::Char('\n') => match self.task_add() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.mode = AppMode::TaskReport;
|
self.mode = AppMode::TaskReport;
|
||||||
self.update()?;
|
self.update(true)?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskError;
|
||||||
|
@ -1674,7 +1674,7 @@ impl TTApp {
|
||||||
AppMode::TaskFilter => match input {
|
AppMode::TaskFilter => match input {
|
||||||
Key::Char('\n') | Key::Esc => {
|
Key::Char('\n') | Key::Esc => {
|
||||||
self.mode = AppMode::TaskReport;
|
self.mode = AppMode::TaskReport;
|
||||||
self.update()?;
|
self.update(true)?;
|
||||||
}
|
}
|
||||||
_ => handle_movement(&mut self.filter, input),
|
_ => handle_movement(&mut self.filter, input),
|
||||||
},
|
},
|
||||||
|
@ -1890,7 +1890,7 @@ mod tests {
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
|
|
||||||
app.context_next();
|
app.context_next();
|
||||||
app.context_select();
|
app.context_select();
|
||||||
|
@ -1904,7 +1904,7 @@ mod tests {
|
||||||
assert_eq!(app.context_table_state.selected(), Some(1));
|
assert_eq!(app.context_table_state.selected(), Some(1));
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
|
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), 1);
|
assert_eq!(app.tasks.lock().unwrap().len(), 1);
|
||||||
assert_eq!(app.current_context_filter, "+finance -private");
|
assert_eq!(app.current_context_filter, "+finance -private");
|
||||||
|
@ -1915,7 +1915,7 @@ mod tests {
|
||||||
assert_eq!(app.context_table_state.selected(), Some(0));
|
assert_eq!(app.context_table_state.selected(), Some(0));
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
|
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), 26);
|
assert_eq!(app.tasks.lock().unwrap().len(), 26);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
@ -1926,7 +1926,7 @@ mod tests {
|
||||||
|
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -1955,7 +1955,7 @@ mod tests {
|
||||||
assert_eq!(task_id, total_tasks + 1);
|
assert_eq!(task_id, total_tasks + 1);
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), (total_tasks + 1) as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), (total_tasks + 1) as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -1982,7 +1982,7 @@ mod tests {
|
||||||
|
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
}
|
}
|
||||||
|
@ -1992,7 +1992,7 @@ mod tests {
|
||||||
|
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -2021,7 +2021,7 @@ mod tests {
|
||||||
assert_eq!(task_id, total_tasks + 1);
|
assert_eq!(task_id, total_tasks + 1);
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), (total_tasks + 1) as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), (total_tasks + 1) as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -2049,7 +2049,7 @@ mod tests {
|
||||||
|
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
}
|
}
|
||||||
|
@ -2061,7 +2061,7 @@ mod tests {
|
||||||
|
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -2093,7 +2093,7 @@ mod tests {
|
||||||
assert_eq!(task_id, total_tasks + 1);
|
assert_eq!(task_id, total_tasks + 1);
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), (total_tasks + 1) as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), (total_tasks + 1) as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -2120,7 +2120,7 @@ mod tests {
|
||||||
|
|
||||||
let mut app = TTApp::new().unwrap();
|
let mut app = TTApp::new().unwrap();
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
}
|
}
|
||||||
|
@ -2135,14 +2135,14 @@ mod tests {
|
||||||
let total_tasks: u64 = 0;
|
let total_tasks: u64 = 0;
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
let now = TimeZone::from_utc_datetime(now.offset(), &now.naive_utc());
|
let now = TimeZone::from_utc_datetime(now.offset(), &now.naive_utc());
|
||||||
|
|
||||||
app.update().unwrap();
|
app.update(true).unwrap();
|
||||||
|
|
||||||
let backend = TestBackend::new(50, 15);
|
let backend = TestBackend::new(50, 15);
|
||||||
let mut terminal = Terminal::new(backend).unwrap();
|
let mut terminal = Terminal::new(backend).unwrap();
|
||||||
|
@ -2201,7 +2201,7 @@ mod tests {
|
||||||
let total_tasks: u64 = 26;
|
let total_tasks: u64 = 26;
|
||||||
|
|
||||||
assert!(app.get_context().is_ok());
|
assert!(app.get_context().is_ok());
|
||||||
assert!(app.update().is_ok());
|
assert!(app.update(true).is_ok());
|
||||||
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
assert_eq!(app.tasks.lock().unwrap().len(), total_tasks as usize);
|
||||||
assert_eq!(app.current_context_filter, "");
|
assert_eq!(app.current_context_filter, "");
|
||||||
|
|
||||||
|
@ -2246,7 +2246,7 @@ mod tests {
|
||||||
app.task_report_previous_page();
|
app.task_report_previous_page();
|
||||||
app.task_report_bottom();
|
app.task_report_bottom();
|
||||||
app.task_report_top();
|
app.task_report_top();
|
||||||
app.update().unwrap();
|
app.update(true).unwrap();
|
||||||
|
|
||||||
let backend = TestBackend::new(50, 15);
|
let backend = TestBackend::new(50, 15);
|
||||||
let mut terminal = Terminal::new(backend).unwrap();
|
let mut terminal = Terminal::new(backend).unwrap();
|
||||||
|
@ -2354,7 +2354,7 @@ mod tests {
|
||||||
|
|
||||||
app.task_report_next();
|
app.task_report_next();
|
||||||
app.context_next();
|
app.context_next();
|
||||||
app.update().unwrap();
|
app.update(true).unwrap();
|
||||||
|
|
||||||
app.calendar_year = 2020;
|
app.calendar_year = 2020;
|
||||||
app.mode = AppMode::Calendar;
|
app.mode = AppMode::Calendar;
|
||||||
|
@ -2440,7 +2440,7 @@ mod tests {
|
||||||
app.mode = AppMode::TaskHelpPopup;
|
app.mode = AppMode::TaskHelpPopup;
|
||||||
app.task_report_next();
|
app.task_report_next();
|
||||||
app.context_next();
|
app.context_next();
|
||||||
app.update().unwrap();
|
app.update(true).unwrap();
|
||||||
|
|
||||||
let backend = TestBackend::new(40, 12);
|
let backend = TestBackend::new(40, 12);
|
||||||
let mut terminal = Terminal::new(backend).unwrap();
|
let mut terminal = Terminal::new(backend).unwrap();
|
||||||
|
@ -2486,7 +2486,7 @@ mod tests {
|
||||||
app.mode = AppMode::TaskContextMenu;
|
app.mode = AppMode::TaskContextMenu;
|
||||||
app.task_report_next();
|
app.task_report_next();
|
||||||
app.context_next();
|
app.context_next();
|
||||||
app.update().unwrap();
|
app.update(true).unwrap();
|
||||||
|
|
||||||
let backend = TestBackend::new(80, 10);
|
let backend = TestBackend::new(80, 10);
|
||||||
let mut terminal = Terminal::new(backend).unwrap();
|
let mut terminal = Terminal::new(backend).unwrap();
|
||||||
|
|
|
@ -94,7 +94,7 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Tick => {
|
Event::Tick => {
|
||||||
let r = app.update();
|
let r = app.update(false);
|
||||||
if r.is_err() {
|
if r.is_err() {
|
||||||
destruct_terminal();
|
destruct_terminal();
|
||||||
return r;
|
return r;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue