#!perl

our $DATE = '2015-06-17'; # DATE
our $VERSION = '0.08'; # VERSION

use 5.010001;
use strict 'subs', 'vars';
use warnings;

use Getopt::Long::EvenLess;
use App::hr qw(hr);

my $color;
my $pattern;

# IFBUILT
sub pick {
    return undef unless @_;
    return $_[@_*rand];
}

# END IFBUILT
# IFUNBUILT
# BEGIN { require Function::Embeddable; *pick = \&Function::Embeddable::pick }
# END IFUNBUILT

sub _set_random_pattern {
    $pattern = pick(
        '.',
        '-',
        '=',
        'x',
        'x-',
        'x---',
        'x-----',
        '*',
        '*-',
        '*---',
        '*-----',
        '/\\',
        'v',
        'V',
    );
}

sub _set_random_color {
    $color = pick(
        'red',
        'bright_red',
        'green',
        'bright_green',
        'blue',
        'bright_blue',
        'cyan',
        'bright_cyan',
        'magenta',
        'bright_magenta',
        'yellow',
        'bright_yellow',
    );
}

GetOptions(
    'color|c=s' => sub { $color = $_[1] },
    'pattern|p=s' => sub { $pattern = $_[1] },
    'random-pattern' => \&_set_random_pattern,
    'random-color' => \&_set_random_color,
    'r' => sub { _set_random_pattern(); _set_random_color() },
    'help|h|?' => sub {
        print <<'_';
hr - Print horizontal bar on the terminal

Usage:
  hr [options] [pattern]
  hr --help (or -h, -?)
  hr --version (-v)
Options:
  --color=s, -c     Color text, all Term::ANSIColor colors are supported
  --pattern=s, -p   Set pattern (also via first argument)
  --random-pattern  Use random pattern
  --random-color    Use random color
  -r                Shortcut for --random-pattern --random-color
_
        exit 0;
    },
    'version|v' => sub {
        say "hr version ", ${__PACKAGE__.'::VERSION'} // 'dev';
        exit 0;
    },
) or exit 1;
$pattern //= $ARGV[0] if @ARGV;
hr($pattern, $color);

# ABSTRACT: Print horizontal bar on the terminal
# PODNAME: hr

__END__

=pod

=encoding UTF-8

=head1 NAME

hr - Print horizontal bar on the terminal

=head1 VERSION

This document describes version 0.08 of hr (from Perl distribution App-hr), released on 2015-06-17.

=head1 SYNOPSIS

 % hr
 =============================================================================

 % hr -c red  ;# will output the same bar, but in red

 % hr x----
 x----x----x----x----x----x----x----x----x----x----x----x----x----x----x----x-

 % hr --random-pattern

 % hr --random-color

 % hr -r  ;# shortcut for --random-pattern --random-color

 % hr -- -x-  ;# specify a pattern that starts with a dash
 % hr -p -x-  ;# ditto

 % hr --help

You can also use the C<hr> function in L<App::hr>.

=head1 OPTIONS

=head2 --color=s, -c

=head2 --pattern=s, -p

=head2 --random-pattern

=head2 --random-color

=head2 -r

Shortcut for --random-pattern --random-color.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-hr>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-hr>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-hr>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
