home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 192_01 / color.c < prev    next >
Text File  |  1979-12-31  |  3KB  |  97 lines

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