Add 256 color support.

Patch by Lars Doelle. Thanks!

CCBUG: 107487


svn path=/trunk/KDE/kdebase/apps/konsole/; revision=557629
This commit is contained in:
Kurt Hindenburg
2006-07-03 16:57:18 +00:00
parent aa00fa3c71
commit f34d820342
7 changed files with 411 additions and 125 deletions

98
README.moreColors Normal file
View File

@@ -0,0 +1,98 @@
[README.moreColors]
The konsole adopted some ESC codes allowing to use extended
color spaces.
There is a predefined 256 color space compatible with his
xterm sister, and, even beyond that, a 3-byte RGB color space.
The ESC codes are as follows:
ESC[ ... 38;2;<r>;<g>;<b> ... m Select RGB foreground color
ESC[ ... 48;2;<r>;<g>;<b> ... m Select RGB background color
ESC[ ... 38;5;<i> ... m Select indexed foreground color
ESC[ ... 48;5;<i> ... m Select indexed background color
<r>,<g> and <b> are each values in the range of 0..255 and
represent the brightness as usual for the respective color.
<i> likely is a value in 0..256, but represents an indexed
color assignment composed as follows:
0 .. 15 - System color, these are taken from the schema.
16 .. 231 - Forms a 6x6x6 RGB color cube.
232 .. 255 - A gray scale ramp without black and white.
Try the tests/color-spaces.pl to visualize the assignment.
----------------------------------------------------------------
A note on conformance
These ESC codes break the "associativity" of SGR, but after some
research the result is, that the standard itself is broken here.
The perhaps best codes due to ECMA-48 would probably be e.g.
38:2:<r>:<g>:<b>, i.e. consistently a colon instead of a semicolon.
But apparently, this is defined different in ISO-8613 (which is
included at this place in ECMA-48), actually breaking ECMA-48.
We cannot help this and implemented the codes as above, which
is a balanced decision.
For 256 color mode, this is compatible with xterm and perhaps
with other xterm compatible terminal emulations.
| ------- Additional Comments From awendt putergeek com 2006-06-07 07:40 -------
| > So a parameter substring is 0-9 and the colon. The semicolon separates
| > sub-parameters. Thus 48:5:<Color> would be one sub-parameter, and
| > 48;5;<Color> many independent, each having an independent meaning in case
| > of a selective parameter.
|
|
| I think you may be onto something here with the colons... I was able to find
| ITU T.416 (which is the same as ISO 8613-6) and it says:
|
| --- snip ---
|
| The parameter values 38 and 48 are followed by a parameter substring used to
| select either the character foreground ?colour value? or the character
| background ?colour value?.
|
| A parameter substring for values 38 or 48 may be divided by one or more
| separators (03/10) into parameter elements, denoted as Pe. The format of such
| a parameter sub-string is indicated as:
|
| Pe : P ...
|
| Each parameter element consists of zero, one or more bit combinations from
| 03/00 to 03/09, representing the digits 0 to 9. An empty parameter element
| represents a default value for this parameter element. Empty parameter
| elements at the end of the parameter substring need not be included.
|
| The first parameter element indicates a choice between:
|
| 0 implementation defined (only applicable for the character
| foreground colour)
| 1 transparent;
| 2 direct colour in RGB space;
| 3 direct colour in CMY space;
| 4 direct colour in CMYK space;
| 5 indexed colour.
|
| If the first parameter has the value 0 or 1, there are no additional parameter
| elements.
|
| If the first parameter element has the value 5, then there is a second
| parameter element specifying the index into the colour table given by the
| attribute ?content colour table? applying to the object with which the
| content is associated.
|
| --- snip ---
|
| The separator character 03/10 they use is a colon, not a semicolon... I wonder
| if the xterm implementation was based on an improper reading of the standard?
|

View File

@@ -27,6 +27,24 @@ typedef unsigned char UINT8;
typedef unsigned short UINT16;
#endif
// Color Table Elements ///////////////////////////////////////////////
/*!
*/
struct ColorEntry
{
ColorEntry(QColor c, bool tr, bool b) : color(c), transparent(tr), bold(b) {}
ColorEntry() : transparent(false), bold(false) {} // default constructors
void operator=(const ColorEntry& rhs) {
color = rhs.color;
transparent = rhs.transparent;
bold = rhs.bold;
}
QColor color;
bool transparent; // if used on bg
bool bold; // if used on fg
};
// Attributed Character Representations ///////////////////////////////
// Colors
@@ -46,6 +64,115 @@ typedef unsigned short UINT16;
#define RE_INTENSIVE (1 << 3) // Widget only
#define RE_CURSOR (1 << 4)
/* cacol is a union of the various color spaces.
Assignment is as follows:
Type - Space - Values
0 - Undefined - u: 0, v:0 w:0
1 - Default - u: 0..1 v:intense w:0
2 - System - u: 0..7 v:intense w:0
3 - Index(256) - u: 16..255 v:0 w:0
4 - RGB - u: 0..255 v:0..256 w:0..256
Default colour space has two separate colours, namely
default foreground and default background colour.
*/
#define CO_UND 0
#define CO_DFT 1
#define CO_SYS 2
#define CO_256 3
#define CO_RGB 4
class cacol
{
public:
cacol();
cacol(UINT8 space, int color);
UINT8 t; // color space indicator
UINT8 u; // various bytes representing the data in the respective ...
UINT8 v; // ... color space. C++ does not do unions, so we cannot ...
UINT8 w; // ... express ourselfs here, properly.
void toggleIntensive(); // Hack or helper?
QColor color(const ColorEntry* base) const;
friend bool operator == (cacol a, cacol b);
friend bool operator != (cacol a, cacol b);
};
#if 0
inline cacol::cacol(UINT8 _t, UINT8 _u, UINT8 _v, UINT8 _w)
: t(_t), u(_u), v(_v), w(_w)
{
}
#else
inline cacol::cacol(UINT8 ty, int co)
: t(ty), u(0), v(0), w(0)
{
switch (t)
{
case CO_UND: break;
case CO_DFT: u = co& 1; break;
case CO_SYS: u = co& 7; v = (co>>3)&1; break;
case CO_256: u = co&255; break;
case CO_RGB: u = co>>16; v = co>>8; w = co; break;
default : t = 0; break;
}
}
#endif
inline cacol::cacol() // undefined, really
: t(CO_UND), u(0), v(0), w(0)
{
}
inline bool operator == (cacol a, cacol b)
{
return a.t == b.t && a.u == b.u && a.v == b.v && a.w == b.w;
}
inline bool operator != (cacol a, cacol b)
{
return a.t != b.t || a.u != b.u || a.v != b.v || a.w != b.w;
}
inline const QColor color256(UINT8 u, const ColorEntry* base)
{
// 0.. 16: system colors
if (u < 8) return base[u+2 ].color; u -= 8;
if (u < 8) return base[u+2+BASE_COLORS].color; u -= 8;
// 16..231: 6x6x6 rgb color cube
if (u < 216) return QColor(255*((u/36)%6)/6,
255*((u/ 6)%6)/6,
255*((u/ 1)%6)/6); u -= 216;
// 232..255: gray, leaving out black and white
int gray = u*10+8; return QColor(gray,gray,gray);
}
inline QColor cacol::color(const ColorEntry* base) const
{
switch (t)
{
case CO_DFT: return base[u+0+(v?BASE_COLORS:0)].color;
case CO_SYS: return base[u+2+(v?BASE_COLORS:0)].color;
case CO_256: return color256(u,base);
case CO_RGB: return QColor(u,v,w);
default : return QColor(255,0,0); // diagnostic catch all
}
}
inline void cacol::toggleIntensive()
{
if (t == CO_SYS || t == CO_DFT)
{
v = !v;
}
}
/*! \class ca
* \brief a character with rendition attributes.
*/
@@ -54,22 +181,28 @@ class ca
{
public:
inline ca(UINT16 _c = ' ',
UINT8 _f = DEFAULT_FORE_COLOR,
UINT8 _b = DEFAULT_BACK_COLOR,
UINT8 _r = DEFAULT_RENDITION)
: c(_c), f(_f), b(_b), r(_r) {}
cacol _f = cacol(CO_DFT,DEFAULT_FORE_COLOR),
cacol _b = cacol(CO_DFT,DEFAULT_BACK_COLOR),
UINT8 _r = DEFAULT_RENDITION)
: c(_c), r(_r), f(_f), b(_b) {}
public:
UINT16 c; // character
UINT8 f; // foreground color
UINT8 b; // background color
UINT8 r; // rendition
cacol f; // foreground color
cacol b; // background color
public:
//FIXME: following a hack to cope with various color spaces
// it brings the rendition pipeline further out of balance,
// which it was anyway as the result of various additions.
bool isTransparent(const ColorEntry* base) const;
bool isBold(const ColorEntry* base) const;
public:
friend bool operator == (ca a, ca b);
friend bool operator != (ca a, ca b);
};
inline bool operator == (ca a, ca b)
{
{
return a.c == b.c && a.f == b.f && a.b == b.b && a.r == b.r;
}
@@ -78,20 +211,16 @@ inline bool operator != (ca a, ca b)
return a.c != b.c || a.f != b.f || a.b != b.b || a.r != b.r;
}
/*!
*/
struct ColorEntry
inline bool ca::isTransparent(const ColorEntry* base) const
{
ColorEntry(QColor c, bool tr, bool b) : color(c), transparent(tr), bold(b) {}
ColorEntry() : transparent(false), bold(false) {} // default constructors
void operator=(const ColorEntry& rhs) {
color = rhs.color;
transparent = rhs.transparent;
bold = rhs.bold;
}
QColor color;
bool transparent; // if used on bg
bool bold; // if used on fg
};
return (b.t == CO_DFT) && base[b.u+0+(b.v?BASE_COLORS:0)].transparent
|| (b.t == CO_SYS) && base[b.u+2+(b.v?BASE_COLORS:0)].transparent;
}
inline bool ca::isBold(const ColorEntry* base) const
{
return (b.t == CO_DFT) && base[b.u+0+(b.v?BASE_COLORS:0)].bold
|| (b.t == CO_SYS) && base[b.u+2+(b.v?BASE_COLORS:0)].bold;
}
#endif // TECOMMON_H

View File

@@ -69,15 +69,15 @@ TEScreen::TEScreen(int l, int c)
histCursor(0),
hist(new HistoryScrollNone()),
cuX(0), cuY(0),
cu_fg(0), cu_bg(0), cu_re(0),
cu_fg(cacol()), cu_bg(cacol()), cu_re(0),
tmargin(0), bmargin(0),
tabstops(0),
sel_begin(0), sel_TL(0), sel_BR(0),
sel_busy(false),
columnmode(false),
ef_fg(0), ef_bg(0), ef_re(0),
ef_fg(cacol()), ef_bg(cacol()), ef_re(0),
sa_cuX(0), sa_cuY(0),
sa_cu_re(0), sa_cu_fg(0), sa_cu_bg(0),
sa_cu_re(0), sa_cu_fg(cacol()), sa_cu_bg(cacol()),
lastPos(-1)
{
/*
@@ -427,8 +427,8 @@ void TEScreen::resizeImage(int new_lines, int new_columns)
for (int x = 0; x < new_columns; x++)
{
newimg[y*new_columns+x].c = ' ';
newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR;
newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR;
newimg[y*new_columns+x].f = cacol(CO_DFT,DEFAULT_FORE_COLOR);
newimg[y*new_columns+x].b = cacol(CO_DFT,DEFAULT_BACK_COLOR);
newimg[y*new_columns+x].r = DEFAULT_RENDITION;
}
newwrapped[y]=false;
@@ -496,7 +496,7 @@ void TEScreen::resizeImage(int new_lines, int new_columns)
*/
void TEScreen::reverseRendition(ca* p)
{ UINT8 f = p->f; UINT8 b = p->b;
{ cacol f = p->f; cacol b = p->b;
p->f = b; p->b = f; //p->r &= ~RE_TRANSPARENT;
}
@@ -515,12 +515,7 @@ void TEScreen::effectiveRendition()
ef_bg = cu_bg;
}
if (cu_re & RE_BOLD)
{
if (ef_fg < BASE_COLORS)
ef_fg += BASE_COLORS;
else
ef_fg -= BASE_COLORS;
}
ef_fg.toggleIntensive();
}
/*!
@@ -542,7 +537,7 @@ ca* TEScreen::getCookedImage()
int x,y;
ca* merged = (ca*)malloc((lines*columns+1)*sizeof(ca));
ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION);
ca dft(' ',cacol(CO_DFT,DEFAULT_FORE_COLOR),cacol(CO_DFT,DEFAULT_BACK_COLOR),DEFAULT_RENDITION);
merged[lines*columns] = dft;
// kDebug(1211) << "InGetCookedImage" << endl;
@@ -1084,45 +1079,25 @@ void TEScreen::resetRendition(int re)
void TEScreen::setDefaultRendition()
{
setForeColorToDefault();
setBackColorToDefault();
setForeColor(CO_DFT,DEFAULT_FORE_COLOR);
setBackColor(CO_DFT,DEFAULT_BACK_COLOR);
cu_re = DEFAULT_RENDITION;
effectiveRendition();
}
/*!
*/
void TEScreen::setForeColor(int fgcolor)
void TEScreen::setForeColor(int space, int color)
{
cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2);
cu_fg = cacol(space, color);
effectiveRendition();
}
/*!
*/
void TEScreen::setBackColor(int bgcolor)
void TEScreen::setBackColor(int space, int color)
{
cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2);
effectiveRendition();
}
/*!
*/
void TEScreen::setBackColorToDefault()
{
cu_bg = DEFAULT_BACK_COLOR;
effectiveRendition();
}
/*!
*/
void TEScreen::setForeColorToDefault()
{
cu_fg = DEFAULT_FORE_COLOR;
cu_bg = cacol(space, color);
effectiveRendition();
}

