~gbmor/clinte

23a7db0f19f82168e8a9324f7e3e88c9701046cc — Ben Morrison 1 year, 6 months ago d88b80d
trimming whitespace
both when posting new item and when displaying items.
prevents posts from messing up the display of other
posts with extraneous whitespace.
1 files changed, 15 insertions(+), 9 deletions(-)

M src/posts.rs
M src/posts.rs => src/posts.rs +15 -9
@@ 48,14 48,16 @@ pub fn create(db: &db::Conn) -> error::Result<()> {
    };

    println!();
    let body = str_to_utf8(&ed::call());
    let body = if body.len() > 500 {
        &body[..500]
    let body_raw = str_to_utf8(&ed::call());
    let body = if body_raw.len() > 500 {
        &body_raw[..500]
    } else {
        &body
        &body_raw
    };

    exec_new(&mut stmt, title, body)?;
    let trimmed_body = body.trim();

    exec_new(&mut stmt, title, trimmed_body)?;

    println!();
    Ok(())


@@ 80,10 82,14 @@ pub fn display(db: &db::Conn) -> error::Result<()> {
    let mut postvec = Vec::new();
    out.for_each(|row| {
        if let Ok(post) = row {
            postvec.push(format!(
                "{}. {} -> by {}\n{}\n",
                post.id, post.title, post.author, post.body
            ));
            let newpost = format!(
                "{}. {} -> by {}\n{}\n\n",
                post.id,
                post.title.trim(),
                post.author,
                post.body.trim()
            );
            postvec.push(newpost);
        }
    });