diff options
author | Tin Lai <oscar@tinyiu.com> | 2023-09-21 13:31:31 +1000 |
---|---|---|
committer | Tin Lai <oscar@tinyiu.com> | 2023-09-21 13:31:51 +1000 |
commit | 5c3332884a917d4da05bfa437ee8b7c7ba5a56b9 (patch) | |
tree | 10bd4e8e0b4e54b7ad53b932784a9fe1cadc8490 /src/edit.rs | |
parent | bb1791d14e64ad83fb57116a24eb913a4946afed (diff) | |
download | rbw-5c3332884a917d4da05bfa437ee8b7c7ba5a56b9.tar.gz rbw-5c3332884a917d4da05bfa437ee8b7c7ba5a56b9.zip |
implements ability to edit from taking piped inputs
Signed-off-by: Tin Lai <oscar@tinyiu.com>
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 aa8c7b1..057996d 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"; |