Runtime::editor() should provide a Command object

This commit is contained in:
Matthias Beyer 2016-01-02 19:27:13 +01:00
parent ad1a0e7f47
commit 2b8bd86ce1

View file

@ -1,4 +1,5 @@
use std::fmt::{Debug, Formatter, Error}; use std::fmt::{Debug, Formatter, Error};
use std::process::Command;
extern crate log; extern crate log;
use log::{LogRecord, LogLevel, LogLevelFilter, LogMetadata, SetLoggerError}; 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; use std::env::var;
if let Some(editor) = self.config.editor() { let (editor, args) : (String, String) = {
editor + &self.config.editor_opts()[..] if let Some(editor) = self.config.editor() {
} else if let Some(editor) = self.configuration.editor() { (editor, self.config.editor_opts())
editor + &self.configuration.editor_opts()[..] } else if let Some(editor) = self.configuration.editor() {
} else if let Ok(editor) = var("EDITOR") { (editor, self.configuration.editor_opts())
editor } else if let Ok(editor) = var("EDITOR") {
} else { (editor, String::from(""))
String::from("vim") } else {
(String::from("vim"), String::from(""))
}
};
let mut e = Command::new(editor);
for arg in args.split(" ") {
e.arg(arg);
} }
e
} }
} }