From c3c1db696f3b04e4aef06fd2b01e436b1fe06b08 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Tue, 26 May 2020 23:22:19 -0400 Subject: editing a post calls $EDITOR --- src/posts.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') 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(()) } -- cgit 1.4.1-2-gfad0