#!/usr/bin/perl -w
#
# fusion figlet - running figlet text using fusionterm
#
# author: Max-Gerd Retzlaff <m.retzlaff@gmx.net>
#                           <mgr@hannover.ccc.de>
#
# date:    $Date: 2002/08/07 17:13:00 $
# version: $Revision: 1.3 $
#
# GnuPG-Information:
#  Fingerprint: 49CD 21F2 41AC 72C5 D0D1  27DC C2B2 48AE 8123 9F12
#  pub  1024D/81239F12 2002-03-12 Max-Gerd Retzlaff <m.retzlaff@gmx.net>
#  uid                            Max-Gerd Retzlaff <mgr@hannover.ccc.de>
#  sub  4096g/63E36E39 2002-03-12
#
# This application is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version. 
#
# This application is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111 USA.  

use termfusion;
set_clients_from_file("clients.fusion");
connect_clients();
$SIG{'INT'} = sub {exit();};
show_clients_info();
my ( $termcols, $termrows ) = get_global_dimensions();

my $file = $ARGV[0] || "fusion.input";
#$| = 1;

open(INFILE, "< $file") or
    die "ERROR: Couldn't open file \"$file\"for reading.\n";
# seek(INFILE,0,2);

END {
    close(INFILE);
}

clrscr;
printallcenter( "\e[?25l" );

my @figarray = ();
for( my $i = 0; $i <= $termrows; $i++ ) {
    push( @figarray, "" );
}

my ( $x, $y, $xmax, $ymax ) = ( 0, 0, 0, 0 );
while(1) {

foreach my $line ( <INFILE> ) {
    chomp( $line );
    push( @figarray,  $line );
    while ( scalar(@figarray) > $termrows ) {
	shift( @figarray );
    }

    for( $y = $#figarray; $y >= 1; $y-- ) {
	my $line = $figarray[$y];
	if ( defined( $figarray[$y-1] ) ) {
	    $oldlength = length( $figarray[$y-1] );
	    if ( $oldlength > length( $line ) ) {
		$line .= " " x ( $oldlength - length ($line) );
	    }
	}
	printsxy( 0, $y, $line, 1 );
    }
    flushallsendbuffers();
    # select( undef, undef, undef, 0.02 );
}
    # select( undef, undef, undef, 0.3 );
    # clrscr();
    # <STDIN>;

    sleep(1);
    seek(INFILE,0,1);
}


END {
    printallcenter( "\e[?25h" );
    clrscr();
    home();
    disconnect_clients();
 }
