#! /usr/bin/env python2

import time
import curses
import logging
import argparse

parser = argparse.ArgumentParser(description='Fun with curses')
parser.add_argument('-s', '--sleep', type=float, default=5, help='Sleep before exiting')
parser.add_argument('--vertical', action='store_true', help='Display characters vertically')
parser.add_argument('-v', '--verbose', action='store_true', help='Enable debugging')
args = parser.parse_args()

logging.basicConfig(format='%(asctime)s %(levelname)s %(pathname)s:%(lineno)d %(msg)s')
log = logging.getLogger()
log.setLevel(logging.DEBUG if args.verbose else logging.WARNING)

stdscr = curses.initscr()
curses.noecho()
curses.cbreak()

####################################################################

"""
Based on an example from https://docs.python.org/2/howto/curses.html
"""

c = 0
pad = curses.newpad(100, 100)
# These loops fill the pad with letters
for y in range(0, 100):
    for x in range(0, 100):
        try:
            # pad.addch(x if args.horizontal else y, y if args.horizontal else x, ord('a') + (x*x+y*y) % 26)
            pad.addch(x if args.vertical else y, y if args.vertical else x, ord('a') + c % 26)
            c += 1
        except curses.error:
            pass

# Displays a section of the pad in the middle of the screen
pad.refresh(0,0, 5,5, 20,75)

####################################################################

time.sleep(args.sleep)

curses.nocbreak()
stdscr.keypad(0)
curses.echo()
curses.endwin()
