don't open an editor is stdin or stdout is not a terminal
This commit is contained in:
parent
3932baff3b
commit
490f946ef6
2 changed files with 14 additions and 2 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue