about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-26 23:22:19 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-26 23:54:16 -0400
commitc3c1db696f3b04e4aef06fd2b01e436b1fe06b08 (patch)
tree5bc61b73397e4a96ce1e707fa0e590cd5f716556
parent841e6a34a49261d2681c8a4d2c1dc176ba4e3b35 (diff)
downloadclinte-c3c1db696f3b04e4aef06fd2b01e436b1fe06b08.tar.gz
editing a post calls $EDITOR
-rw-r--r--src/posts.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/posts.rs b/src/posts.rs
index be95533..f625a90 100644
--- a/src/posts.rs
+++ b/src/posts.rs
@@ -133,7 +133,6 @@ pub fn update_handler(db: &db::Conn, id: u32) -> error::Result<()> {
     }
 
     let mut new_title = String::new();
-    let mut new_body = String::new();
 
     println!("Updating post {}", id_num_in);
     println!();
@@ -141,12 +140,19 @@ pub fn update_handler(db: &db::Conn, id: u32) -> error::Result<()> {
     println!();
     println!("Enter new title:");
     io::stdin().read_line(&mut new_title)?;
-    println!();
-    println!("Enter new body:");
-    io::stdin().read_line(&mut new_body)?;
-    println!();
 
-    update(&new_title, &new_body, id_num_in, &db)?;
+    let body_raw = str_to_utf8(&ed::call());
+    let body = if body_raw.len() > 500 {
+        &body_raw[..500]
+    } else {
+        &body_raw
+    };
+
+    let trimmed_body = body.trim();
+
+    update(&new_title, &trimmed_body, id_num_in, &db)?;
+
+    println!();
     Ok(())
 }
 
@@ -201,6 +207,7 @@ pub fn delete_handler(db: &db::Conn, id: u32) -> error::Result<()> {
     }
 
     exec_stmt_no_params(&mut del_stmt)?;
+    println!();
     Ok(())
 }