mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 23:46:41 +02:00
Move thread to start_background_thread function
This commit is contained in:
parent
a7b4f424e3
commit
953ec46e74
1 changed files with 34 additions and 32 deletions
66
src/app.rs
66
src/app.rs
|
@ -126,41 +126,43 @@ impl TTApp {
|
|||
colors: TColor::default(),
|
||||
};
|
||||
app.update();
|
||||
let handle = {
|
||||
let tasks = app.tasks.clone();
|
||||
let filter = app.filter.clone();
|
||||
thread::spawn(move || loop {
|
||||
let mut task = Command::new("task");
|
||||
|
||||
task.arg("rc.json.array=on");
|
||||
task.arg("export");
|
||||
|
||||
match shlex::split(&filter) {
|
||||
Some(cmd) => {
|
||||
for s in cmd {
|
||||
task.arg(&s);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
task.arg("");
|
||||
}
|
||||
}
|
||||
|
||||
let output = task
|
||||
.output()
|
||||
.expect("Unable to run `task export`. Check documentation for more information.");
|
||||
let data = String::from_utf8(output.stdout).unwrap();
|
||||
let imported = import(data.as_bytes());
|
||||
if let Ok(i) = imported {
|
||||
*(tasks.lock().unwrap()) = i;
|
||||
tasks.lock().unwrap().sort_by(cmp);
|
||||
}
|
||||
thread::sleep(Duration::from_millis(250));
|
||||
})
|
||||
};
|
||||
app.start_background_thread();
|
||||
app
|
||||
}
|
||||
|
||||
pub fn start_background_thread(&self) {
|
||||
let tasks = self.tasks.clone();
|
||||
let filter = self.filter.clone();
|
||||
thread::spawn(move || loop {
|
||||
let mut task = Command::new("task");
|
||||
|
||||
task.arg("rc.json.array=on");
|
||||
task.arg("export");
|
||||
|
||||
match shlex::split(&filter) {
|
||||
Some(cmd) => {
|
||||
for s in cmd {
|
||||
task.arg(&s);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
task.arg("");
|
||||
}
|
||||
}
|
||||
|
||||
let output = task
|
||||
.output()
|
||||
.expect("Unable to run `task export`. Check documentation for more information.");
|
||||
let data = String::from_utf8(output.stdout).unwrap();
|
||||
let imported = import(data.as_bytes());
|
||||
if let Ok(i) = imported {
|
||||
*(tasks.lock().unwrap()) = i;
|
||||
tasks.lock().unwrap().sort_by(cmp);
|
||||
}
|
||||
thread::sleep(Duration::from_millis(250));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, f: &mut Frame<impl Backend>) {
|
||||
let tasks_is_empty = self.tasks.lock().unwrap().is_empty();
|
||||
let tasks_len = self.tasks.lock().unwrap().len();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue