#include <rtl.h>
#include <rtl_sched.h>
#include <posix/unistd.h>

static int terminal_fd;
static pthread_t pthread;

MODULE_AUTHOR("Miguel Masmano Tello <mmasmano@disca.upv.es>");
MODULE_DESCRIPTION("Example of use of the RT_Terminal");

MODULE_LICENSE("GPL");

void *main_func (void *att) {

  char str[] = "";

  char str1 [] = "This is the RT-TERMINAL\nTHIS component uses VT100 ESC commands.\x1B[3;0H\x1B[34;47mYou\x1B[31;44mcan\x1B[36;41mchange\x1B[30;42measily\x1B[34;47mthe\x1B[32;40mcolors\x1B[10;10H\x1B[34;43mOr you can move by the screen";

    write (terminal_fd, str1, strlen(str1));

  return 0;
}

int init_module (void) {
  terminal_fd = open ("/dev/rt_tty", O_NONBLOCK);
  if ("terminal_fd" < 0) {
    rtl_printf ("Error opening RT_Terminal\n");
    return -1;
  }
  pthread_create (&pthread, NULL, main_func, 0);
  return 0;
}

void cleanup_module (void) {
  close (terminal_fd);
}
