Merge pull request #1372 from matthiasbeyer/libimagrt/edit-stdin-devtty
libimagrt: Pass /dev/tty as stdin to editor
This commit is contained in:
commit
ec2f87afad
3 changed files with 21 additions and 17 deletions
|
@ -23,6 +23,7 @@ error_chain! {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreign_links {
|
foreign_links {
|
||||||
|
IO(::std::io::Error);
|
||||||
TomlDeError(::toml::de::Error);
|
TomlDeError(::toml::de::Error);
|
||||||
TomlQueryError(::toml_query::error::Error);
|
TomlQueryError(::toml_query::error::Error);
|
||||||
HandlebarsTemplateError(::handlebars::TemplateError);
|
HandlebarsTemplateError(::handlebars::TemplateError);
|
||||||
|
|
|
@ -39,6 +39,7 @@ use io::OutputProxy;
|
||||||
use libimagerror::trace::*;
|
use libimagerror::trace::*;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
||||||
|
use libimagutil::debug_result::DebugResult;
|
||||||
use spec::CliSpec;
|
use spec::CliSpec;
|
||||||
|
|
||||||
/// The Runtime object
|
/// The Runtime object
|
||||||
|
@ -454,7 +455,7 @@ impl<'a> Runtime<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a editor command object which can be called to open the $EDITOR
|
/// Get a editor command object which can be called to open the $EDITOR
|
||||||
pub fn editor(&self) -> Option<Command> {
|
pub fn editor(&self) -> Result<Option<Command>, RuntimeError> {
|
||||||
self.cli()
|
self.cli()
|
||||||
.value_of("editor")
|
.value_of("editor")
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
|
@ -466,18 +467,19 @@ impl<'a> Runtime<'a> {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.or(env::var("EDITOR").ok())
|
.or(env::var("EDITOR").ok())
|
||||||
.map(|s| {debug!("Editing with '{}'", s); s})
|
.ok_or_else(|| RuntimeErrorKind::IOError.into())
|
||||||
|
.map_dbg(|s| format!("Editing with '{}'", s))
|
||||||
.and_then(|s| {
|
.and_then(|s| {
|
||||||
let mut split = s.split(" ");
|
let mut split = s.split(" ");
|
||||||
let command = split.next();
|
let command = split.next();
|
||||||
if command.is_none() {
|
if command.is_none() {
|
||||||
return None
|
return Ok(None)
|
||||||
}
|
}
|
||||||
let mut c = Command::new(command.unwrap()); // secured above
|
let mut c = Command::new(command.unwrap()); // secured above
|
||||||
c.args(split);
|
c.args(split);
|
||||||
c.stdin(::std::process::Stdio::null());
|
c.stdin(::std::fs::File::open("/dev/tty")?);
|
||||||
c.stderr(::std::process::Stdio::inherit());
|
c.stderr(::std::process::Stdio::inherit());
|
||||||
Some(c)
|
Ok(Some(c))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,18 +72,19 @@ impl EditHeader for Entry {
|
||||||
pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> {
|
pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> {
|
||||||
use libimagutil::edit::edit_in_tmpfile_with_command;
|
use libimagutil::edit::edit_in_tmpfile_with_command;
|
||||||
|
|
||||||
rt.editor()
|
let editor = rt
|
||||||
.ok_or(EE::from_kind(EditErrorKind::NoEditor))
|
.editor()
|
||||||
.and_then(|editor| {
|
.chain_err(|| EditErrorKind::NoEditor)?
|
||||||
edit_in_tmpfile_with_command(editor, s)
|
.ok_or_else(|| EE::from_kind(EditErrorKind::NoEditor))?;
|
||||||
.chain_err(|| EditErrorKind::IOError)
|
|
||||||
.and_then(|worked| {
|
edit_in_tmpfile_with_command(editor, s)
|
||||||
if !worked {
|
.chain_err(|| EditErrorKind::IOError)
|
||||||
Err(EditErrorKind::ProcessExitFailure.into())
|
.and_then(|worked| {
|
||||||
} else {
|
if !worked {
|
||||||
Ok(())
|
Err(EditErrorKind::ProcessExitFailure.into())
|
||||||
}
|
} else {
|
||||||
})
|
Ok(())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue