home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 205_01 / color.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-12-31  |  2.4 KB  |  88 lines

  1.  
  2. /*
  3. HEADER:                 CUG205.00;
  4. TITLE:                  MSBASIC-like COLOR command;
  5. DATE:                   06/24/86;
  6. DESCRIPTION:
  7.   "Changes the colors of text on PC-Clones.
  8.    Supplier help screen; available by entering
  9.    the color command without parameters.";
  10. KEYWORDS:               Color, ANSI;
  11. SYSTEM:                 MS-DOS;
  12. FILENAME:               COLOR.C;
  13. WARNINGS:
  14.                         "Requires ANSI.SYS";
  15. AUTHORS:                 Michael M. Yokoyama;
  16. COMPILERS:              Microsoft;
  17. */
  18. static char *progid = { "color.c by Michael Yokoyama" };
  19. /*      COLOR.C
  20.  
  21.     by Michael M. Yokoyama
  22.  
  23.     Selects text colors for use in MS/PC-DOS.
  24.  
  25.     This program uses ANSI escape sequences.  To use this program, you 
  26.     must have the file named ANSI.SYS on the root directory of your boot 
  27.     disk, and the following statement in your CONFIG.SYS file.
  28.  
  29.         device=ANSI.SYS
  30. */ 
  31.  
  32. #include <stdio.h>
  33. #define ESC 27
  34.  
  35. main(argc, argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.     if ((argc == 1) || (argc > 3 )) {
  40.         help();
  41.         exit(1);
  42.     }
  43.     if (argv[1][1] == '+') {
  44.         printf("%c[0m",ESC);
  45.         printf("%c[1m",ESC);
  46.     } 
  47.     else printf("%c[0m",ESC);
  48.     printf("%c[3%cm",ESC,*argv[1]);
  49.     if (argv[2] == NULL ) {
  50.         printf("%c[2J",ESC);    
  51.         exit(1);
  52.     }
  53.     printf("%c[4%cm",ESC,*argv[2]);
  54.     printf("%c[2J",ESC);    
  55. }
  56.  
  57. help()
  58. {
  59.     int c;
  60.     printf("%c[2J%c[0;43;30mUsage:  COLOR <foreground>[+] [<background>]\n",ESC,ESC);    
  61.     printf("  COLOR 0 3    Black on yellow\n");
  62.     printf("Default:    The background color code may be omitted; the default is black.\n");
  63.     printf("  COLOR 4      Blue (on default black)\n");
  64.     printf("%c[0;43;30mNormal color codes:\n",ESC);
  65.     for (c = 40; c <= 47; c++) {
  66.         printf("%c[0;%d;30m",ESC,c);
  67.         colors();
  68.         printf("\n");
  69.     }
  70.     printf("%c[0;43;30mHighlight:  Append a plus (+) after the foreground code to highlight the color.\n",ESC); 
  71.     printf("  COLOR 2+ 4   Bright green on blue\n");
  72.     printf("Highlight color codes:\n");
  73.     for (c = 40; c <= 46; c++) {
  74.         printf("%c[1;%d;30m",ESC,c);
  75.         colors();
  76.         printf("\n");
  77.     }
  78.     printf("%c[1;47;30m",ESC,c);
  79.     colors();
  80.     printf("%c[0;43;30m",ESC);
  81. }
  82.  
  83. colors()
  84. {
  85.     printf("%c[30m Black: 0  %c[31mRed: 1  %c[32mGreen: 2  %c[33mYellow: 3  ",ESC,ESC,ESC,ESC);
  86.     printf("%c[34mBlue: 4  %c[35mMagenta: 5  %c[36mCyan: 6  %c[37mWhite: 7 %c[0;43;30m",ESC,ESC,ESC,ESC,ESC);
  87. }
  88.