curs_color.3x.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  2. <!--
  3. ****************************************************************************
  4. * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. *
  5. * *
  6. * Permission is hereby granted, free of charge, to any person obtaining a *
  7. * copy of this software and associated documentation files (the *
  8. * "Software"), to deal in the Software without restriction, including *
  9. * without limitation the rights to use, copy, modify, merge, publish, *
  10. * distribute, distribute with modifications, sublicense, and/or sell *
  11. * copies of the Software, and to permit persons to whom the Software is *
  12. * furnished to do so, subject to the following conditions: *
  13. * *
  14. * The above copyright notice and this permission notice shall be included *
  15. * in all copies or substantial portions of the Software. *
  16. * *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  20. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  21. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  23. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  24. * *
  25. * Except as contained in this notice, the name(s) of the above copyright *
  26. * holders shall not be used in advertising or otherwise to promote the *
  27. * sale, use or other dealings in this Software without prior written *
  28. * authorization. *
  29. ****************************************************************************
  30. * @Id: curs_color.3x,v 1.28 2005/12/18 00:00:37 tom Exp @
  31. -->
  32. <HTML>
  33. <HEAD>
  34. <TITLE>curs_color 3x</TITLE>
  35. <link rev=made href="mailto:bug-ncurses@gnu.org">
  36. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  37. </HEAD>
  38. <BODY>
  39. <H1>curs_color 3x</H1>
  40. <HR>
  41. <PRE>
  42. <!-- Manpage converted by man2html 3.0.1 -->
  43. <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG> <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
  44. </PRE>
  45. <H2>NAME</H2><PRE>
  46. <STRONG>start_color</STRONG>, <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>, <STRONG>has_colors</STRONG>,
  47. <STRONG>can_change_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>, <STRONG>COLOR_PAIR</STRONG>
  48. - <STRONG>curses</STRONG> color manipulation routines
  49. </PRE>
  50. <H2>SYNOPSIS</H2><PRE>
  51. <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
  52. <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
  53. <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
  54. <STRONG>int</STRONG> <STRONG>init_color(short</STRONG> <STRONG>color,</STRONG> <STRONG>short</STRONG> <STRONG>r,</STRONG> <STRONG>short</STRONG> <STRONG>g,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
  55. <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
  56. <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
  57. <STRONG>int</STRONG> <STRONG>color_content(short</STRONG> <STRONG>color,</STRONG> <STRONG>short</STRONG> <STRONG>*r,</STRONG> <STRONG>short</STRONG> <STRONG>*g,</STRONG> <STRONG>short</STRONG>
  58. <STRONG>*b);</STRONG>
  59. <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
  60. </PRE>
  61. <H2>DESCRIPTION</H2><PRE>
  62. <STRONG>Overview</STRONG>
  63. <STRONG>curses</STRONG> support color attributes on terminals with that ca-
  64. pability. To use these routines <STRONG>start_color</STRONG> must be
  65. called, usually right after <STRONG>initscr</STRONG>. Colors are always
  66. used in pairs (referred to as color-pairs). A color-pair
  67. consists of a foreground color (for characters) and a
  68. background color (for the blank field on which the charac-
  69. ters are displayed). A programmer initializes a color-
  70. pair with the routine <STRONG>init_pair</STRONG>. After it has been ini-
  71. tialized, <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>), a macro defined in <STRONG>&lt;curses.h&gt;</STRONG>,
  72. can be used as a new video attribute.
  73. If a terminal is capable of redefining colors, the pro-
  74. grammer can use the routine <STRONG>init_color</STRONG> to change the defi-
  75. nition of a color. The routines <STRONG>has_colors</STRONG> and
  76. <STRONG>can_change_color</STRONG> return <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>, depending on
  77. whether the terminal has color capabilities and whether
  78. the programmer can change the colors. The routine <STRONG>col-</STRONG>
  79. <STRONG>or_content</STRONG> allows a programmer to extract the amounts of
  80. red, green, and blue components in an initialized color.
  81. The routine <STRONG>pair_content</STRONG> allows a programmer to find out
  82. how a given color-pair is currently defined.
  83. <STRONG>Routine</STRONG> <STRONG>Descriptions</STRONG>
  84. The <STRONG>start_color</STRONG> routine requires no arguments. It must be
  85. called if the programmer wants to use colors, and before
  86. any other color manipulation routine is called. It is
  87. good practice to call this routine right after <STRONG>initscr</STRONG>.
  88. <STRONG>start_color</STRONG> initializes eight basic colors (black, red,
  89. green, yellow, blue, magenta, cyan, and white), and two
  90. global variables, <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG> (respectively
  91. defining the maximum number of colors and color-pairs the
  92. terminal can support). It also restores the colors on the
  93. terminal to the values they had when the terminal was just
  94. turned on.
  95. The <STRONG>init_pair</STRONG> routine changes the definition of a color-
  96. pair. It takes three arguments: the number of the color-
  97. pair to be changed, the foreground color number, and the
  98. background color number. For portable applications:
  99. - The value of the first argument must be between <STRONG>1</STRONG> and
  100. <STRONG>COLOR_PAIRS-1</STRONG>.
  101. - The value of the second and third arguments must be
  102. between 0 and <STRONG>COLORS</STRONG>. Color pair 0 is assumed to be
  103. white on black, but is actually whatever the terminal
  104. implements before color is initialized. It cannot be
  105. modified by the application.
  106. If the color-pair was previously initialized, the screen
  107. is refreshed and all occurrences of that color-pair are
  108. changed to the new definition.
  109. As an extension, ncurses allows you to set color pair 0
  110. via the <STRONG>assume_default_colors</STRONG> routine, or to specify the
  111. use of default colors (color number <STRONG>-1</STRONG>) if you first in-
  112. voke the <STRONG>use_default_colors</STRONG> routine.
  113. The <STRONG>init_color</STRONG> routine changes the definition of a color.
  114. It takes four arguments: the number of the color to be
  115. changed followed by three RGB values (for the amounts of
  116. red, green, and blue components). The value of the first
  117. argument must be between <STRONG>0</STRONG> and <STRONG>COLORS</STRONG>. (See the section
  118. <STRONG>Colors</STRONG> for the default color index.) Each of the last
  119. three arguments must be a value between 0 and 1000. When
  120. <STRONG>init_color</STRONG> is used, all occurrences of that color on the
  121. screen immediately change to the new definition.
  122. The <STRONG>has_colors</STRONG> routine requires no arguments. It returns
  123. <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise, it
  124. returns <STRONG>FALSE</STRONG>. This routine facilitates writing terminal-
  125. independent programs. For example, a programmer can use
  126. it to decide whether to use color or some other video at-
  127. tribute.
  128. The <STRONG>can_change_color</STRONG> routine requires no arguments. It
  129. returns <STRONG>TRUE</STRONG> if the terminal supports colors and can
  130. change their definitions; other, it returns <STRONG>FALSE</STRONG>. This
  131. routine facilitates writing terminal-independent programs.
  132. The <STRONG>color_content</STRONG> routine gives programmers a way to find
  133. the intensity of the red, green, and blue (RGB) components
  134. in a color. It requires four arguments: the color number,
  135. and three addresses of <STRONG>short</STRONG>s for storing the information
  136. about the amounts of red, green, and blue components in
  137. the given color. The value of the first argument must be
  138. between 0 and <STRONG>COLORS</STRONG>. The values that are stored at the
  139. addresses pointed to by the last three arguments are be-
  140. tween 0 (no component) and 1000 (maximum amount of compo-
  141. nent).
  142. The <STRONG>pair_content</STRONG> routine allows programmers to find out
  143. what colors a given color-pair consists of. It requires
  144. three arguments: the color-pair number, and two addresses
  145. of <STRONG>short</STRONG>s for storing the foreground and the background
  146. color numbers. The value of the first argument must be
  147. between 1 and <STRONG>COLOR_PAIRS-1</STRONG>. The values that are stored
  148. at the addresses pointed to by the second and third argu-
  149. ments are between 0 and <STRONG>COLORS</STRONG>.
  150. <STRONG>Colors</STRONG>
  151. In <STRONG>&lt;curses.h&gt;</STRONG> the following macros are defined. These are
  152. the default colors. <STRONG>curses</STRONG> also assumes that <STRONG>COLOR_BLACK</STRONG>
  153. is the default background color for all terminals.
  154. <STRONG>COLOR_BLACK</STRONG>
  155. <STRONG>COLOR_RED</STRONG>
  156. <STRONG>COLOR_GREEN</STRONG>
  157. <STRONG>COLOR_YELLOW</STRONG>
  158. <STRONG>COLOR_BLUE</STRONG>
  159. <STRONG>COLOR_MAGENTA</STRONG>
  160. <STRONG>COLOR_CYAN</STRONG>
  161. <STRONG>COLOR_WHITE</STRONG>
  162. </PRE>
  163. <H2>RETURN VALUE</H2><PRE>
  164. The routines <STRONG>can_change_color()</STRONG> and <STRONG>has_colors()</STRONG> return
  165. <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
  166. All other routines return the integer <STRONG>ERR</STRONG> upon failure and
  167. an <STRONG>OK</STRONG> (SVr4 specifies only "an integer value other than
  168. <STRONG>ERR</STRONG>") upon successful completion.
  169. X/Open defines no error conditions. This implementation
  170. will return <STRONG>ERR</STRONG> on attempts to use color values outside
  171. the range 0 to COLORS-1 (except for the default colors ex-
  172. tension), or use color pairs outside the range 0 to COL-
  173. OR_PAIR-1. Color values used in <STRONG>init_color</STRONG> must be in the
  174. range 0 to 1000. An error is returned from all functions
  175. if the terminal has not been initialized. An error is re-
  176. turned from secondary functions such as <STRONG>init_pair</STRONG> if
  177. <STRONG>start_color</STRONG> was not called.
  178. <STRONG>init_color</STRONG>
  179. returns an error if the terminal does not sup-
  180. port this feature, e.g., if the <EM>initial-</EM>
  181. <EM>ize</EM><STRONG>_</STRONG><EM>color</EM> capability is absent from the termi-
  182. nal description.
  183. <STRONG>start_color</STRONG>
  184. returns an error If the color table cannot be
  185. allocated.
  186. </PRE>
  187. <H2>NOTES</H2><PRE>
  188. In the <EM>ncurses</EM> implementation, there is a separate color
  189. activation flag, color palette, color pairs table, and as-
  190. sociated COLORS and COLOR_PAIRS counts for each screen;
  191. the <STRONG>start_color</STRONG> function only affects the current screen.
  192. The SVr4/XSI interface is not really designed with this in
  193. mind, and historical implementations may use a single
  194. shared color palette.
  195. Note that setting an implicit background color via a color
  196. pair affects only character cells that a character write
  197. operation explicitly touches. To change the background
  198. color used when parts of a window are blanked by erasing
  199. or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
  200. Several caveats apply on 386 and 486 machines with VGA-
  201. compatible graphics:
  202. - COLOR_YELLOW is actually brown. To get yellow, use
  203. COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
  204. - The A_BLINK attribute should in theory cause the
  205. background to go bright. This often fails to work,
  206. and even some cards for which it mostly works (such
  207. as the Paradise and compatibles) do the wrong thing
  208. when you try to set a bright "yellow" background (you
  209. get a blinking yellow foreground instead).
  210. - Color RGB values are not settable.
  211. </PRE>
  212. <H2>PORTABILITY</H2><PRE>
  213. This implementation satisfies XSI Curses's minimum maxi-
  214. mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
  215. The <STRONG>init_pair</STRONG> routine accepts negative values of fore-
  216. ground and background color to support the <STRONG>use_de-</STRONG>
  217. <STRONG>fault_colors</STRONG> extension, but only if that routine has been
  218. first invoked.
  219. The assumption that <STRONG>COLOR_BLACK</STRONG> is the default background
  220. color for all terminals can be modified using the <STRONG>as-</STRONG>
  221. <STRONG>sume_default_colors</STRONG> extension.
  222. This implementation checks the pointers, e.g., for the
  223. values returned by <STRONG>color_content</STRONG> and <STRONG>pair_content</STRONG>, and
  224. will treat those as optional parameters when null.
  225. </PRE>
  226. <H2>SEE ALSO</H2><PRE>
  227. <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_initscr.3x.html">curs_initscr(3x)</A></STRONG>, <STRONG><A HREF="curs_attr.3x.html">curs_attr(3x)</A></STRONG>, <STRONG>default_col-</STRONG>
  228. <STRONG><A HREF="default_colors.3x.html">ors(3x)</A></STRONG>
  229. <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
  230. </PRE>
  231. <HR>
  232. <ADDRESS>
  233. Man(1) output converted with
  234. <a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>
  235. </ADDRESS>
  236. </BODY>
  237. </HTML>