/* Compile with cc -std=c11 -Wall -Wextra -Werror terminal.c -o terminal. */
#include <stdio.h>
#include <stdlib.h>

static void plot(int column, int row, int color, char mark)
{
    printf("\033[%d;%dH\033[%dm%c", column, row, color, mark /* TODO: map the terminal coordinates */);
}

static void restore_terminal(void)
{
    fputs("\033[0m\033[2J\033[H\033[?25h", stdout);
    fflush(stdout);
}

int main(void)
{
    if (atexit(restore_terminal) != 0) return 1;
    fputs("\033[2J\033[?25l", stdout);
    plot(2, 2, 36, 'A');
    plot(28, 10, 36, 'B');
    for (int row = 3; row <= 9; ++row)
        plot(15, row, 33, '*');
    fflush(stdout);
    (void)getchar();
    return ferror(stdin) ? 1 : 0;
}
