File: demo-showkey.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 (41 lines) | stat: -rw-r--r-- 627 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
#!/usr/bin/perl

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

use v5.14;
use warnings;

use Tickit;

my $text;

sub lines {  1 }
sub cols  { 10 }

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

   my $win = $self->window;

   $rb->goto( ( $win->lines - $self->lines ) / 2, ( $win->cols - $self->cols ) / 2 );
   $rb->text( $text ) if defined $text;
   $rb->erase_to( $win->cols );

   $win->cursor_at( 0, 0 );
}

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

   $text = join ": ", $args->type, $args->str;
   $self->redraw;

   return 0;
}

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