1d522f475Smrg#! /usr/bin/perl
204b94745Smrg# $XTermId: 256colres.pl,v 1.16 2007/06/08 23:58:37 tom Exp $
320d2c4d2Smrg# -----------------------------------------------------------------------------
420d2c4d2Smrg# this file is part of xterm
520d2c4d2Smrg#
620d2c4d2Smrg# Copyright 1999-2002,2007 by Thomas E. Dickey
720d2c4d2Smrg#
820d2c4d2Smrg#                         All Rights Reserved
920d2c4d2Smrg#
1020d2c4d2Smrg# Permission is hereby granted, free of charge, to any person obtaining a
1120d2c4d2Smrg# copy of this software and associated documentation files (the
1220d2c4d2Smrg# "Software"), to deal in the Software without restriction, including
1320d2c4d2Smrg# without limitation the rights to use, copy, modify, merge, publish,
1420d2c4d2Smrg# distribute, sublicense, and/or sell copies of the Software, and to
1520d2c4d2Smrg# permit persons to whom the Software is furnished to do so, subject to
1620d2c4d2Smrg# the following conditions:
1720d2c4d2Smrg#
1820d2c4d2Smrg# The above copyright notice and this permission notice shall be included
1920d2c4d2Smrg# in all copies or substantial portions of the Software.
2020d2c4d2Smrg#
2120d2c4d2Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2220d2c4d2Smrg# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2320d2c4d2Smrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2420d2c4d2Smrg# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
2520d2c4d2Smrg# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2620d2c4d2Smrg# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2720d2c4d2Smrg# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2820d2c4d2Smrg#
2920d2c4d2Smrg# Except as contained in this notice, the name(s) of the above copyright
3020d2c4d2Smrg# holders shall not be used in advertising or otherwise to promote the
3120d2c4d2Smrg# sale, use or other dealings in this Software without prior written
3220d2c4d2Smrg# authorization.
3320d2c4d2Smrg# -----------------------------------------------------------------------------
34d522f475Smrg
35d522f475Smrg# Construct a header file defining default resources for the 256-color model
36d522f475Smrg# of xterm.  This is modeled after the 256colors2.pl script.
37d522f475Smrg
38d522f475Smrg# use the resources for colors 0-15 - usually more-or-less a
39d522f475Smrg# reproduction of the standard ANSI colors, but possibly more
40d522f475Smrg# pleasing shades
41d522f475Smrg
42d522f475Smrguse strict;
43d522f475Smrg
44d522f475Smrgour ( $line1, $line2, $line3 );
45d522f475Smrgour ( $red, $green, $blue, $gray );
46d522f475Smrgour ( $level, $code, @steps );
47d522f475Smrg
48d522f475Smrgprint <<EOF;
49d522f475Smrg/*
50d522f475Smrg * This header file was generated by $0
51d522f475Smrg */
52d522f475Smrg/* \$XTermId\$ */
53d522f475Smrg
54d522f475Smrg#ifndef included_256colres_h
55d522f475Smrg#define included_256colres_h
56d522f475Smrg
57d522f475SmrgEOF
58d522f475Smrg
59d522f475Smrg$line1="COLOR_RES(\"%d\",";
60d522f475Smrg$line2="\tscreen.Acolors[%d],";
61d522f475Smrg$line3="\tDFT_COLOR(\"rgb:%2.2x/%2.2x/%2.2x\")),\n";
62d522f475Smrg
63d522f475Smrg# colors 16-231 are a 6x6x6 color cube
64d522f475Smrgfor ($red = 0; $red < 6; $red++) {
65d522f475Smrg    for ($green = 0; $green < 6; $green++) {
66d522f475Smrg	for ($blue = 0; $blue < 6; $blue++) {
67d522f475Smrg	    $code = 16 + ($red * 36) + ($green * 6) + $blue;
68d522f475Smrg	    printf($line1, $code);
69d522f475Smrg	    printf($line2, $code);
70d522f475Smrg	    printf($line3,
71d522f475Smrg		   ($red ? ($red * 40 + 55) : 0),
72d522f475Smrg		   ($green ? ($green * 40 + 55) : 0),
73d522f475Smrg		   ($blue ? ($blue * 40 + 55) : 0));
74d522f475Smrg	}
75d522f475Smrg    }
76d522f475Smrg}
77d522f475Smrg
78d522f475Smrg# colors 232-255 are a grayscale ramp, intentionally leaving out
79d522f475Smrg# black and white
80d522f475Smrg$code=232;
81d522f475Smrgfor ($gray = 0; $gray < 24; $gray++) {
82d522f475Smrg    $level = ($gray * 10) + 8;
83d522f475Smrg    $code = 232 + $gray;
84d522f475Smrg    printf($line1, $code);
85d522f475Smrg    printf($line2, $code);
86d522f475Smrg    printf($line3,
87d522f475Smrg	   $level, $level, $level);
88d522f475Smrg}
89d522f475Smrg
90d522f475Smrgprint <<EOF;
91d522f475Smrg
92d522f475Smrg#endif /* included_256colres_h */
93d522f475SmrgEOF
94