View File

@@ -112,12 +112,11 @@ public: // these are all `Screen' operations
//
void setRendition (int rendition);
void resetRendition(int rendition);
void setForeColor (int fgcolor);
void setBackColor (int bgcolor);
//
void setForeColor (int space, int color);
void setBackColor (int space, int color);
//
void setDefaultRendition();
void setForeColorToDefault();
void setBackColorToDefault();
//
// -------------------------------------
//
@@ -220,8 +219,8 @@ private: // helper
// cursor color and rendition info
UINT8 cu_fg; // foreground
UINT8 cu_bg; // background
cacol cu_fg; // foreground
cacol cu_bg; // background
UINT8 cu_re; // rendition
// margins ----------------
@@ -247,8 +246,8 @@ private: // helper
// effective colors and rendition ------------
UINT8 ef_fg; // These are derived from
UINT8 ef_bg; // the cu_* variables above
cacol ef_fg; // These are derived from
cacol ef_bg; // the cu_* variables above
UINT8 ef_re; // to speed up operation
//
@@ -263,8 +262,8 @@ private: // helper
// rendition info
UINT8 sa_cu_re;
UINT8 sa_cu_fg;
UINT8 sa_cu_bg;
cacol sa_cu_fg;
cacol sa_cu_bg;
// last position where we added a character
int lastPos;

