aboutsummaryrefslogtreecommitdiffstats
path: root/src/edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit.rs')
-rw-r--r--src/edit.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/edit.rs b/src/edit.rs
index aa8c7b1..cb59366 100644
--- a/src/edit.rs
+++ b/src/edit.rs
@@ -3,6 +3,14 @@ use crate::prelude::*;
use std::io::{Read as _, Write as _};
pub fn edit(contents: &str, help: &str) -> Result<String> {
+ if ! atty::is(atty::Stream::Stdin) {
+ // directly read from piped content
+ return match std::io::read_to_string(std::io::stdin()) {
+ Err(e) => Err(Error::FailedToReadFromStdin{ err: e }),
+ Ok(res) => Ok(res),
+ };
+ }
+
let mut var = "VISUAL";
let editor = std::env::var_os(var).unwrap_or_else(|| {
var = "EDITOR";
@@ -30,7 +38,7 @@ pub fn edit(contents: &str, help: &str) -> Result<String> {
let editor = std::path::Path::new(&editor);
let mut editor_args = vec![];
- #[allow(clippy::single_match)] // more to come
+ #[allow(clippy::single_match_else)] // more to come
match editor.file_name() {
Some(editor) => match editor.to_str() {
Some("vim" | "nvim") => {