PDA

View Full Version : Color Program (no help required)



Lynux-Penguin
04-27-2002, 01:20 PM
because these forums are mainly used for help, I wanted to enrich the environment with a little program I am working on, I have one that has more code but this is the program before I added to it. A nice color interface!



#include <stdio.h>

#define RESET 0
#define BRIGHT 1
#define DIM 2
#define UNDERLINE 3
#define BLINK 4
#define REVERSE 7
#define HIDDEN 8

#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7

void textcolor(int attr, int fg, int bg);
int main()
{
char ans;
system("clear");
printf("\t\t\t\t");
textcolor(BRIGHT,BLUE,BLACK);
printf("Welcome!");
textcolor(RESET,WHITE,BLACK);
printf("\nTest!\n");
// Menu plus more functions here
printf("Do you want to continue? [y/n]: ");
scanf("%c",&ans);
printf("%c\n",ans);
if(ans == 'y' )
{
printf("good!"); //more code here
}
else
{
printf("bad!"); // more code here
}
printf("\n");
return 0;
}

void textcolor(int attr, int fg, int bg)
{ char command[13];

/* Command is the control command to the terminal */
sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
printf("%s", command);
}
// more functions here

//basically I commented out the stuff I had in the bigger program



the original source was found on some website, I will post it as soon as I find it, the true author of textcolor() should get credit.

Xterria
05-05-2002, 04:25 PM
you forgot to include stdlib.h!!!!!
you should be punished.
anyway, it's cool...it gives attitude to my konsole

stautze
05-06-2002, 04:35 AM
If you didn't write textcolor, what did you write that is so great besides a poor yes/no interface. Try this:



typedef enum boolean { FALSE, TRUE } Boolean;

Boolean UserSaysYes(void)
{
int c;

printf(" (y,n)? ");
do {
while ((c = getchar()) == '\n');
if (c == 'y' || c == 'Y' || c == 'n' || c == 'N')
return (c == 'y' || c == 'Y');
printf("Please respond by typing one of the letters y or n\n");
} while (1);
}

Xterria
05-06-2002, 06:54 PM
we can all see your trying to look cool by putting in complecated code, right?
WELL IT AINT WORKIN

Lynux-Penguin
05-06-2002, 11:51 PM
oh thats nice, but thats not complicated.
Want to see my EDUMP Module for the 2.2 Kernel?

stautze
05-07-2002, 12:05 AM
>we can all see your trying to look cool by putting in complecated code, right?

yep

stautze
05-07-2002, 12:20 AM
BTW LP no offense intended, it was three in the morning and homework was taking me way longer than I expected. I thought I had seen that code in a linux mag somewhere, and I was just trying to be an arse. Not necessary...

Lynux-Penguin
05-07-2002, 12:20 AM
actually, that wasn't my intention...
I posted it because I was really bored, so I searched for something interesting on linux programming and added a line or two and posted it, just a reason to post something. (Hint: wanted to reach Senior Member sooner)

the code really isn't complicated if you read the article that came with it.
no, here is something complicated...
(not really, just annoying)


#include <stdio.h>
int main()
{
int x,_x,__x,x__;printf("\n"); scanf("%d",&_x);scanf("%d",&__x);x__ = __x++;
x = (_x++) - (__x - x__);if(x>__x){ return 0; } for(;x<__x;x++){ if(x = __x-1)
{ printf("\ndone\n");}}
return 0;
}

sorry if I am annoying anyone, I am really bored.

Lynux-Penguin
05-07-2002, 12:22 AM
Originally posted by Xterria
you forgot to include stdlib.h!!!!!
you should be punished.
anyway, it's cool...it gives attitude to my konsole

umm, on my compiler.... stdlib.h isn't required for this program to run or compile succesfully.

Unregistered
05-08-2002, 03:51 PM
Originally posted by Xterria
you forgot to include stdlib.h!!!!!
you should be punished.
anyway, it's cool...it gives attitude to my konsole

^lamer!

dont worry bout this kid all he posts is garbage...