#!perl

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2021-02-19'; # DATE
our $DIST = 'Text-ANSITable'; # DIST
our $VERSION = '0.602'; # VERSION

use 5.010;
use strict;
use warnings;

use Module::Load::Util qw(instantiate_class_with_optional_args);
use Text::ANSITable;

binmode(STDOUT, ":encoding(utf8)");

my $t = Text::ANSITable->new;

if ($ARGV[0]) {
    $t->border_style($ARGV[0]);
}

my @all_bs = $t->list_border_styles;
my %all_bsobj;
for my $bsname (@all_bs) {
    my $info = instantiate_class_with_optional_args({ns_prefix=>"BorderStyle", construct=>0}, $bsname);
    my $class = $info->{class};
    my $struct = $class->get_struct;
    my $args = ($struct->{examples} && @{ $struct->{examples} } ? $struct->{examples}[0]{args} : undef) // {};
    $all_bsobj{$bsname} = instantiate_class_with_optional_args({}, [$class, $args]);
}

$t->columns(['Name', 'Summary', 'box_chars?', 'utf8?']);
my $utf8; # we sort by not utf8 and then utf8, just to demonstrate add_row_separator
for my $name (sort {($all_bsobj{$a}->get_struct->{utf8} ? 1:0)<=>($all_bsobj{$b}->get_struct->{utf8} ? 1:0) || $a cmp $b} @all_bs) {
    my $bsobj = $all_bsobj{$name};
    my $struct = $bsobj->get_struct;
    my $selected = $name eq $t->border_style;
    $t->add_row(
        [$name . ($selected ? " (*)" : ""), $struct->{summary}, $struct->{box_chars} ? 1:0, $struct->{utf8} ? 1:0],
        {fgcolor=>$selected && $t->use_color ? "aaaa00" : undef});

    if (!$utf8 && $struct->{utf8}) {
        $t->add_row_separator;
        $utf8++;
    }
}

say "Tip: you can run me with border style name as argument to try it out.";
print $t->draw;

#use Data::Dump; dd $t->{_row_separators}; dd $t->{_draw}{frow_separators};

# ABSTRACT: List available border styles for Text::ANSITable
# PODNAME: ansitable-list-border-styles

__END__

=pod

=encoding UTF-8

=head1 NAME

ansitable-list-border-styles - List available border styles for Text::ANSITable

=head1 VERSION

This document describes version 0.602 of ansitable-list-border-styles (from Perl distribution Text-ANSITable), released on 2021-02-19.

=head1 SYNOPSIS

 % ansitable-list-border-styles

Sample output:

 Tip: you can run me with border style name as argument to try it out.
 .-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
 | Name                                Summary                                                                                                              box_chars?   utf8? |
 |                                                                                                                                                                             |
 | ASCII::None                         No borders, but data row separator is still drawn using dashes                                                           N          N   |
 | ASCII::SingleLine                   Single line border with ASCII characters                                                                                 N          N   |
 | ASCII::SingleLineDoubleAfterHeade   Just like ASCII::SingleLine but uses double line to separate header row and first data row                               N          N   |
 | r                                                                                                                                                                           |
 | ASCII::SingleLineHorizontalOnly     Single line border with ASCII characters, horizontal only                                                                N          N   |
 | ASCII::SingleLineInnerOnly          Single line border with ASCII characters, between columns only                                                           N          N   |
 | ASCII::SingleLineOuterOnly (*)      Single line border with ASCII characters, outer borders only                                                             N          N   |
 | ASCII::SingleLineVerticalOnly       Single line border with ASCII characters, vertical only                                                                  N          N   |
 | ASCII::Space                        Space as borders, but data row separator is still drawn using dashes                                                     N          N   |
 | ASCII::SpaceInnerOnly               No borders, but columns are still separated using spaces and data row separator is still drawn using dashes              N          N   |
 | BoxChar::None                       No borders, but data row separator is still drawn using horizontal line                                                  Y          N   |
 | BoxChar::SingleLine                 Single line border with box-drawing characters                                                                           Y          N   |
 | BoxChar::SingleLineHorizontalOnly   Single line border with box-drawing characters, horizontal only                                                          Y          N   |
 | BoxChar::SingleLineInnerOnly        Single line border with box-drawing characters, between columns only                                                     Y          N   |
 | BoxChar::SingleLineOuterOnly        Single line border with box-drawing characters, outer borders only                                                       Y          N   |
 | BoxChar::SingleLineVerticalOnly     Single line border with box-drawing characters, vertical only                                                            Y          N   |
 | BoxChar::Space                      Space as borders, but data row separator is still drawn using horizontal line                                            Y          N   |
 | BoxChar::SpaceInnerOnly             No borders, but columns are still separated using spaces and data row separator is still drawn using horizontal          Y          N   |
 |                                     line                                                                                                                                    |
 | Test::CustomChar                    A border style that uses a single custom character                                                                       N          N   |
 | Test::Labeled                       A border style that uses labeled characters as described in specification, to show which character goes where            N          Y   |
 +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | UTF8::Brick                         Single-line, bold on bottom right to give illusion of depth                                                              N          Y   |
 | UTF8::BrickOuterOnly                Single-line (outer only), bold on bottom right to give illusion of depth                                                 N          Y   |
 | UTF8::DoubleLine                    Double-line border with UTF8 characters                                                                                  N          Y   |
 | UTF8::None                          No borders, but data row separator is still drawn using horizontal line                                                  N          Y   |
 | UTF8::SingleLine                    Single-line border with UTF8 characters                                                                                  N          Y   |
 | UTF8::SingleLineBold                Bold single-line border with UTF8 characters                                                                             N          Y   |
 | UTF8::SingleLineBoldHeader          Single-line border (header box bold) with UTF8 characters                                                                N          Y   |
 | UTF8::SingleLineCurved              Single-line border with UTF8 characters, curved edges                                                                    N          Y   |
 | UTF8::SingleLineDoubleAfterHeader   Just like UTF8::SingleLine but uses double line to separate header row and first data row                                N          Y   |
 | UTF8::SingleLineHorizontalOnly      Single line border with box-drawing characters, horizontal only                                                          N          Y   |
 | UTF8::SingleLineInnerOnly           Single line border with UTF8 characters, between columns only                                                            N          Y   |
 | UTF8::SingleLineOuterOnly           Single line border with UTF8 characters, outer borders only                                                              N          Y   |
 | UTF8::SingleLineVerticalOnly        Single line border with UTF8 characters, vertical only                                                                   N          Y   |
 | UTF8::Space                         Space as borders, but data row separator is still drawn using horizontal line                                            N          Y   |
 | UTF8::SpaceInnerOnly                No borders, but columns are still separated using spaces and data row separator is still drawn using horizontal          N          Y   |
 |                                     line                                                                                                                                    |
 `-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

=head1 HOMEPAGE

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

=head1 SOURCE

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

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://github.com/perlancar/perl-Text-ANSITable/issues>

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) 2021, 2020, 2018, 2017, 2016, 2015, 2014, 2013 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