[comp.sources.wanted] Xfortune?

jv@mh.nl (Johan Vromans) (03/22/90)

I'm looking for a X version of fortune(6). One that displays the
fortune message in a separate window, sized to the size of the
message.
Does there exist such a goodie?

Thanks for any info.

	Johan
--
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62944/62500
------------------------ "Arms are made for hugging" -------------------------

tchrist@convex.COM (Tom Christiansen) (03/23/90)

In article <JV.90Mar21094521@squirrel.mh.nl> jv@mh.nl (Johan Vromans) writes:
>I'm looking for a X version of fortune(6). One that displays the
>fortune message in a separate window, sized to the size of the
>message.
>Does there exist such a goodie?
>
>Thanks for any info.
>
>	Johan

There does now. :-)  Actually, it's not a "real" x program, but it's
good enough for me.  We just snarf in a fortune, take its measurements, 
and call up an xterm with the right dimensions.    Clip and call
"xfortune", and pass it fortune arguments, like -l and -a.


    #!/usr/bin/perl

    ($me = $0) =~ s,.*/,,;

    $FORTUNE = '/usr/games/fortune';
    $TMP = "/tmp/$me.$$";

    die "can't run $FORTUNE: $!" unless -x $FORTUNE;

    open (FORTUNE, "$FORTUNE @ARGV | expand |");
    while (<FORTUNE>) {
	$rows++;
	$cols = length if $cols < length;
	$fortune .= $_;
    } 
    (close FORTUNE) || die "bad pclose on $FORTUNE: $?";

    $rows++, $cols++;

    open (TMP, ">$TMP") || die "can't write $TMP: $!";
    print TMP $fortune;
    close TMP;

    system 'xterm', '-geometry', "${cols}x${rows}", 
	    '-n', 'xfort', 
	    '-e', 'less', '-P(hit q to quit)', $TMP;

    unlink $TMP;

--tom
--

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"

aperez@cvbnet.UUCP (Arturo Perez x6739) (03/24/90)

From article <JV.90Mar21094521@squirrel.mh.nl>, by jv@mh.nl (Johan Vromans):
> I'm looking for a X version of fortune(6). One that displays the
> fortune message in a separate window, sized to the size of the
> message.
> Does there exist such a goodie?
> 
> Thanks for any info.
> 
> 	Johan
> --
> Johan Vromans				       jv@mh.nl via internet backbones
> Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
> Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62944/62500
> ------------------------ "Arms are made for hugging" -------------------------

I've written a shell script that does more or less this.  It depends on your
having xmessage.  I actually use it for my .login.  Here it is.


#
clear
if (-x /usr/games/fortune) then
    set f=/tmp/fortune.$$
    /usr/games/fortune -a | sed 's@	@        @g'> $f
    if ($?DISPLAY) then
        set c=`awk '{ if (length > l) l = length } END { print l }' $f`
        set l=`cat $f | wc -l`
        set width=`expr $c \* 10`
        set height=`expr $l \* 25 + 38`
        xmessage -noprint -font lucidasans-18 -geometry ${width}x${height}+250+350 $f 
    else
	cat $f
    endif
    rm -f $f
endif

Arturo Perez
ComputerVision, a division of Prime
aperez@cvbnet.prime.com
Too much information, like a bullet through my brain -- The Police

caag@inf.rl.ac.uk (Crispin Goswell) (03/26/90)

In article <JV.90Mar21094521@squirrel.mh.nl> jv@mh.nl (Johan Vromans) writes:
>I'm looking for a X version of fortune(6). One that displays the
>fortune message in a separate window, sized to the size of the
>message.
>Does there exist such a goodie?

How about this five minute shell script? It could probably use some tidying up.
Type RETURN in the window to make it go away.

-------------------- cut here ----------------
#!/bin/sh

if [ $# = 0 ]
then
	TEMP=/tmp/xfortune$$ export TEMP
	/usr/games/fortune >$TEMP
	LINES=`wc -l <$TEMP`
	LINES=`echo $LINES`
	COLS=`awk -e '{ last = length ($0); if (widest < last) widest = last;} 
	END{if (last == widest) print widest+1; else print widest;}' $TEMP`
	xterm -geom ${COLS}x${LINES} -e $0 $TEMP $LINES
else
	head -"`expr $2 - 1`" $1
	echo -n "`tail -1 $1`"
	rm $1
	read foo
fi
-----------------------------------------------

Name:   Crispin Goswell                   |-------|__   Informatics Department
UUCP: {... | mcvax}!ukc!rlinf!caag        |  Tea  |  | Rutherford Appleton Lab
JANET: caag@uk.ac.rl.inf                  \  Mug  /_/          Chilton, Didcot
ARPA: caag%inf.rl.ac.uk@nsfnet-relay.ac.uk \_____/           Oxon OX11 0QX, UK

"Where are you when the Sun goes down? You're so far away from me."
        - Dire Straits
-- 

Name:   Crispin Goswell                   |-------|__   Informatics Department
UUCP: {... | mcvax}!ukc!rlinf!caag        |  Tea  |  | Rutherford Appleton Lab
JANET: caag@uk.ac.rl.inf                  \  Mug  /_/          Chilton, Didcot
ARPA: caag%inf.rl.ac.uk@nsfnet-relay.ac.uk \_____/           Oxon OX11 0QX, UK

"Where are you when the Sun goes down? You're so far away from me."
        - Dire Straits