From 490f946ef6bca53f965514235d1325f6a5c4cab6 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Sun, 13 Jul 2025 10:38:29 -0600 Subject: [PATCH] don't open an editor is stdin or stdout is not a terminal --- src/comment.rs | 8 +++++++- src/issue.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index e9c3134..c8e26c9 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -1,4 +1,4 @@ -use std::io::Write; +use std::io::{IsTerminal, Write}; #[derive(Debug, PartialEq)] pub struct Comment { @@ -26,6 +26,8 @@ pub enum CommentError { EditorError, #[error("supplied description is empty")] EmptyDescription, + #[error("stdin/stdout is not a terminal")] + StdioIsNotTerminal, } impl Comment { @@ -146,6 +148,10 @@ impl Comment { /// Used by Issue::add_comment() when no description is supplied, /// and (FIXME: in the future) used by `ent edit COMMENT`. pub fn edit_description_file(&mut self) -> Result<(), CommentError> { + if !std::io::stdin().is_terminal() || !std::io::stdout().is_terminal() { + return Err(CommentError::StdioIsNotTerminal); + } + let description_filename = self.description_filename(); let exists = description_filename.exists(); diff --git a/src/issue.rs b/src/issue.rs index bd0632c..1558578 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -1,5 +1,5 @@ use core::fmt; -use std::io::Write; +use std::io::{IsTerminal, Write}; use std::str::FromStr; #[cfg(feature = "log")] @@ -54,6 +54,8 @@ pub enum IssueError { EmptyDescription, #[error("tag {0} not found")] TagNotFound(String), + #[error("stdin/stdout is not a terminal")] + StdioIsNotTerminal, } impl FromStr for State { @@ -385,6 +387,10 @@ impl Issue { /// Used by Issue::new() when no description is supplied, and also /// used by `ent edit ISSUE`. fn edit_description_file(&mut self) -> Result<(), IssueError> { + if !std::io::stdin().is_terminal() || !std::io::stdout().is_terminal() { + return Err(IssueError::StdioIsNotTerminal); + } + let description_filename = self.description_filename(); let exists = description_filename.exists(); let editor = match std::env::var("EDITOR") {