View File

@@ -607,7 +607,8 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
QString& str, const ca *attr, bool pm, bool clear)
{
int a = font_a + m_lineSpacing / 2;
QColor fColor = printerFriendly ? Qt::black : color_table[attr->f].color;
QColor fColor = printerFriendly ? Qt::black : attr->f.color(color_table);
QColor bColor = attr->b.color(color_table);
QString drawstr;
if ((attr->r & RE_CURSOR) && !isPrinting)
@@ -616,7 +617,7 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
// Paint background
if (!printerFriendly)
{
if (color_table[attr->b].transparent)
if (attr->isTransparent(color_table))
{
if (pm)
paint.setBackgroundMode( Qt::TransparentMode );
@@ -625,12 +626,12 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
}
else
{
if (pm || color_table[attr->b].color != color_table[ colorsSwapped ? DEFAULT_FORE_COLOR : DEFAULT_BACK_COLOR ].color
|| clear || (blinking && (attr->r & RE_BLINK)))
if (pm || clear || (blinking && (attr->r & RE_BLINK)) ||
attr->b == cacol(CO_DFT, colorsSwapped ? DEFAULT_FORE_COLOR : DEFAULT_BACK_COLOR) )
// draw background colors with 75% opacity
if ( argb_visual && qAlpha(blend_color) < 0xff ) {
QRgb col = color_table[attr->b].color.rgb();
QRgb col = bColor.rgb();
Q_UINT8 salpha = 192;
Q_UINT8 dalpha = 255 - salpha;
@@ -646,7 +647,7 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
paint.fillRect(rect, QColor(col));
} else
paint.fillRect(rect, color_table[attr->b].color);
paint.fillRect(rect, bColor);
}
QString tmpStr = str.simplified();
@@ -685,8 +686,8 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
{
if (!cursorBlinking)
{
paint.fillRect(r, color_table[attr->f].color);
fColor = color_table[attr->b].color;
paint.fillRect(r, fColor);
fColor = bColor;
}
}
else
@@ -706,7 +707,7 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
bool shadow = false;
paint.setPen(fColor);
int x = rect.x();
if (color_table[attr->f].bold && printerBold)
if (attr->isBold(color_table) && printerBold)
{
// When printing we use a bold font for bold
paint.save();
@@ -747,13 +748,13 @@ void TEWidget::drawAttrStr(QPainter &paint, const QRect& rect,
paint.drawText(x,y, str);
}
if (color_table[attr->f].bold && isPrinting)
if (attr->isBold(color_table) && isPrinting)
{
// When printing we use a bold font for bold
paint.restore();
}
if (color_table[attr->f].bold && !printerBold)
if (attr->isBold(color_table) && !printerBold)
{
paint.setClipRect(rect);
// On screen we use overstrike for bold
@@ -818,9 +819,9 @@ void TEWidget::setImage(const ca* const newimg, int lines, int columns)
int tLy = tL.y();
hasBlinker = false;
int cf = -1; // undefined
int cb = -1; // undefined
int cr = -1; // undefined
cacol cf; // undefined
cacol cb; // undefined
int cr = -1; // undefined
int lins = qMin(this->lines, qMax(0,lines ));
int cols = qMin(this->columns,qMax(0,columns));
@@ -1077,9 +1078,9 @@ void TEWidget::paintContents(QPainter &paint, const QRect &rect, bool pm)
disstrU[p++] = c; //fontMap(c);
bool lineDraw = isLineChar(c);
bool doubleWidth = (image[loc(x,y)+1].c == 0);
int cf = image[loc(x,y)].f;
int cb = image[loc(x,y)].b;
int cr = image[loc(x,y)].r;
cacol cf = image[loc(x,y)].f;
cacol cb = image[loc(x,y)].b;
int cr = image[loc(x,y)].r;
while (x+len <= rlx &&
image[loc(x+len,y)].f == cf &&
image[loc(x+len,y)].b == cb &&
@@ -2044,10 +2045,10 @@ void TEWidget::clearImage()
// We initialize image[image_size] too. See makeImage()
for (int i = 0; i <= image_size; i++)
{
image[i].c = 0xff; //' ';
image[i].f = 0xff; //DEFAULT_FORE_COLOR;
image[i].b = 0xff; //DEFAULT_BACK_COLOR;
image[i].r = 0xff; //DEFAULT_RENDITION;
image[i].c = ' ';
image[i].f = cacol(CO_DFT,DEFAULT_FORE_COLOR);
image[i].b = cacol(CO_DFT,DEFAULT_BACK_COLOR);
image[i].r = DEFAULT_RENDITION;
}
}

View File

@@ -353,6 +353,17 @@ void TEmuVt102::onRcvChar(int cc)
for (i=0;i<=argc;i++)
if ( epp( )) { tau( TY_CSI_PR(cc,argv[i]), 0, 0); }
else if(egt( )) { tau( TY_CSI_PG(cc ), 0, 0); } // spec. case for ESC]>0c or ESC]>c
else if (cc == 'm' && argc - i >= 4 && (argv[i] == 38 || argv[i] == 48) && argv[i+1] == 2)
{ // ESC[ ... 48;2;<red>;<green>;<blue> ... m -or- ESC[ ... 38;2;<red>;<green>;<blue> ... m
i += 2;
tau( TY_CSI_PS(cc, argv[i-2]), CO_RGB, (argv[i] << 16) | (argv[i+1] << 8) | argv[i+2]);
i += 2;
}
else if (cc == 'm' && argc - i >= 2 && (argv[i] == 38 || argv[i] == 48) && argv[i+1] == 5)
{ // ESC[ ... 48;5;<index> ... m -or- ESC[ ... 38;5;<index> ... m
i += 2;
tau( TY_CSI_PS(cc, argv[i-2]), CO_256, argv[i]);
}
else { tau( TY_CSI_PS(cc,argv[i]), 0, 0); }
resetToken();
}
@@ -552,43 +563,49 @@ switch( N )
case TY_CSI_PS('m', 25) : scr->resetRendition (RE_BLINK ); break;
case TY_CSI_PS('m', 27) : scr->resetRendition (RE_REVERSE ); break;
case TY_CSI_PS('m', 30) : scr->setForeColor ( 0); break;
case TY_CSI_PS('m', 31) : scr->setForeColor ( 1); break;
case TY_CSI_PS('m', 32) : scr->setForeColor ( 2); break;
case TY_CSI_PS('m', 33) : scr->setForeColor ( 3); break;
case TY_CSI_PS('m', 34) : scr->setForeColor ( 4); break;
case TY_CSI_PS('m', 35) : scr->setForeColor ( 5); break;
case TY_CSI_PS('m', 36) : scr->setForeColor ( 6); break;
case TY_CSI_PS('m', 37) : scr->setForeColor ( 7); break;
case TY_CSI_PS('m', 39) : scr->setForeColorToDefault( ); break;
case TY_CSI_PS('m', 30) : scr->setForeColor (CO_SYS, 0); break;
case TY_CSI_PS('m', 31) : scr->setForeColor (CO_SYS, 1); break;
case TY_CSI_PS('m', 32) : scr->setForeColor (CO_SYS, 2); break;
case TY_CSI_PS('m', 33) : scr->setForeColor (CO_SYS, 3); break;
case TY_CSI_PS('m', 34) : scr->setForeColor (CO_SYS, 4); break;
case TY_CSI_PS('m', 35) : scr->setForeColor (CO_SYS, 5); break;
case TY_CSI_PS('m', 36) : scr->setForeColor (CO_SYS, 6); break;
case TY_CSI_PS('m', 37) : scr->setForeColor (CO_SYS, 7); break;
case TY_CSI_PS('m', 40) : scr->setBackColor ( 0); break;
case TY_CSI_PS('m', 41) : scr->setBackColor ( 1); break;
case TY_CSI_PS('m', 42) : scr->setBackColor ( 2); break;
case TY_CSI_PS('m', 43) : scr->setBackColor ( 3); break;
case TY_CSI_PS('m', 44) : scr->setBackColor ( 4); break;
case TY_CSI_PS('m', 45) : scr->setBackColor ( 5); break;
case TY_CSI_PS('m', 46) : scr->setBackColor ( 6); break;
case TY_CSI_PS('m', 47) : scr->setBackColor ( 7); break;
case TY_CSI_PS('m', 49) : scr->setBackColorToDefault( ); break;
case TY_CSI_PS('m', 38) : scr->setForeColor (p, q); break;
case TY_CSI_PS('m', 90) : scr->setForeColor ( 8); break;
case TY_CSI_PS('m', 91) : scr->setForeColor ( 9); break;
case TY_CSI_PS('m', 92) : scr->setForeColor ( 10); break;
case TY_CSI_PS('m', 93) : scr->setForeColor ( 11); break;
case TY_CSI_PS('m', 94) : scr->setForeColor ( 12); break;
case TY_CSI_PS('m', 95) : scr->setForeColor ( 13); break;
case TY_CSI_PS('m', 96) : scr->setForeColor ( 14); break;
case TY_CSI_PS('m', 97) : scr->setForeColor ( 15); break;
case TY_CSI_PS('m', 39) : scr->setForeColor (CO_DFT, 0); break;
case TY_CSI_PS('m', 100) : scr->setBackColor ( 8); break;
case TY_CSI_PS('m', 101) : scr->setBackColor ( 9); break;
case TY_CSI_PS('m', 102) : scr->setBackColor ( 10); break;
case TY_CSI_PS('m', 103) : scr->setBackColor ( 11); break;
case TY_CSI_PS('m', 104) : scr->setBackColor ( 12); break;
case TY_CSI_PS('m', 105) : scr->setBackColor ( 13); break;
case TY_CSI_PS('m', 106) : scr->setBackColor ( 14); break;
case TY_CSI_PS('m', 107) : scr->setBackColor ( 15); break;
case TY_CSI_PS('m', 40) : scr->setBackColor (CO_SYS, 0); break;
case TY_CSI_PS('m', 41) : scr->setBackColor (CO_SYS, 1); break;
case TY_CSI_PS('m', 42) : scr->setBackColor (CO_SYS, 2); break;
case TY_CSI_PS('m', 43) : scr->setBackColor (CO_SYS, 3); break;
case TY_CSI_PS('m', 44) : scr->setBackColor (CO_SYS, 4); break;
case TY_CSI_PS('m', 45) : scr->setBackColor (CO_SYS, 5); break;
case TY_CSI_PS('m', 46) : scr->setBackColor (CO_SYS, 6); break;
case TY_CSI_PS('m', 47) : scr->setBackColor (CO_SYS, 7); break;
case TY_CSI_PS('m', 48) : scr->setBackColor (p, q); break;
case TY_CSI_PS('m', 49) : scr->setBackColor (CO_DFT, 1); break;
case TY_CSI_PS('m', 90) : scr->setForeColor (CO_SYS, 8); break;
case TY_CSI_PS('m', 91) : scr->setForeColor (CO_SYS, 9); break;
case TY_CSI_PS('m', 92) : scr->setForeColor (CO_SYS, 10); break;
case TY_CSI_PS('m', 93) : scr->setForeColor (CO_SYS, 11); break;
case TY_CSI_PS('m', 94) : scr->setForeColor (CO_SYS, 12); break;
case TY_CSI_PS('m', 95) : scr->setForeColor (CO_SYS, 13); break;
case TY_CSI_PS('m', 96) : scr->setForeColor (CO_SYS, 14); break;
case TY_CSI_PS('m', 97) : scr->setForeColor (CO_SYS, 15); break;
case TY_CSI_PS('m', 100) : scr->setBackColor (CO_SYS, 8); break;
case TY_CSI_PS('m', 101) : scr->setBackColor (CO_SYS, 9); break;
case TY_CSI_PS('m', 102) : scr->setBackColor (CO_SYS, 10); break;
case TY_CSI_PS('m', 103) : scr->setBackColor (CO_SYS, 11); break;
case TY_CSI_PS('m', 104) : scr->setBackColor (CO_SYS, 12); break;
case TY_CSI_PS('m', 105) : scr->setBackColor (CO_SYS, 13); break;
case TY_CSI_PS('m', 106) : scr->setBackColor (CO_SYS, 14); break;
case TY_CSI_PS('m', 107) : scr->setBackColor (CO_SYS, 15); break;
case TY_CSI_PS('n', 5) : reportStatus ( ); break;
case TY_CSI_PS('n', 6) : reportCursorPosition ( ); break;

67
tests/color-spaces.pl Normal file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $
print "256 color mode\n\n";
# display back ground colors
for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) {
# first the system ones:
print "System colors:\n";
for ($color = 0; $color < 8; $color++) {
print "\x1b[${fgbg};5;${color}m::";
}
print "\x1b[0m\n";
for ($color = 8; $color < 16; $color++) {
print "\x1b[${fgbg};5;${color}m::";
}
print "\x1b[0m\n\n";
# now the color cube
print "Color cube, 6x6x6:\n";
for ($green = 0; $green < 6; $green++) {
for ($red = 0; $red < 6; $red++) {
for ($blue = 0; $blue < 6; $blue++) {
$color = 16 + ($red * 36) + ($green * 6) + $blue;
print "\x1b[${fgbg};5;${color}m::";
}
print "\x1b[0m ";
}
print "\n";
}
# now the grayscale ramp
print "Grayscale ramp:\n";
for ($color = 232; $color < 256; $color++) {
print "\x1b[${fgbg};5;${color}m::";
}
print "\x1b[0m\n\n";
}
print "Examples for the 3-byte color mode\n\n";
for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) {
# now the color cube
print "Color cube\n";
for ($green = 0; $green < 256; $green+=43) {
for ($red = 0; $red < 256; $red+=43) {
for ($blue = 0; $blue < 256; $blue+=43) {
print "\x1b[${fgbg};2;${red};${green};${blue}m::";
}
print "\x1b[0m ";
}
print "\n";
}
# now the grayscale ramp
print "Grayscale ramp:\n";
for ($gray = 0; $gray < 256; $gray+=10) {
print "\x1b[${fgbg};2;${gray};${gray};${gray}m::";
}
print "\x1b[0m\n\n";
}