diff options
author | Jesse Luehrs <doy@tozt.net> | 2024-01-01 15:50:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-01 15:50:27 -0500 |
commit | 27be76f23ed36d595c1f3fa37b0d5de0cae56def (patch) | |
tree | 8731ce04614e8b6dc04c1a885e4c4f5b99240611 /src/edit.rs | |
parent | 224a660b1d66fda5ee2366086f40339672f321ab (diff) | |
parent | 5c3332884a917d4da05bfa437ee8b7c7ba5a56b9 (diff) | |
download | rbw-27be76f23ed36d595c1f3fa37b0d5de0cae56def.tar.gz rbw-27be76f23ed36d595c1f3fa37b0d5de0cae56def.zip |
Merge pull request #138 from soraxas/feat-edit-from-stdin
Implements ability to edit from taking piped inputs
Diffstat (limited to 'src/edit.rs')
-rw-r--r-- | src/edit.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/edit.rs b/src/edit.rs index 178e188..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"; |