Acme-Curses-Marquee

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

Acme-Curses-Marquee

This module implements a big, stupid, OO, curses-based, scrolling
marquee. Woooo!

Check out the included 'scrolly' test script, which has 2 independent
marquees to play with, if you'd like to see A::C::M in action before
installing the module (but don't set a font before setting some text
on a marquee).


INSTALLATION

To install this module, run the following commands:

    perl Makefile.PL
    make
    make test

lib/Acme/Curses/Marquee.pm  view on Meta::CPAN


    # curses halfdelay mode is what actually drives the display
    # and its argument is what determines the rate of the crawl
    halfdelay(1);

    # spawn subwindow to hold marquee and create marquee object
    my $mw = subwin(9,80,0,0);
    my $m = Acme::Curses::Marquee->new( window => $mw,
                                        height => 9,
                                        width  => 80,
                                        font   => larry3d,
                                        text   => 'hello, world' );

    # then, in the event loop
    while (1) {
        my $ch = getch;
        do_input_processing_and_other_crud();
        $m->scroll;
    }

=head1 METHODS

lib/Acme/Curses/Marquee.pm  view on Meta::CPAN

Creates a new A::C::M object. Three arguments are required:

    * window
    * height
    * width

C<window> should be a curses window that the marquee can write
to. C<height> and C<width> should be the height and width of that
window, in characters.

There are also two optional arguments: C<font>, which sets the figlet
font of the marquee (defaults to the figlet default, 'standard'), and
C<text> which will set an initial string to be displayed and cause the
marquee to start display as soon as it is created.

=cut

sub new {
    my ($class,%args) = @_;

    die "Can't create marquee object without a host window\n" 
        unless( defined $args{window} );
    die "Can't create marquee object without height value\n" 
        unless( defined $args{height} );
    die "Can't create marquee object without width value\n" 
        unless( defined $args{width} );

    my $self = bless { win    => $args{window},
                       height => $args{height},
                       width  => $args{width},
                       font   => $args{font} || 'standard',
                       srctxt => $args{text} || undef, 
                       figtxt => '',
                       txtlen => 0,
                       offset => 0,
                       active => 0,
                     }, $class;

    $self->text($self->{srctext}) if (defined $self->{srctxt});

    return $self;

lib/Acme/Curses/Marquee.pm  view on Meta::CPAN

   $m->text("New line of text");

...render it via figlet, split it into an array, and perform width
adjustments as neccessary. Store the new text, figleted text, length
of figleted text lines, and set marquee state to active.

=cut

sub text {
    my ($self,$text) = @_;
    my $font  = $self->{font};
    my $width = length($text) * 12;
    my $line  = 0;

    # render text via figlet
    my @fig = split(/\n/,`figlet -f $font -w $width '$text'`);

    # find longest line length
    foreach my $i (0..(@fig - 1)) {
        $line = length($fig[$i]) if (length($fig[$i]) > $line);
    }

    # set line length to window width if shorter than that
    $line = $self->{width} if ($line < $self->{width});

    # pad all lines window width or longest length + 5

lib/Acme/Curses/Marquee.pm  view on Meta::CPAN

        $fig[$i] = join('',$fig[$i],(' 'x $pad));
    }
    
    $self->{active} = 1;
    $self->{offset} = 0;
    $self->{srctxt} = $text;
    $self->{txtlen} = length($fig[0]);
    $self->{figtxt} = \@fig;
}

=head2 font

Sets the font of the marquee object and then calls C<text> to make the
display change.

    $m->font('univers')

This method should not be called before the marquee object is active.
No checking is done to ensure the spacified font exists.

=cut

sub font {
    my ($self,$font) = @_;
    $self->{font} = $font;
    $self->text($self->{srctxt});
}

=head2 is_active

Returns the marquee object's status (whether text has been set or not)

=cut

sub is_active {

scrolly  view on Meta::CPAN


initscr;
halfdelay(1);
noecho;

$scr1 = subwin(9,COLS,0,0);
$scr2 = subwin(9,COLS,9,0);
$cli = subwin(3,80,18,0);

addstr(21,0,"'/1 TEXT' or '/2 TEXT' to set top/bottom marquee texts");
addstr(22,0,"'/f1 FONT' or '/f2 FONT' to set top/bottom marquee fonts");
addstr(23,0,"/q to quit");
box($cli,ACS_VLINE,ACS_HLINE);
refresh();

$m1 = Acme::Curses::Marquee->new( window => $scr1,
                                  height => 9,
                                  width  => COLS );

$m2 = Acme::Curses::Marquee->new( window => $scr2,
                                  height => 9,

scrolly  view on Meta::CPAN

        endwin;
        exit;
    } elsif ($string =~ /^\/1 /) {
        $string =~ s|^/1 ||;
        $m1->text($string);
    } elsif ($string =~ /^\/2 /) {
        $string =~ s|^/2 ||;
        $m2->text($string);
    } elsif ($string =~ /^\/f1 /) {
        $string =~ s|^/f1 ||;
        $m1->font($string);
    } elsif ($string =~ /^\/f2 /) {
        $string =~ s|^/f2 ||;
        $m2->font($string);
    }
}



( run in 1.864 second using v1.01-cache-2.11-cpan-ceb78f64989 )