File: demo-colorwidget.pl

package info (click to toggle)
libtickit-perl 0.73-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 660 kB
  • sloc: perl: 4,944; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl

package ColourWidget;
use base 'Tickit::Widget';

use v5.14;
use warnings;

use Tickit;

my $text = "Press 0 to 7 to change the colour of this text";

sub lines { 1 }
sub cols  { length $text }

sub render_to_rb
{
   my $self = shift;
   my ( $rb, $rect ) = @_;

   my $win = $self->window;

   $rb->eraserect( $rect );

   $rb->text_at( ( $win->lines - $self->lines ) / 2, ( $win->cols - $self->cols ) / 2, $text );
}

sub on_key
{
   my $self = shift;
   my ( $args ) = @_;

   if( $args->type eq "text" and $args->str =~ m/[0-7]/ ) {
      $self->set_style( fg => $args->str );
      $self->redraw;
      return 1;
   }

   return 0;
}

Tickit->new( root => ColourWidget->new )->run;