home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / scrcolor.zip / ScrColor.cmd
OS/2 REXX Batch file  |  1993-11-17  |  10KB  |  231 lines

  1. /*
  2. program: ScrColor.cmd
  3. type:    REXXSAA-OS/2
  4. purpose: set default ANSI screen colors and allow REXX-programs to query them
  5.          (used e.g. by SHOWINI, CRONRGF, ATRGF)
  6. version: 1.0.0.0.1 :)
  7. date:    1993-09-20
  8. changed: 1993-11-17, merely added documentation, no functional changes
  9. author:  Rony G. Flatscher,
  10.          Wirtschaftsuniversität/Vienna
  11.          RONY@AWIWUW11.BITNET
  12.          Rony.Flatscher@wu-wien.ac.at
  13.  
  14. usage:   ScrColor [some string]
  15.          - if called from the command line the default background and 
  16.            foreground colors are set, additionally all defined colors
  17.            are shown; 
  18.            if any argument is given on the command line, the 
  19.            ANSI-escape-sequences are shown in addition (e.g. "ScrColor ?");
  20.  
  21.            e.g. add to your OS/2-CMD-WPS-objects the parameter: "/K ScrColor.CMD" 
  22.            or change systemwide (change CONFIG.SYS):
  23.  
  24.                SET OS2_SHELL=C:\OS2\CMD.EXE /K SCRCOLOR.CMD
  25.  
  26.          - if called as a function, the entire set of defined colors is
  27.            returned in a parsable string (see e.g. rxDecode.CMD, how a REXX-program 
  28.            can retrieve the presently active colors)
  29.  
  30. All rights reserved, copyrighted 1993 no guarantee that it works without
  31. errors, etc. etc.
  32.  
  33. donated to the public domain granted that you are not charging anything
  34. (money etc.) for it and derivates based upon it, as you did not write it,
  35. etc. if that holds you may bundle it with commercial programs too
  36.  
  37. Please, if you find an error, post me a message describing it, I will
  38. try to fix and rerelease it to the net.
  39.  
  40. **************
  41.  
  42. An excerpt from ANSI-escape-sequences as explained in:
  43.  
  44.  OS/2 Frequently Asked Questions List 
  45.  User's Edition 
  46.  Release 2.1C
  47.  August 28, 1993 
  48.  Compiled by Timothy F. Sipples 
  49.  
  50. For changes, suggestions, or additions please mail 
  51. sip1@kimbark.uchicago.edu or write:
  52.  
  53.   ESC[#;#;....;#m               Set display attributes where # is 
  54.                                  0 for normal display 
  55.                                  1 bold on 
  56.                                  4 underline (mono only) 
  57.                                  5 blink on 
  58.                                  7 reverse video on 
  59.                                  8 nondisplayed (invisible) 
  60.                                 30 black foreground 
  61.                                 31 red foreground 
  62.                                 32 green foreground 
  63.                                 33 yellow foreground 
  64.                                 34 blue foreground 
  65.                                 35 magenta foreground 
  66.                                 36 cyan foreground 
  67.                                 37 white foreground 
  68.                                 40 black background 
  69.                                 41 red background 
  70.                                 42 green background 
  71.                                 43 yellow background 
  72.                                 44 blue background 
  73.                                 45 magenta background 
  74.                                 46 cyan background 
  75.                                 47 white background 
  76.  
  77. remark: one can set a list of screen-attributes; if so, they need to be
  78.         delmited by a semi-colon (;); after the last sequence a little "m"
  79.         has to be attached to tell ANSI.SYS that colors are meant
  80. */
  81.  
  82. ESC    = '1B'x || "["   /* define ANSI-ESCape character */
  83.  
  84. /* ANSI-values for colors */
  85.  
  86. black   = 0
  87. red     = 1
  88. green   = 2
  89. yellow  = 3
  90. blue    = 4
  91. magenta = 5
  92. cyan    = 6
  93. white   = 7
  94.  
  95. /* ANSI-values for fore-/background */
  96. foreground = 30         /* add color, e.g. 30 + 2 = 32 ==> green foreground */
  97. background = 40         /* add color, e.g. 40 + 7 = 47 ==> white background */
  98.  
  99. /* additional ANSI-values which work on VGA */
  100. normal    = 0           /* reset screen to white on black */
  101. bold      = 1
  102. /************************** end of ANSI-information **************************/
  103.  
  104.  
  105.  
  106. /*******************************************************/
  107. /* default settings for WHITE TEXT on BLACK BACKGROUND */
  108. /*******************************************************/
  109.  
  110. screen_normal  = normal || ";" || foreground + white  || ";" || background + black
  111. screen_inverse = normal || ";" || foreground + black  || ";" || background + white
  112. text_normal    = screen_normal
  113. text_info      = screen_normal || ";" ||                foreground + cyan
  114. text_highlight = screen_normal || ";" ||                foreground + yellow
  115. text_alarm     = screen_normal || ";" || bold || ";" || foreground + red
  116. /* inverse colors */
  117. text_normal_inverse    = screen_inverse
  118. text_info_inverse      = screen_inverse || ";" ||                foreground + cyan
  119. text_highlight_inverse = screen_inverse || ";" ||                foreground + green
  120. text_alarm_inverse     = screen_inverse || ";" || bold || ";" || foreground + red
  121. /*******************************************************/
  122.  
  123.  
  124.  
  125. /*******************************************************/
  126. /* default settings for BLACK TEXT on WHITE BACKGROUND */
  127. /*******************************************************/
  128.  
  129. screen_normal  = normal || ";" || foreground + black  || ";" || background + white
  130. screen_inverse = normal || ";" || foreground + white  || ";" || background + black
  131. text_normal    = screen_normal
  132. text_info      = screen_normal || ";" || bold || ";" || foreground + blue
  133. text_highlight = screen_normal || ";" ||                foreground + green
  134. text_alarm     = screen_normal || ";" || bold || ";" || foreground + red
  135. /* inverse colors */
  136. text_normal_inverse    = screen_inverse
  137. text_info_inverse      = screen_inverse || ";" || bold || ";" || foreground + green
  138. text_highlight_inverse = screen_inverse || ";" || bold || ";" || foreground + cyan
  139. text_alarm_inverse     = screen_inverse || ";" || bold || ";" || foreground + red
  140. /*******************************************************/
  141.  
  142.  
  143.  
  144.  
  145. /*                        CHANGE COLORS FROM HERE                            */
  146. /*                                                                           */
  147. /*                  ||||||||||||||||||||||||||||||||||||                     */
  148. /*                  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV                     */
  149.  
  150. /****************** change according to your preferences *********************/
  151. /* attention: the following settings take effect !                           */
  152. /*            just copy the default you wish and change the colors           */
  153. /*****************************************************************************/
  154.  
  155. /*******************************************************/
  156. /* default settings for WHITE TEXT on BLACK BACKGROUND */
  157. /*******************************************************/
  158.  
  159. screen_normal  = normal || ";" || foreground + white  || ";" || background + black  
  160. screen_inverse = normal || ";" || foreground + black  || ";" || background + white  
  161. text_normal    = screen_normal
  162. text_info      = screen_normal || ";" ||                foreground + cyan
  163. text_highlight = screen_normal || ";" ||                foreground + yellow
  164. text_alarm     = screen_normal || ";" || bold || ";" || foreground + red
  165. /* inverse colors */
  166. text_normal_inverse    = screen_inverse 
  167. text_info_inverse      = screen_inverse || ";" ||                foreground + cyan
  168. text_highlight_inverse = screen_inverse || ";" ||                foreground + green
  169. text_alarm_inverse     = screen_inverse || ";" || bold || ";" || foreground + red   
  170. /*******************************************************/
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. /*******************************************************************************/
  179. /* add ESCape to begin and "m" to the end to complete the ANSI-Escape-sequence */
  180. screen_normal      = ESC || screen_normal       || "m"
  181. screen_inverse     = ESC || screen_inverse      || "m"
  182. text_normal        = ESC || text_normal         || "m"
  183. text_info          = ESC || text_info           || "m"
  184. text_highlight     = ESC || text_highlight      || "m"
  185. text_alarm         = ESC || text_alarm          || "m"
  186. text_normal_inverse    = ESC || text_normal_inverse     || "m"
  187. text_info_inverse      = ESC || text_info_inverse       || "m"
  188. text_highlight_inverse = ESC || text_highlight_inverse  || "m"
  189. text_alarm_inverse     = ESC || text_alarm_inverse      || "m"
  190.  
  191. PARSE SOURCE . called_as .
  192.  
  193. IF called_as = "COMMAND" THEN           /* called from command-line ? */
  194. DO
  195.    CALL CHAROUT ,screen_normal          /* set screen */
  196.    "Cls"                                /* Clear Screen via OS/2's CMD.EXE */
  197.    IF ARG(1) <> "" THEN                 /* if argument given, then show escape sequences */
  198.    DO
  199.       SAY
  200.       CALL CHAROUT ,screen_normal          /* set screen */
  201.       SAY RIGHT("screen_normal <ESC", 40)  || SUBSTR(screen_normal, 2)  || ">"
  202.       CALL CHAROUT ,text_normal    
  203.       SAY RIGHT("text_normal <ESC", 40)    || SUBSTR(text_normal, 2)    || ">"
  204.       CALL CHAROUT ,text_info      
  205.       SAY RIGHT("text_info <ESC", 40)      || SUBSTR(text_info, 2)      || ">"
  206.       CALL CHAROUT ,text_highlight 
  207.       SAY RIGHT("text_highlight <ESC", 40) || SUBSTR(text_highlight, 2) || ">"
  208.       CALL CHAROUT ,text_alarm     
  209.       SAY RIGHT("text_alarm <ESC", 40)     || SUBSTR(text_alarm, 2)     || ">"
  210.       CALL CHAROUT ,screen_inverse 
  211.       SAY RIGHT("screen_inverse <ESC", 40) || SUBSTR(screen_inverse, 2) || ">"
  212.       CALL CHAROUT ,screen_normal
  213.  
  214.       CALL CHAROUT ,text_normal_inverse
  215.       SAY RIGHT("text_normal_inverse <ESC", 40) || SUBSTR(text_normal_inverse, 2) || ">"
  216.       CALL CHAROUT ,text_info_inverse
  217.       SAY RIGHT("text_info_inverse <ESC", 40) || SUBSTR(text_info_inverse, 2) || ">"
  218.       CALL CHAROUT ,text_highlight_inverse
  219.       SAY RIGHT("text_highlight_inverse <ESC", 40) || SUBSTR(text_highlight_inverse, 2) || ">"
  220.       CALL CHAROUT ,text_alarm_inverse
  221.       SAY RIGHT("text_alarm_inverse <ESC", 40) || SUBSTR(text_alarm_inverse, 2) || ">"
  222.    END
  223.    CALL CHAROUT ,screen_normal          /* set screen */
  224. END
  225. ELSE RETURN screen_normal screen_inverse,
  226.             text_normal text_info,
  227.             text_highlight text_alarm,
  228.             text_normal_inverse text_info_inverse,
  229.             text_highlight_inverse text_alarm_inverse
  230.  
  231.