#!/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:26:02 $
# version: $Revision: 1.4 $
#
# 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 $figlet = "/usr/bin/figlet";
my $figlet_options = "-w 1000000"; # $termcols";
my $font = "figletfont/univers";
my $text = $ARGV[0] || "this is fusion figlet";
my $figtext = qx($figlet -f $font $figlet_options $text);
$| = 1;
my @figarray = ();
my ( $x, $y, $xmax, $ymax ) = ( 0, 0, 0, 0 );

foreach my $line ( split( "\n", $figtext ) ) {
    $figarray[$y] = $line;
    $x = length( $line ) - 1;
    $xmax = $x if ( $x > $xmax );

    $x = 0;
    $ymax = $y if ( $y > $ymax );
    $y++;
}

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

my $yswab = int( ( $termrows - $ymax ) / 2 );

for( my $xswab = 0 - $xmax; ; $xswab = ( $xswab > $termcols )?0-$xmax:$xswab+1 ) {

    for( $y = 0; $y <= $#figarray; $y++ ) {
	printxy( $xswab - 1, $y + $yswab, " ", 1 );
	printsxy( $xswab, $y + $yswab, $figarray[$y], 1 );
    }
    flushallsendbuffers();

    # select( undef, undef, undef, 0.02 );
    # clrscr();
    # <STDIN>;
}

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