#!/usr/bin/python

# credits = Copyright (c) 2002, 2003 John Morton.
#
# Permission to use, copy, modify, distribute, and sell this software and
# its documentation for any purpose is hereby granted without fee, 
# provided that the above copyright notice appear in all copies and that 
# both that copyright notice and this permission notice appear in supporting
# documentation.  No representations are made about the suitability of this
# software for any purpose.  It is provided "as is" without express or 
# implied warranty.

"""
Sort of like subtitles, but this one reads from stdin, and displays
them along the middle. 
"""

import sys, os, time

command = 'yaf-splash -transparent -bw 0 -timeout 3 -font \"-adobe-helvetica-bold-r-normal-*-*-180-*-*-p-*-*-1\" -text "%s" >/dev/null'


for line in sys.stdin.xreadlines():
    line = line.rstrip()
    if line == "":
        # Blank lines act as a pause.
        time.sleep(2)
    else:
        # escape any double quotes and dollars
        line = line.replace('"','\\\"')
        line = line.replace("$","\\\$")            
        res = os.system(command % line)        
        if res << 8 != 0:
            # yaf-splash was killed by some signal
            sys.exit(1)
        elif res >> 8 != 0:
            # yaf-splash died for some other reason
            sys.exit(1)

            
