Created
April 11, 2020 22:00
-
-
Save rjbs/fccb42e8ddf586e679679b70d11a8ba8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v5.20.0; | |
| use warnings; | |
| use IO::Async; | |
| use IO::Async::Timer::Periodic; | |
| use Tickit::Async; | |
| use Tickit::Widget::Static; | |
| use Tickit::Widget::GridBox; | |
| use List::MoreUtils qw(natatime); | |
| my $tickit = Tickit::Async->new; | |
| my $box = Tickit::Widget::GridBox->new( | |
| style => { | |
| col_spacing => 2, | |
| row_spacing => 1, | |
| } | |
| ); | |
| my %status; | |
| for my $x (1 .. 100) { | |
| $status{$x} = Tickit::Widget::Static->new( | |
| text => sprintf(' % 4i ', $x), | |
| bg => "red", | |
| fg => "hi-white", | |
| align => "centre", | |
| valign => "middle", | |
| ); | |
| } | |
| my $iter = natatime 5, sort { $a <=> $b } keys %status; | |
| while (my @keys = $iter->()) { | |
| my @values = grep {; defined } @status{ @keys }; | |
| printf "Adding %i-widget row (%s)\n", 0+@values, join q{ }, @keys; | |
| $box->append_row([ grep {; defined } @status{ @keys } ]); | |
| } | |
| printf "Window: %i, %i\n", $tickit->rootwin->cols, $tickit->rootwin->lines; | |
| printf "Grid : %i, %i <%i by %i>\n", | |
| $box->requested_cols, $box->requested_lines, | |
| $box->colcount, $box->rowcount; | |
| exit 1 if $ENV{DEBUG}; | |
| $tickit->set_root_widget( $box ); | |
| my $loop = IO::Async::Loop->new; | |
| my $timer = IO::Async::Timer::Periodic->new( | |
| interval => 1, | |
| on_tick => sub { | |
| state $c = 0; | |
| $c++; | |
| my $i = 1 + int rand(100); | |
| $status{$i}->set_text("C: $c"); | |
| }, | |
| ); | |
| $timer->start; | |
| $loop->add($timer); | |
| $tickit->run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment