#!perl

our $DATE = '2020-06-21'; # DATE
our $VERSION = '0.599_002'; # TRIAL 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;
my @all_ct = $t->list_color_themes;
my %all_ctobj;
for my $ctname (@all_ct) {
    say "D:$ctname";
    my $info = instantiate_class_with_optional_args({ns_prefix=>"ColorTheme", construct=>0}, $ctname);
    my $class = $info->{class};
    my $struct = $class->get_struct;
    my $args = ($struct->{examples} && @{ $struct->{examples} } ? $struct->{examples}[0]{args} : undef) // {};
    $all_ctobj{$ctname} = instantiate_class_with_optional_args({}, [$class, $args]);
}

my $chosen_ct = $ARGV[0] // $t->color_theme;

$t->columns(['Name', 'Summary']);
for my $name (@all_ct) {
    my $ctobj = $all_ctobj{$name};
    my $struct = $ctobj->get_struct;
    my $selected = $chosen_ct eq $name;

    $t->add_row([$name . ($selected ? " (*)" : ""), $struct->{summary}],
                {fgcolor=>($selected && $t->use_color ? 'aaaa00' : undef)});
}

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

$t = Text::ANSITable->new;
$t->color_theme($chosen_ct);
my $ct = $t->color_theme;
$t->columns(['num','percent%','date','bool?','text']);
$t->add_row([1, 0.4, time(), 1, 'hello']);
$t->add_row([-3.3, 1, time(), 0, 'world']);
$t->add_row_separator;
$t->add_row([$_, $_/10, 1367451584+$_*10000, int(rand()*2), "x$_"])
    for 1..5;

say "Demo table";
print $t->draw;

# ABSTRACT: List available color themes for Text::ANSITable
# PODNAME: ansitable-list-color-themes

__END__

=pod

=encoding UTF-8

=head1 NAME

ansitable-list-color-themes - List available color themes for Text::ANSITable

=head1 VERSION

This document describes version 0.599_002 of ansitable-list-color-themes (from Perl distribution Text-ANSITable), released on 2020-06-21.

=head1 SYNOPSIS

 % ansitable-list-color-themes

Sample output:

 D:GraphicsColorNames
 D:Harmony::Analogous
 D:Harmony::Monochromatic
 D:Lens::Darken
 D:Lens::Lighten
 D:Lens::Tint
 D:NoColor
 D:Test::Dynamic
 D:Test::Random
 D:Test::RandomANSI16
 D:Test::RandomANSI256
 D:Test::Static
 D:Text::ANSITable::Standard::Gradation
 D:Text::ANSITable::Standard::GradationWhiteBG
 D:Text::ANSITable::Standard::NoGradation
 D:Text::ANSITable::Standard::NoGradationWhiteBG
 Tip: you can run me with color theme name as argument to try it out.
 .-------------------------------------------------------------------------------------------------------------.
 | Name                                            Summary                                                     |
 |                                                                                                             |
 | GraphicsColorNames                              Display Graphics::ColorNames::* color scheme as color theme |
 | Harmony::Analogous                              Create theme with colors equidistant in hue                 |
 | Harmony::Monochromatic                          Create a monochromatic color theme                          |
 | Lens::Darken                                    Darken other theme                                          |
 | Lens::Lighten                                   Lighten other theme                                         |
 | Lens::Tint                                      Tint other theme                                            |
 | NoColor (*)                                     An empty color theme that provides no items                 |
 | Test::Dynamic                                   A dynamic color theme                                       |
 | Test::Random                                    A color theme which gives random colors                     |
 | Test::RandomANSI16                              A color theme which gives random 16-color ANSI codes        |
 | Test::RandomANSI256                             A color theme which gives random 256-color ANSI codes       |
 | Test::Static                                    A static color theme                                        |
 | Text::ANSITable::Standard::Gradation            Gradation border (for terminal with black background)       |
 | Text::ANSITable::Standard::GradationWhiteBG     Gradation (for terminal with white background)              |
 | Text::ANSITable::Standard::NoGradation          No gradation, for black background                          |
 | Text::ANSITable::Standard::NoGradationWhiteBG   Default (no gradation, for white background)                |
 `-------------------------------------------------------------------------------------------------------------'
 Demo table
 .-------------------------------------------------------.
 |  num   percent%          date           bool?   text  |
 |                                                       |
 |    1     40,00%   2020-06-21 11:54:00     Y     hello |
 | -3.3    100,00%   2020-06-21 11:54:00     N     world |
 +-------------------------------------------------------+
 |    1     10,00%   2013-05-02 09:26:24     Y     x1    |
 |    2     20,00%   2013-05-02 12:13:04     Y     x2    |
 |    3     30,00%   2013-05-02 14:59:44     Y     x3    |
 |    4     40,00%   2013-05-02 17:46:24     N     x4    |
 |    5     50,00%   2013-05-02 20:33:04     Y     x5    |
 `-------------------------------------------------------'

=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://rt.cpan.org/Public/Dist/Display.html?Name=Text-ANSITable>

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) 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
