viernes 4 de noviembre de 2011
A FALTA DE CONIO.H EN LINUX SIN UTILIZAR NCURSES.H
Revisando unos códigos descubrí uno que hace como un año no tocaba y se los comparto. La idea no es suplantar ncurses.h ni nada por el estilo, simple y llanamente el objetivo es crear fuentes con colores sin necesidad de ocupar librerías extras ni mandando parámetros diferentes al compilador.
Es una forma no tan convencional de enviar a la consola códigos de escapes para colores. Otro es una adaptación de lo que seria un "gotoxy". Basta con copiar este codigo y guardarlo (llamandolo "linux_console.h") en la misma carpeta de su código y posteriormente en sus programas agregarlo en su #include.
######################################################################
/*
* linux_console.c
*
* Copyright 2010 Ing. Noé López
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#define negro "\033[22;30m"
#define rojo "\033[22;31m"
#define verde "\033[22;32m"
#define cafe "\033[22;33m"
#define azul "\033[22;34m"
#define magenta "\033[22;35m"
#define cyan "\033[22;36m"
#define gris "\033[22;37m"
#define gris_oscuro "\033[01;30m"
#define rojo_claro "\033[01;31m"
#define verde_claro "\033[01;32m"
#define amarillo "\033[01;33m"
#define azul_claro "\033[01;34m"
#define magenta_claro "\033[01;35m"
#define cyan_claro "\033[01;36m"
#define blanco "\033[01;37m"
#define MAX_SCREEN_AREA 100
int gotoxy(int x, int y){
char essq[MAX_SCREEN_AREA]={0}; // String variable to hold the escape sequence
sprintf(essq, "\033[%d;%df", y,x);
printf("%s", essq);
return 0;
}
###################################################################
para utilizarlo acá un ejemplo:
###################################################################
#include <stdio.h>
#include "linux_console.c"//<-- noten como llamo a mi archivo
int main(int argc, char **argv){
printf(verde_claro);
gotoxy(3,6);
printf("Mi color es verde brillante");
printf(amarillo);
gotoxy(10,7);
printf("Mi color ahora es amarillo");
return 0;
}
##################################################################
Espero les sea de gran utilidad. Saludos.
Suscribirse a:
Comentarios de la entrada (Atom)

0 comentarios:
Publicar un comentario