Parcourir la source

bin/tau: more useful info added when writing task description in editor

Dastan-glitch il y a 3 ans
Parent
commit
ef882ac410
3 fichiers modifiés avec 44 ajouts et 3 suppressions
  1. 6 1
      bin/tau/tau-cli/src/main.rs
  2. 22 0
      bin/tau/tau-cli/src/primitives.rs
  3. 16 2
      bin/tau/tau-cli/src/util.rs

+ 6 - 1
bin/tau/tau-cli/src/main.rs

@@ -199,9 +199,14 @@ async fn main() -> Result<()> {
                 };
                 };
 
 
                 if task.desc.is_none() {
                 if task.desc.is_none() {
-                    task.desc = desc_in_editor()?;
+                    task.desc = desc_in_editor(task.clone())?;
                 };
                 };
 
 
+                if task.clone().desc.unwrap().trim().is_empty() {
+                    error!("Abort adding the task due to empty description.");
+                    exit(1)
+                }
+
                 return tau.add(task).await
                 return tau.add(task).await
             }
             }
 
 

+ 22 - 0
bin/tau/tau-cli/src/primitives.rs

@@ -97,6 +97,28 @@ pub struct TaskInfo {
     pub comments: Vec<Comment>,
     pub comments: Vec<Comment>,
 }
 }
 
 
+impl From<BaseTask> for TaskInfo {
+    fn from(value: BaseTask) -> Self {
+        Self {
+            ref_id: String::default(),
+            workspace: String::default(),
+            id: u32::default(),
+            title: value.title,
+            tags: value.tags,
+            desc: String::default(),
+            owner: String::default(),
+            assign: value.assign,
+            project: value.project,
+            due: value.due,
+            rank: value.rank,
+            created_at: i64::default(),
+            state: String::default(),
+            events: vec![],
+            comments: vec![],
+        }
+    }
+}
+
 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
 pub struct TaskEvent {
 pub struct TaskEvent {
     pub action: String,
     pub action: String,

+ 16 - 2
bin/tau/tau-cli/src/util.rs

@@ -28,6 +28,11 @@ use log::error;
 
 
 use darkfi::{util::time::Timestamp, Result};
 use darkfi::{util::time::Timestamp, Result};
 
 
+use crate::{
+    primitives::{BaseTask, TaskInfo},
+    view::print_task_info,
+};
+
 /// Parse due date (e.g. "1503" for 15 March) as i64 timestamp.
 /// Parse due date (e.g. "1503" for 15 March) as i64 timestamp.
 pub fn due_as_timestamp(due: &str) -> Option<i64> {
 pub fn due_as_timestamp(due: &str) -> Option<i64> {
     if due.len() != 4 || due.parse::<u32>().is_err() {
     if due.len() != 4 || due.parse::<u32>().is_err() {
@@ -57,7 +62,8 @@ pub fn due_as_timestamp(due: &str) -> Option<i64> {
 }
 }
 
 
 /// Start up the preferred editor to edit a task's description.
 /// Start up the preferred editor to edit a task's description.
-pub fn desc_in_editor() -> Result<Option<String>> {
+pub fn desc_in_editor(task: BaseTask) -> Result<Option<String>> {
+    let task_info = TaskInfo::from(task);
     // Create a temporary file with some comments inside.
     // Create a temporary file with some comments inside.
     let mut file_path = env::temp_dir();
     let mut file_path = env::temp_dir();
     let file_name = format!("tau-{}", Timestamp::current_time().0);
     let file_name = format!("tau-{}", Timestamp::current_time().0);
@@ -65,7 +71,12 @@ pub fn desc_in_editor() -> Result<Option<String>> {
     let mut file = File::create(&file_path)?;
     let mut file = File::create(&file_path)?;
 
 
     writeln!(file, "\n# Write your task description here.")?;
     writeln!(file, "\n# Write your task description here.")?;
-    writeln!(file, "# Lines starting with \"#\" will be removed")?;
+    writeln!(file, "# Lines starting with \"#\" will be removed.")?;
+    writeln!(file, "# An empty description aborts adding the task.")?;
+    writeln!(file, "\n# ------------------------ >8 ------------------------")?;
+    writeln!(file, "# Do not modify or remove the line above.")?;
+    writeln!(file, "# Everything below it will be ignored.")?;
+    writeln!(file, "\n{:?}", print_task_info(task_info))?;
 
 
     // Try $EDITOR, and if not, fallback to xdg-open.
     // Try $EDITOR, and if not, fallback to xdg-open.
     let editor_argv0 = match env::var("EDITOR") {
     let editor_argv0 = match env::var("EDITOR") {
@@ -84,6 +95,9 @@ pub fn desc_in_editor() -> Result<Option<String>> {
         if !i.starts_with('#') {
         if !i.starts_with('#') {
             lines.push(i.to_string())
             lines.push(i.to_string())
         }
         }
+        if i == "# ------------------------ >8 ------------------------" {
+            break
+        }
     }
     }
     Ok(Some(lines.join("\n")))
     Ok(Some(lines.join("\n")))
 }
 }