Skip to content

Commit

Permalink
handle y/n prompting without interactive terminal
Browse files Browse the repository at this point in the history
mostly
  • Loading branch information
rjbs committed Mar 12, 2017
1 parent 058c53b commit b63c441
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/Dist/Zilla/Chrome/Term.pm
Expand Up @@ -110,6 +110,16 @@ sub prompt_yn {
$arg ||= {};
my $default = $arg->{default};

if (! $self->_isa_tty) {
if (defined $default) {
return OneZero->coerce($default);
}

$self->logger->log_fatal(
"want interactive input, but terminal doesn't appear interactive"
);
}

my $input = $self->term_ui->ask_yn(
prompt => $prompt,
(defined $default ? (default => OneZero->coerce($default)) : ()),
Expand All @@ -118,11 +128,16 @@ sub prompt_yn {
return $input;
}

sub _isa_tty {
my $isa_tty = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT));
return $isa_tty;
}

sub prompt_any_key {
my ($self, $prompt) = @_;
$prompt ||= 'press any key to continue';

my $isa_tty = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT));
my $isa_tty = $self->_isa_tty;

if ($isa_tty) {
local $| = 1;
Expand Down

0 comments on commit b63c441

Please sign in to comment.