Explorar el Código

tau-cli: properly write multi line comments in desc_in_editor function

Dastan-glitch hace 4 años
padre
commit
01287b22c1
Se han modificado 1 ficheros con 9 adiciones y 3 borrados
  1. 9 3
      bin/tau/tau-cli/src/util.rs

+ 9 - 3
bin/tau/tau-cli/src/util.rs

@@ -1,4 +1,9 @@
-use std::{env, fs, process::Command};
+use std::{
+    env,
+    fs::{self, File},
+    io::Write,
+    process::Command,
+};
 
 use chrono::{Datelike, Local, NaiveDate};
 use log::error;
@@ -33,9 +38,10 @@ pub fn desc_in_editor() -> Result<Option<String>> {
     let mut file_path = env::temp_dir();
     let file_name = format!("tau-{}", Timestamp::current_time().0);
     file_path.push(file_name);
+    let mut file = File::create(&file_path)?;
 
-    fs::write(&file_path, "# Write your task description here.\n")?;
-    fs::write(&file_path, "# Lines starting with \"#\" will be removed\n")?;
+    writeln!(file, "\n# Write your task description here.")?;
+    writeln!(file, "# Lines starting with \"#\" will be removed")?;
 
     // Try $EDITOR, and if not, fallback to xdg-open.
     let editor_argv0 = match env::var("EDITOR") {