#!/usr/bin/env python
# Flinks
# Copyright (C) 2008 Martin Bays <mbays@sdf.lonestar.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see http://www.gnu.org/licenses/.

import sys, os
from string import *

import curses
from curses.wrapper import wrapper

import locale
locale.setlocale(locale.LC_ALL, '')

from flinkspkg.Browser import Browser, QuitException
from flinkspkg.Config import Config

if __name__ == "__main__":
    def go(scr, config):
        browser = Browser(scr, config)
        try:
            browser.mainLoop()
        except QuitException:
            pass
        browser.onExit()
        browser.writeState()

    config = Config()
    errCode = config.processArgs(sys.argv)
    if errCode is not None:
        sys.exit(errCode)

    if config.loadErrors:
        for error in config.loadErrors:
            print(error)
        print("[Enter to continue]")
        input()

    wrapper(go, config)
