#!/usr/bin/env python
# coding: latin-1

import sys, os
import curses, time, color, random

class Stuff: pass
stuff = Stuff()

def curses_init(stdscr):
	curses.curs_set(0)
	stdscr.leaveok(1)
	color.init_colors()

def random_position(scr):
	max_y, max_x = scr.getmaxyx()
	x = random.randint(0, max_x - 1)
	y = random.randint(0, max_y - 1)
	if x == max_x - 1 and y == max_y - 1:
		return random_position(scr)
	return x, y

def random_star():
	return random.choice(".,`'+*x")

def random_color():
	return random.choice(color.clut)

def random_blabber(scr):
	x, y = random_position(scr)
	line = stuff.blabber.readline()
	try: scr.addstr(y, x, line)
	except: pass

def update(scr):
	x, y = random_position(scr)
	scr.addch(y, x, random_star(), random_color())
	for _ in range(27):
		x, y = random_position(scr)
		scr.addch(y, x, ' ')
	if not random.randint(0, 20): random_blabber(scr)

def run(stdscr):
	curses_init(stdscr)
	while True:
		time.sleep(1)
		update(stdscr)
		stdscr.refresh()

def main():
	stuff.blabber = os.popen(sys.argv[1], "r")
	curses.wrapper(run)

if __name__ == '__main__': main()
