#include "curses_output.h"

#include "constants.h"

curses_output::curses_output(cursor *new_curse):
        curse{new_curse} {}

void curses_output::render() {
        curse->show();
}

std::string BLANK(DISPLAY_BUFFER_SIZE, ' ');

void curses_output::clear() {
        print_str({0, 0}, BLANK, A_NORMAL);
}

void curses_output::print_char(const position &pos, const char ch,
                               const int attrs) {
        if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
                return;

        curse->print_char(pos, ch, attrs);
}

void curses_output::print_str(const position &pos, const std::string &str,
                              const int attrs) {
        if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
                return;

        position tmp = pos;

        for (std::size_t i = 0; i < str.length(); ++i) {
                curse->print_char(tmp, str[i], attrs);
                tmp += {1, 0};

                if (tmp.x >= DISPLAY_WIDTH)
                        tmp = {0, tmp.y + 1};
        }
}
