don't open an editor is stdin or stdout is not a terminal

This commit is contained in:
Sebastian Kuzminsky 2025-07-13 10:38:29 -06:00
parent 3932baff3b
commit 490f946ef6
2 changed files with 14 additions and 2 deletions

View file

@ -1,4 +1,4 @@
use std::io::Write; use std::io::{IsTerminal, Write};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Comment { pub struct Comment {
@ -26,6 +26,8 @@ pub enum CommentError {
EditorError, EditorError,
#[error("supplied description is empty")] #[error("supplied description is empty")]
EmptyDescription, EmptyDescription,
#[error("stdin/stdout is not a terminal")]
StdioIsNotTerminal,
} }
impl Comment { impl Comment {
@ -146,6 +148,10 @@ impl Comment {
/// Used by Issue::add_comment() when no description is supplied, /// Used by Issue::add_comment() when no description is supplied,
/// and (FIXME: in the future) used by `ent edit COMMENT`. /// and (FIXME: in the future) used by `ent edit COMMENT`.
pub fn edit_description_file(&mut self) -> Result<(), CommentError> { 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 description_filename = self.description_filename();
let exists = description_filename.exists(); let exists = description_filename.exists();

View file

@ -1,5 +1,5 @@
use core::fmt; use core::fmt;
use std::io::Write; use std::io::{IsTerminal, Write};
use std::str::FromStr; use std::str::FromStr;
#[cfg(feature = "log")] #[cfg(feature = "log")]
@ -54,6 +54,8 @@ pub enum IssueError {
EmptyDescription, EmptyDescription,
#[error("tag {0} not found")] #[error("tag {0} not found")]
TagNotFound(String), TagNotFound(String),
#[error("stdin/stdout is not a terminal")]
StdioIsNotTerminal,
} }
impl FromStr for State { impl FromStr for State {
@ -385,6 +387,10 @@ impl Issue {
/// Used by Issue::new() when no description is supplied, and also /// Used by Issue::new() when no description is supplied, and also
/// used by `ent edit ISSUE`. /// used by `ent edit ISSUE`.
fn edit_description_file(&mut self) -> Result<(), IssueError> { 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 description_filename = self.description_filename();
let exists = description_filename.exists(); let exists = description_filename.exists();
let editor = match std::env::var("EDITOR") { let editor = match std::env::var("EDITOR") {