/* 
 *    Programmed By: Mohammed Isam Mohammed [mohammed_isam1984@yahoo.com]
 *    Copyright 2014 (c)
 * 
 *    file: screen.c
 *    This file is part of mino (Mino).
 *
 *    mino (Mino) is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    mino (Mino) is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with mino (Mino).  If not, see <http://www.gnu.org/licenses/>.
 */    

#include "defs.h"
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>	//included for terminal size query

void setScreenColors(int FG, int BG) 
{
  fprintf(stdout, "\x1b[%d;%dm", FG, BG);	//control sequence to set screen color
}

void getScreenSize() 
{
 struct winsize w;
 ioctl(0, TIOCGWINSZ, &w);	//find the size of the view
 //printf("Rows: %d\n", w.ws_row);
 //printf("Cols: %d\n", w.ws_col);
 SCREEN_H = w.ws_row;
 SCREEN_W = w.ws_col;
}

void clearScreen() 
{
 /*char *cls = "\x1b[2J";	//console control sequence: ESC[2J (ESC = 27 Dec = Hex "1b")
 int clsLen = strlen(cls);
 //call it volatile to force the compiler to put asm code in this place, no optimizations
 __asm__ __volatile__ (
   "movl $4, %%eax\n\
   movl $1, %%ebx\n\
   int $0x80"
   ://output registers goes here -- if any
   :"d"(clsLen),"c"(cls)	//input vars (in braces) put into registers "in quotes"
   ://registers whose contents are not valid any more goes here -- if any
 );
 */
 fprintf(stdout, "\x1b[2J");
 fprintf(stdout, "\x1b[37;4m");
 fprintf(stdout, "\e[3J\e[1;1H");
}
