~gbmor/clinte

896f987f2705d1c5152d6c0741c377e3612f048a — Ben Morrison 1 year, 2 months ago c3c1db6
prepopulating editor with post body when editing
2 files changed, 9 insertions(+), 4 deletions(-)

M src/ed.rs
M src/posts.rs
M src/ed.rs => src/ed.rs +6 -1
@@ 16,7 16,7 @@ fn create_tmp_file<'a>() -> Result<String, std::io::Error> {
    }
}

pub fn call() -> String {
pub fn call(body: &str) -> String {
    // If they don't have $EDITOR set, just default to nano
    // instead of assuming vim or emacs.
    let editor = match env::var("EDITOR") {


@@ 36,6 36,11 @@ pub fn call() -> String {
    let tmp_loc = error::helper(create_tmp_file(), "Couldn't create tempfile");

    error::helper(
        fs::write(&tmp_loc, body),
        "Couldn't populate tempfile with message",
    );

    error::helper(
        process::Command::new(editor)
            .arg(&tmp_loc)
            .stdin(process::Stdio::inherit())

M src/posts.rs => src/posts.rs +3 -3
@@ 51,7 51,7 @@ pub fn create(db: &db::Conn) -> error::Result<()> {

    println!();

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


@@ 136,12 136,12 @@ pub fn update_handler(db: &db::Conn, id: u32) -> error::Result<()> {

    println!("Updating post {}", id_num_in);
    println!();
    println!("Title: {}\n\nBody: {}", row[0], row[2]);
    println!("Current Title: {}", &row[0]);
    println!();
    println!("Enter new title:");
    io::stdin().read_line(&mut new_title)?;

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