From b9b805689e2387d8b97225af5ca8b76c5ac0c689 Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Sun, 27 Jan 2013 22:08:06 +0100 Subject: [PATCH] Revert hrev38316 fore-/background colors customization This reverts hrev38316 in parts of foreground and background colors handling. Mentioned revision has hardcoded colors to system ANSI color entries 7 and 0 correspondently. It is very uncomfortable for the console programs like Midnight Commander because they become colors that were defined in the current Terminal scheme and doesn't correspond to real ANSI color names. For example "ANSI black" can be black, white, blue, gray or something else in dependency of the current color scheme configuration. The same side-effect was obviously observed for "ANSI white" and produced funny color combinations in software. --- src/apps/terminal/TermParse.cpp | 8 +++--- src/apps/terminal/TermView.cpp | 48 +++++++++++++++++++-------------- src/apps/terminal/TermView.h | 2 ++ 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index 48cdbeefd1..a038ea98a9 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -72,8 +72,8 @@ TermParse::_NextParseChar() TermParse::TermParse(int fd) : fFd(fd), - fAttr(FORECOLORED(7)), - fSavedAttr(FORECOLORED(7)), + fAttr(BACKCOLOR), + fSavedAttr(BACKCOLOR), fParseThread(-1), fReaderThread(-1), fReaderSem(-1), @@ -393,7 +393,7 @@ TermParse::EscParse() int width = 1; BAutolock locker(fBuffer); - fAttr = fSavedAttr = FORECOLORED(7); + fAttr = fSavedAttr = BACKCOLOR; while (!fQuitting) { try { @@ -832,7 +832,7 @@ TermParse::EscParse() switch (param[row]) { case DEFAULT: case 0: /* Reset attribute */ - fAttr = FORECOLORED(7); + fAttr = 0; break; case 1: /* Bold */ diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 54d9621577..305b30cc3d 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -373,7 +373,7 @@ TermView::_InitObject(const ShellParameters& shellParameters) if (error < B_OK) return error; - SetLowColor(fTermColorTable[8]); + SetLowColor(fTextBackColor); SetViewColor(B_TRANSPARENT_32_BIT); return B_OK; @@ -626,10 +626,10 @@ TermView::GetTermSizeFromRect(const BRect &rect, int *_rows, void TermView::SetTextColor(rgb_color fore, rgb_color back) { - fTermColorTable[0] = back; - fTermColorTable[7] = fore; + fTextBackColor = back; + fTextForeColor = fore; - SetLowColor(back); + SetLowColor(fTextBackColor); } @@ -660,20 +660,20 @@ TermView::SetTermColor(uint index, rgb_color color, bool dynamic) switch (index) { case 10: - fTermColorTable[7] = color; + fTextForeColor = color; break; case 11: - fTermColorTable[0] = color; - SetLowColor(fTermColorTable[0]); + fTextBackColor = color; + SetLowColor(fTextBackColor); break; case 110: - fTermColorTable[7] = + fTextForeColor = PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR); break; case 111: - fTermColorTable[0] = + fTextBackColor = PrefHandler::Default()->getRGB(PREF_TEXT_BACK_COLOR); - SetLowColor(fTermColorTable[0]); + SetLowColor(fTextBackColor); break; default: break; @@ -914,19 +914,26 @@ void TermView::_DrawLinePart(int32 x1, int32 y1, uint32 attr, char *buf, int32 width, bool mouse, bool cursor, BView *inView) { - rgb_color rgb_fore, rgb_back; - inView->SetFont(&fHalfFont); // Set pen point int x2 = x1 + fFontWidth * width; int y2 = y1 + fFontHeight; + rgb_color rgb_fore = fTextForeColor; + rgb_color rgb_back = fTextBackColor; + // color attribute int forecolor = IS_FORECOLOR(attr); int backcolor = IS_BACKCOLOR(attr); - rgb_fore = fTermColorTable[forecolor]; - rgb_back = fTermColorTable[backcolor]; + + if (IS_FORESET(attr)) + rgb_fore = fTermColorTable[forecolor]; + if (IS_BACKSET(attr)) + rgb_back = fTermColorTable[backcolor]; + +// printf("DLP:[%03x %03x %03x]; [%03x %03x %03x];\n", +// rgb_fore.red, rgb_fore.green, rgb_fore.blue, rgb_back.red, rgb_back.green, rgb_back.blue); // Selection check. if (cursor) { @@ -1011,7 +1018,7 @@ TermView::_DrawCursor() if (cursorVisible) SetHighColor(fCursorBackColor); else - SetHighColor(fTermColorTable[IS_BACKCOLOR(attr)]); + SetHighColor(cursorVisible ? fCursorBackColor : fTextBackColor); } FillRect(rect); @@ -1163,7 +1170,7 @@ TermView::Draw(BRect updateRect) if (clearLeft <= updateRect.right) { BRect rect(clearLeft, updateRect.top, updateRect.right, updateRect.bottom); - SetHighColor(fTermColorTable[0]); + SetHighColor(fTextBackColor); FillRect(rect); } } @@ -1174,7 +1181,7 @@ TermView::Draw(BRect updateRect) if (clearTop <= updateRect.bottom) { BRect rect(updateRect.left, clearTop, updateRect.right, updateRect.bottom); - SetHighColor(fTermColorTable[0]); + SetHighColor(fTextBackColor); FillRect(rect); } } @@ -1221,6 +1228,7 @@ TermView::Draw(BRect updateRect) uint32 backcolor = IS_BACKCOLOR(fVisibleTextBuffer->GetLineColor( lineIndexInHistory)); rgb_color rgb_back = fTermColorTable[backcolor]; + // /* rgb_color*/ rgb_back = fTextBackColor; SetHighColor(rgb_back); FillRect(rect); } @@ -3002,15 +3010,15 @@ TermView::_DrawInlineMethodString() BRect eraseRect(startPoint, endPoint); PushState(); - SetHighColor(fTermColorTable[7]); + SetHighColor(fTextForeColor); FillRect(eraseRect); PopState(); BPoint loc = _ConvertFromTerminal(fCursor); loc.y += fFontHeight; SetFont(&fHalfFont); - SetHighColor(fTermColorTable[0]); - SetLowColor(fTermColorTable[7]); + SetHighColor(fTextBackColor); + SetLowColor(fTextForeColor); DrawString(fInline->String(), loc); } diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index e4c183bc03..c7fe52ffb6 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -259,6 +259,8 @@ private: InlineInput* fInline; // Color and Attribute. + rgb_color fTextForeColor; + rgb_color fTextBackColor; rgb_color fCursorForeColor; rgb_color fCursorBackColor; rgb_color fSelectForeColor;