#!/usr/bin/env python
""" Module "Habitica" : Main Driver Program

    The main program is launched from this module
"""

from habitican_curse import *
import logging

# Ability to display symbols
locale.setlocale(locale.LC_ALL, '')

def BookKeepingThread():
    try:
        G.content = CT.ContentManager()
    except:
        return

    # Set user stats now that content has been fetched
    G.user.attrStats = H.GetUserStats(G.user.data)
    G.user.PrintUserStats()

def main(curses_screen):

    #Initialize the logging facility
    dbg_level=C.getConfig("debug_lvl")
    dbg_file=C.getConfig("debug_file")

    if(dbg_file is not None):
        logging.basicConfig(filename=dbg_file,level=int(dbg_level))
    else:
        logging.basicConfig(level=int(dbg_level))


    G.screen = Screen(curses_screen)
    G.screen.Initialize()
    C.ConfigureRuntime(curses_screen)
    G.reqManager = RM.RequestManager()
    G.reqManager.FetchData()
    G.intf = I.Interface()
    G.intf.Init()
    bookThread = threading.Thread(target=BookKeepingThread)
    bookThread.start()
    #inputThread = threading.Thread(target=G.intf.Input)
    #inputThread.start()


    G.intf.Input()
    DEBUG.Display("Cleaning up...")
    bookThread.join()

if __name__ == "__main__":
    G.reqManager = RM.RequestManager()
    curses.wrapper(main)
