#!perl

our $DATE = '2021-02-19'; # DATE
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;
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.602 of ansitable-list-color-themes (from Perl distribution Text-ANSITable), released on 2021-02-19.

=head1 SYNOPSIS

 % ansitable-list-color-themes

Sample output:

 D:Data::Dump::Color::Default16
 D:Data::Dump::Color::Default256
 D:Data::Dump::Color::Light
 D:Distinct::WhiteBG
 D:GraphicsColorNames
 D:NoColor
 D:Test::Dynamic
 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                                                                    |
 |                                                                                                                            |
 | Data::Dump::Color::Default16                                                                                               |
 | Data::Dump::Color::Default256                                                                                              |
 | Data::Dump::Color::Light                                                                                                   |
 | Distinct::WhiteBG                               Pick some distinct colors (that are suitable for white background) for you |
 | GraphicsColorNames                              Display Graphics::ColorNames::* color scheme as color theme                |
 | NoColor (*)                                     An empty color theme that provides no items                                |
 | Test::Dynamic                                   A dynamic color theme                                                      |
 | 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%   2021-02-19 08:58:50     Y     hello |
 | -3.3    100,00%   2021-02-19 08:58:50     N     world |
 +-------------------------------------------------------+
 |    1     10,00%   2013-05-02 09:26:24     N     x1    |
 |    2     20,00%   2013-05-02 12:13:04     N     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     N     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://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