From 2b8bd86ce16f37b6df956c3480f550056c826a39 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 2 Jan 2016 19:27:13 +0100 Subject: [PATCH] Runtime::editor() should provide a Command object --- src/runtime.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index 9ccce2f2..029e68a8 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -1,4 +1,5 @@ use std::fmt::{Debug, Formatter, Error}; +use std::process::Command; extern crate log; use log::{LogRecord, LogLevel, LogLevelFilter, LogMetadata, SetLoggerError}; @@ -112,18 +113,26 @@ impl<'a> Runtime<'a> { } } - pub fn editor(&self) -> String { + pub fn editor(&self) -> Command { use std::env::var; - if let Some(editor) = self.config.editor() { - editor + &self.config.editor_opts()[..] - } else if let Some(editor) = self.configuration.editor() { - editor + &self.configuration.editor_opts()[..] - } else if let Ok(editor) = var("EDITOR") { - editor - } else { - String::from("vim") + let (editor, args) : (String, String) = { + if let Some(editor) = self.config.editor() { + (editor, self.config.editor_opts()) + } else if let Some(editor) = self.configuration.editor() { + (editor, self.configuration.editor_opts()) + } else if let Ok(editor) = var("EDITOR") { + (editor, String::from("")) + } else { + (String::from("vim"), String::from("")) + } + }; + + let mut e = Command::new(editor); + for arg in args.split(" ") { + e.arg(arg); } + e } }