fix: Allow spaces in project name 🐛

This commit is contained in:
Dheepak Krishnamurthy 2021-10-29 13:36:41 -06:00
parent 865369fcf4
commit 847ff1c2da
2 changed files with 31 additions and 10 deletions

View file

@ -276,8 +276,11 @@ impl TaskwarriorTui {
for c in app.config.filter.chars() {
app.filter.insert(c, 1);
}
app.get_context()?;
app.update(true)?;
app.filter_history_context.load()?;
app.filter_history_context.add(app.filter.as_str());
app.command_history_context.load()?;
@ -4427,7 +4430,7 @@ mod tests {
// #[test]
fn test_app() {
let mut app = TaskwarriorTui::new("completed").unwrap();
let mut app = TaskwarriorTui::new("next").unwrap();
app.update(true).unwrap();

View file

@ -118,25 +118,43 @@ impl ProjectsState {
.context("Unable to run `task summary`")
.unwrap();
let data = String::from_utf8_lossy(&output.stdout);
let contains_avg_age = data
.split('\n')
.into_iter()
.skip(1)
.collect::<Vec<&str>>()
.first()
.unwrap()
.contains("Avg age");
for line in data.split('\n').into_iter().skip(3) {
if line.is_empty() {
break;
}
let row: Vec<String> = line
let mut row: Vec<String> = line
.split(' ')
.map(str::trim)
.map(str::trim_start)
.filter(|x| !x.is_empty())
.filter(|x| !x.chars().all(|c| c == '='))
.map(ToString::to_string)
.collect();
let name = (&row[0]).parse()?;
let remaining = (&row[1]).parse()?;
let mut avg_age = "0s".to_string();
let mut complete = (&row[2]).parse()?;
if row.len() > 3 {
avg_age = (&row[2]).parse()?;
complete = (&row[3]).parse()?;
}
assert!(row.len() >= 3);
let (complete, avg_age, remaining, name) = if contains_avg_age {
(
row.pop().unwrap().parse().unwrap(),
row.pop().unwrap().parse().unwrap(),
row.pop().unwrap().parse().unwrap(),
row.join(" "),
)
} else {
(
row.pop().unwrap().parse().unwrap(),
"0s".to_string(),
row.pop().unwrap().parse().unwrap(),
row.join(" "),
)
};
self.rows.push(ProjectDetails {
name,
remaining,