/*
 * Copyright (c) 2024 Ross Cunniff
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
using namespace oadl;

#include "libterm.oah"

proc main()
{
    using namespace term;

    Start(IS_COLOR, CAN_SCROLL);
    try {
        RawInput(1);
        CLS();
        GotoRC(5, 10);
        "Here at 5,10";

        Reverse(1);
        " -- reverse vid!";

        Reverse(0);
        "  Delta: \x394";

        GotoRC(6, 10);
        "IS_COLOR: ", Query(IS_COLOR);

        GotoRC(15,10);
        ColorPair(1,BLUE, BLACK);
        ColorPair(2,WHITE, BLACK);
        SetColor(1);
        Bold(1);
        "Press a key...";

        Flush();

        while (Getch() == NULL) {
        }

        ScrollRegion(11,20);
        for (var i = 0; i < 5; i++) {
            Scroll(-1);
            Flush();
            wait(250);
        }
        for (var i = 0; i < 5; i++) {
            Scroll(1);
            Flush();
            wait(250);
        }

        SetColor(2);
        Bold(0);
        GotoRC(16, 10); "EEOL: 12345";
        GotoRC(17, 10); "EEOS: 1";
        GotoRC(18, 10); "EEOS: 2";
        GotoRC(19, 10); "EEOS: 3";

        GotoRC(15, 25);
        Flush();

        while (Getch() == NULL) {
        }

        GotoRC(16, 15);
        EEOL();
        GotoRC(17, 15);
        EEOS();

        GotoRC(15, 10);
        "Press enter...";
        Flush();

        RawInput(0);
        var s = readstr();

        Stop();
    } catch(n) {
        Stop();
        say("Caught exception ", n, "\n");
    }

    say("Got here!\n");
    try {
        Start(-1);
    } catch(n) {
        say("Caught exception ", n, "\n");
    }
}