/// Save the received command to a temporary file, which is the edited with $EDITOR
/// As soon as the editor is closed, read the file content and send a message
/// with the updated command to the daemon
Save the received command to a temporary file, which is the edited with $EDITOR
As soon as the editor is closed, read the file content and send a message
with the updated command to the daemon
Save the received command to a temporary file which is the edited with $EDITOR As soon as the editor is closed read the file content and send a message with the updated command to the daemon
pub fn edit(message: Message) -> Message {
    let message = match message {
        Message::EditResponse(message) => message,
        _ => {
            error!("Should have received a EditResponseMessage");
            exit(1);
        }
    };
    let editor = env::var("EDITOR").unwrap_or("vi".to_string());
    // Create a temporary file with the command, vim can edit
    let mut file = NamedTempFile::new().expect("Failed to create a temporary file");
    writeln!(file, "{}", message.command).expect("Failed writing to temporary file");
    Command::new(editor)
        .arg(file.path())
        .status()
        .expect("Failed to start editor");
    let mut file = file.into_file();
    file.seek(SeekFrom::Start(0))
        .expect("Couldn't seek to start of file. Aborting.");
    let mut edited_command = String::new();
    file.read_to_string(&mut edited_command)
        .expect("Failed to read Command after editing");
    Message::Edit(EditMessage {
        task_id: message.task_id,
        command: edited_command,
    })
}
pub fn edit ( message : Message ) -> Message { let message = match message { Message :: EditResponse ( message ) => message , _ => { error ! ( " " ) ; exit ( 1 ) ; } } ; let editor = env :: var ( " " ) . unwrap_or ( " " . to_string ( ) ) ; // Create a temporary file with the command, vim can edit let mut file = NamedTempFile :: new ( ) . expect ( " " ) ; writeln ! ( file " " message command ) . expect ( " " ) ; Command :: new ( editor ) . arg ( file . path ( ) ) . status ( ) . expect ( " " ) ; let mut file = file . into_file ( ) ; file . seek ( SeekFrom :: Start ( 0 ) ) . expect ( " " ) ; let mut edited_command = String :: new ( ) ; file . read_to_string ( & mut edited_command ) . expect ( " " ) ; Message :: Edit ( EditMessage { task_id : message . task_id , command : edited_command , } ) }
Save the received command to a temporary file, which is the edited with $EDITOR
As soon as the editor is closed, read the file content and send a message
with the updated command to the daemon
Save the received command to a temporary file which is the edited with $EDITOR As soon as the editor is closed read the file content and send a message with the updated command to the daemon
message
Message