From c81ac43ca657794797e228f8229f8264424d2b76 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Thu, 7 Apr 2022 22:47:37 -0600 Subject: [PATCH] fix: Use split_once and rc.defaultwidth=0 for column labels --- src/app.rs | 1 + src/task_report.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index 23e8870..3f0ad7c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -202,6 +202,7 @@ impl TaskwarriorTui { let output = std::process::Command::new("task") .arg("rc.color=off") .arg("rc._forcecolor=off") + .arg("rc.defaultwidth=0") .arg("show") .output() .context("Unable to run `task show`.") diff --git a/src/task_report.rs b/src/task_report.rs index 7fe9dd0..4db6be3 100644 --- a/src/task_report.rs +++ b/src/task_report.rs @@ -19,6 +19,13 @@ pub fn format_date(dt: NaiveDateTime) -> String { dt.format("%Y-%m-%d").to_string() } +fn split_once(in_string: &str) -> (&str, &str) { + let mut splitter = in_string.splitn(2, ' '); + let first = splitter.next().unwrap(); + let second = splitter.next().unwrap(); + (first, second) +} + pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime, with_remainder: bool) -> String { let to_dt = Local.from_local_datetime(&to_dt).unwrap(); let from_dt = Local.from_local_datetime(&from_dt).unwrap(); @@ -175,6 +182,7 @@ impl TaskReportTable { } else { let output = Command::new("task") .arg("show") + .arg("rc.defaultwidth=0") .arg(format!("report.{}.columns", report)) .output()?; String::from_utf8_lossy(&output.stdout).into_owned() @@ -182,7 +190,7 @@ impl TaskReportTable { for line in data.split('\n') { if line.starts_with(format!("report.{}.columns", report).as_str()) { - let column_names = line.split(' ').collect::>()[1]; + let column_names = split_once(line).1; for column in column_names.split(',') { self.columns.push(column.to_string()); } @@ -191,13 +199,14 @@ impl TaskReportTable { let output = Command::new("task") .arg("show") + .arg("rc.defaultwidth=0") .arg(format!("report.{}.labels", report)) .output()?; let data = String::from_utf8_lossy(&output.stdout); for line in data.split('\n') { if line.starts_with(format!("report.{}.labels", report).as_str()) { - let label_names = line.split(' ').collect::>()[1]; + let label_names = split_once(line).1; for label in label_names.split(',') { self.labels.push(label.to_string()); }