#include <iostream>
#include "Window.h"
#include "Runtime.h"
#include <memory>
#include "System.h"
#include "DefaultCommandMap.h"

int main(int argc, char * argv[])
{
    if (!System::init(argv))
    {
        return 1;
    }

    Runtime::init(System::executable_path().c_str(), APPNAME);
    DefaultCommandMap::build();

    const char * filename = nullptr;
    if (argc > 1)
    {
        filename = argv[1];
    }
    std::shared_ptr<Buffer> b = std::make_shared<Buffer>(filename);
    Window w;
    if (!w.create(b))
    {
        std::cerr << "Error creating window." << std::endl;
        return 1;
    }

    w.run_event_loop();

    return 0;
}
