package TopGUI; use strict; use warnings; use Curses::UI::POE; use base qw( Object::Event ); use Moo; ########################################### sub start { ########################################### my( $self ) = @_; $self->{ cui } = Curses::UI::POE->new( -color_support => 1 ); $self->{ win } = $self->{ cui }->add("win_id", "Window"); my @loptions = qw( -width -1 -paddingspaces 1 -fg white -bg blue ); $self->{ top } = $self->{ win }->add( qw( top Label -y 0 ), @loptions, - text => "" ); $self->{ lbox } = $self->{ win }->add( qw( lb Listbox -padtop 1 -padbottom 1 -border 1 ), ); my $footer = "Type [c] to clear " . "counters [q] to quit"; $self->{ bottom } = $self->{ win }->add( qw( bottom Label -y -1), @loptions, -text => $footer ); $self->reg_cb( "update", sub { $self->update( @_ ); } ); $self->{ cui }->set_binding( sub { exit 0; }, "q"); $self->{ cui }->set_binding( sub { $self->event( "clear" ) }, "c"); $self->{ cui }->mainloop; } ########################################### sub update { ########################################### my( $self, $packets, $lines ) = @_; $self->{ top }->text( "Packets captured: $packets" ); $self->{ top }->draw(); $self->{ lbox }->{-values} = $lines; $self->{ lbox }->{-labels} = { map { $_ => $_ } @$lines }; $self->{ lbox }->draw(1); $self->{ bottom }->draw(); } 1;