1#!/usr/bin/perl 2 3use v5.14; 4use warnings; 5 6use List::Util qw( min max ); 7 8use Tickit::Async; 9use IO::Async::Loop; 10use IO::Async::Timer::Periodic; 11 12my $loop = IO::Async::Loop->new; 13my $tickit = Tickit::Async->new; 14 15my $colour_offset = 0; 16my $rootwin = $tickit->rootwin; 17 18my $win = $rootwin->make_sub( 5, 5, $rootwin->lines - 10, $rootwin->cols - 10 ); 19$win->bind_event( expose => sub { 20 my ( $self, undef, $info ) = @_; 21 22 my $rb = $info->rb; 23 24 foreach my $line ( $info->rect->linerange ) { 25 $rb->text_at( $line, 0, "Here is some content for line $line " . 26 "X" x ( $self->cols - 30 ), 27 Tickit::Pen->new( fg => 1 + ( $line + $colour_offset ) % 6 ), 28 ); 29 } 30} ); 31 32# Logic to erase the borders 33$rootwin->bind_event( expose => sub { 34 my ( $self, undef, $info ) = @_; 35 36 my $rb = $info->rb; 37 my $rect = $info->rect; 38 39 foreach my $line ( $rect->top .. 4 ) { 40 $rb->erase_at( $line, 0, $self->cols ); 41 } 42 foreach my $line ( $self->lines-5 .. $rect->bottom-1 ) { 43 $rb->erase_at( $line, 0, $self->cols ); 44 } 45 if( $rect->left < 5 ) { 46 foreach my $line ( max( $rect->top, 4 ) .. min( $self->lines-5, $rect->bottom-1 ) ) { 47 $rb->erase_at( $line, 0, 5 ); 48 } 49 } 50 if( $rect->right > $self->cols-5 ) { 51 foreach my $line ( max( $rect->top, 4 ) .. min( $self->lines-5, $rect->bottom-1 ) ) { 52 $rb->erase_at( $line, $self->cols - 5, 5 ); 53 } 54 } 55} ); 56 57$loop->add( IO::Async::Timer::Periodic->new( 58 interval => 0.5, 59 on_tick => sub { 60 $colour_offset++; 61 $colour_offset %= 6; 62 $win->expose; 63 } )->start ); 64 65my $popup_win; 66 67$rootwin->bind_event( mouse => sub { 68 my ( $self, undef, $info ) = @_; 69 return unless $info->type eq "press"; 70 71 if( $info->button == 3 ) { 72 $popup_win->hide if $popup_win; 73 74 $popup_win = $rootwin->make_float( $info->line, $info->col, 3, 21 ); 75 $popup_win->pen->chattr( bg => 4 ); 76 77 $popup_win->bind_event( expose => sub { 78 my ( $self, undef, $info ) = @_; 79 80 my $rb = $info->rb; 81 $rb->text_at( 0, 0, "+-------------------+" ); 82 $rb->text_at( 1, 0, "| Popup Window Here |" ); 83 $rb->text_at( 2, 0, "+-------------------+" ); 84 } ); 85 86 $popup_win->show; 87 } 88 else { 89 $popup_win->hide if $popup_win; 90 undef $popup_win; 91 } 92}); 93 94$rootwin->expose; 95$tickit->run; 96