BBS-Perm
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/BBS/Perm/Term.pm view on Meta::CPAN
bless $self, ref $class || $class;
}
sub init { # initiate a new term
my ( $self, $conf ) = @_;
my $term = Gnome2::Vte::Terminal->new;
push @{ $self->{terms} }, $term;
push @{ $self->{titles} }, $conf->{title}
|| $conf->{username} . '@' . $conf->{site};
push @{ $self->{encoding} }, $conf->{encoding};
if ( defined $self->{current} ) { # has term already?
$self->term->hide;
}
$self->{current} = $#{ $self->{terms} };
$self->widget->pack_start( $self->term, TRUE, TRUE, 0 );
$self->term->show;
$self->term->grab_focus;
if ( $conf->{encoding} ) {
$term->set_encoding( $conf->{encoding} );
}
if ( $conf->{font} ) {
my $font = Pango::FontDescription->from_string( $conf->{font} );
$term->set_font($font);
}
if ( $conf->{color} ) {
my @elements = qw/foreground background dim bold cursor highlight/;
for (@elements) {
if ( $conf->{color}{$_} ) {
no strict 'refs';
"Gnome2::Vte::Terminal::set_color_$_"->(
$term, Gtk2::Gdk::Color->parse( $conf->{color}{$_} )
);
}
}
}
if ( $conf->{background_file} && -e $conf->{background_file} ) {
$term->set_background_image_file( $conf->{background_file} );
}
if ( $conf->{background_transparent} ) {
$term->set_background_transparent(1);
}
if ( defined $conf->{opacity} ) {
$conf->{opacity} *= 65535 if $conf->{opacity} <= 1;
$term->set_opacity($conf->{opacity});
}
if ( defined $conf->{mouse_autohide} ) {
$term->set_mouse_autohide( $conf->{mouse_autohide} );
}
my $timeout = defined $conf->{timeout} ? $conf->{timeout} : 60;
if ($timeout) {
$term->{timer} = Glib::Timeout->add( 1000 * $timeout,
sub { $term->feed_child( chr 0 ); return TRUE; }, $term );
}
}
sub clean { # called when child exited
my $self = shift;
my ( $current, $new_pos );
$new_pos = $current = $self->{current};
if ( @{ $self->{terms} } > 1 ) {
if ( $current == @{ $self->{terms} } - 1 ) {
$new_pos = 0;
}
else {
$new_pos++;
}
$self->term->hide;
$self->{terms}->[$new_pos]->show;
$self->{terms}->[$new_pos]->grab_focus;
}
else {
undef $new_pos;
}
$self->widget->remove( $self->term );
$self->term->destroy;
splice @{ $self->{terms} }, $current, 1;
$self->{current} = $new_pos == 0 ? 0 : $new_pos - 1
if defined $new_pos;
}
sub term { # get current terminal
my $self = shift;
return $self->{terms}->[ $self->{current} ]
if defined $self->{current};
}
sub switch { # switch terms, -1 for left, 1 for right
my ( $self, $offset ) = @_;
return unless $offset;
return unless @{ $self->{terms} } > 1;
my ( $current, $new_pos );
$new_pos = $current = $self->{current};
if ( $offset == 1 ) {
if ( $current >= @{ $self->{terms} } - 1 ) {
$new_pos = 0;
}
else {
$new_pos++;
}
}
elsif ( $offset == -1 ) {
if ( $current == 0 ) {
$new_pos = @{ $self->{terms} } - 1;
}
else {
$new_pos--;
}
}
$self->term->hide if defined $self->term;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.152 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )