Ask

 view release on metacpan or  search on metacpan

lib/Ask/Caroline.pm  view on Meta::CPAN

use 5.008008;
use strict;
use warnings;

package Ask::Caroline;

our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION   = '0.015';

use Moo;
use Caroline ();
use Path::Tiny 'path';
use Term::ANSIColor 'colored';
use namespace::autoclean;

with 'Ask::API';

has caroline => (
	is      => 'lazy',
	default => sub {
		my $self = shift;
		Scalar::Util::weaken( my $weak = $self );
		'Caroline'->new(
			completion_callback => sub {
				return unless $weak && $weak->has_completion;
				$weak->completion->( @_ );
			},
		);
	},
);

has completion => ( is => 'rw', predicate => 1, clearer => 1 );

sub BUILD {
	STDOUT->autoflush( 1 );
}

sub is_usable {
	my ( $self ) = @_;
	-t STDIN and -t STDOUT;
}

sub quality {
	my ( $self ) = ( shift );
	
	( ref( $self ) ? $self : 'Caroline'->new )->is_supported ? 90 : 30;
}

sub entry {
	my ( $self, %opts ) = ( shift, @_ );
	$opts{prompt} = 'entry> ' unless exists $opts{prompt};
	
	if ( exists $opts{completion} ) {
		$self->completion( $opts{completion} );
	}
	else {
		$self->completion(
			sub {
				return $opts{default};
			}
		);
	}
	
	if ( exists $opts{text} ) {
		$self->info(
			text   => $opts{text},
			colour => $opts{colour} || 'bright_cyan',
		);
	}
	
	my ( $line, $tio );
	
	if (
		$opts{hide_text}



( run in 1.116 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )