Move colors table from TermView to TerminalBuffer
* ColorsTable moved to TerminalBuffer to let easy lookup of table during parsing of control sequences; * Default Palette initialized from now in TermApp and preserved from modifying by applications;
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
static bool sUsageRequested = false;
|
static bool sUsageRequested = false;
|
||||||
//static bool sGeometryRequested = false;
|
//static bool sGeometryRequested = false;
|
||||||
|
|
||||||
|
rgb_color TermApp::fDefaultPalette[kTermColorCount];
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
@@ -57,6 +58,8 @@ TermApp::TermApp()
|
|||||||
fArgs(NULL)
|
fArgs(NULL)
|
||||||
{
|
{
|
||||||
fArgs = new Arguments(0, NULL);
|
fArgs = new Arguments(0, NULL);
|
||||||
|
|
||||||
|
_InitDefaultPalette();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -309,3 +312,43 @@ TermApp::_Usage(char *name)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermApp::_InitDefaultPalette()
|
||||||
|
{
|
||||||
|
// 0 - 15 are system ANSI colors
|
||||||
|
const char * keys[kANSIColorCount] = {
|
||||||
|
PREF_ANSI_BLACK_COLOR,
|
||||||
|
PREF_ANSI_RED_COLOR,
|
||||||
|
PREF_ANSI_GREEN_COLOR,
|
||||||
|
PREF_ANSI_YELLOW_COLOR,
|
||||||
|
PREF_ANSI_BLUE_COLOR,
|
||||||
|
PREF_ANSI_MAGENTA_COLOR,
|
||||||
|
PREF_ANSI_CYAN_COLOR,
|
||||||
|
PREF_ANSI_WHITE_COLOR,
|
||||||
|
PREF_ANSI_BLACK_HCOLOR,
|
||||||
|
PREF_ANSI_RED_HCOLOR,
|
||||||
|
PREF_ANSI_GREEN_HCOLOR,
|
||||||
|
PREF_ANSI_YELLOW_HCOLOR,
|
||||||
|
PREF_ANSI_BLUE_HCOLOR,
|
||||||
|
PREF_ANSI_MAGENTA_HCOLOR,
|
||||||
|
PREF_ANSI_CYAN_HCOLOR,
|
||||||
|
PREF_ANSI_WHITE_HCOLOR
|
||||||
|
};
|
||||||
|
|
||||||
|
rgb_color* color = fDefaultPalette;
|
||||||
|
PrefHandler* handler = PrefHandler::Default();
|
||||||
|
for (uint i = 0; i < kANSIColorCount; i++)
|
||||||
|
*color++ = handler->getRGB(keys[i]);
|
||||||
|
|
||||||
|
// 16 - 231 are 6x6x6 color "cubes" in xterm color model
|
||||||
|
for (uint red = 0; red < 256; red += (red == 0) ? 95 : 40)
|
||||||
|
for (uint green = 0; green < 256; green += (green == 0) ? 95 : 40)
|
||||||
|
for (uint blue = 0; blue < 256; blue += (blue == 0) ? 95 : 40)
|
||||||
|
(*color++).set_to(red, green, blue);
|
||||||
|
|
||||||
|
// 232 - 255 are grayscale ramp in xterm color model
|
||||||
|
for (uint gray = 8; gray < 240; gray += 10)
|
||||||
|
(*color++).set_to(gray, gray, gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include "Colors.h"
|
||||||
|
|
||||||
class Arguments;
|
class Arguments;
|
||||||
class BRect;
|
class BRect;
|
||||||
@@ -48,6 +49,8 @@ public:
|
|||||||
TermApp();
|
TermApp();
|
||||||
virtual ~TermApp();
|
virtual ~TermApp();
|
||||||
|
|
||||||
|
static const rgb_color* DefaultPalette()
|
||||||
|
{ return fDefaultPalette; }
|
||||||
protected:
|
protected:
|
||||||
virtual void ReadyToRun();
|
virtual void ReadyToRun();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
@@ -64,13 +67,14 @@ private:
|
|||||||
static status_t _ChildCleanupThread(void* data);
|
static status_t _ChildCleanupThread(void* data);
|
||||||
|
|
||||||
void _Usage(char *name);
|
void _Usage(char *name);
|
||||||
|
void _InitDefaultPalette();
|
||||||
private:
|
private:
|
||||||
bool fStartFullscreen;
|
bool fStartFullscreen;
|
||||||
BString fWindowTitle;
|
BString fWindowTitle;
|
||||||
|
|
||||||
BWindow* fTermWindow;
|
BWindow* fTermWindow;
|
||||||
Arguments* fArgs;
|
Arguments* fArgs;
|
||||||
|
static rgb_color fDefaultPalette[kTermColorCount];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -892,17 +892,20 @@ TermParse::EscParse()
|
|||||||
|
|
||||||
case 38:
|
case 38:
|
||||||
{
|
{
|
||||||
if (nparam == 3 && param[1] == 5) {
|
int color = -1;
|
||||||
attributes &= ~FORECOLOR;
|
if (nparam == 3 && param[1] == 5)
|
||||||
attributes |= FORECOLORED(param[2]);
|
color = param[2];
|
||||||
attributes |= FORESET;
|
else if (nparam == 5 && param[1] == 2)
|
||||||
|
color = fBuffer->GuessPaletteColor(
|
||||||
|
param[2], param[3], param[4]);
|
||||||
|
|
||||||
} else if (nparam == 5) {
|
if (color >= 0) {
|
||||||
// TODO lookup
|
attributes &= ~FORECOLOR;
|
||||||
|
attributes |= FORECOLORED(color);
|
||||||
|
attributes |= FORESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = nparam; // force exit of the parsing
|
row = nparam; // force exit of the parsing
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -934,17 +937,20 @@ TermParse::EscParse()
|
|||||||
|
|
||||||
case 48:
|
case 48:
|
||||||
{
|
{
|
||||||
if (nparam == 3 && param[1] == 5) {
|
int color = -1;
|
||||||
attributes &= ~BACKCOLOR;
|
if (nparam == 3 && param[1] == 5)
|
||||||
attributes |= BACKCOLORED(param[2]);
|
color = param[2];
|
||||||
attributes |= BACKSET;
|
else if (nparam == 5 && param[1] == 2)
|
||||||
|
color = fBuffer->GuessPaletteColor(
|
||||||
|
param[2], param[3], param[4]);
|
||||||
|
|
||||||
} else if (nparam == 5) {
|
if (color >= 0) {
|
||||||
// TODO lookup
|
attributes &= ~BACKCOLOR;
|
||||||
|
attributes |= BACKCOLORED(color);
|
||||||
|
attributes |= BACKSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = nparam; // force exit of the parsing
|
row = nparam; // force exit of the parsing
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
#include "PrefHandler.h"
|
#include "PrefHandler.h"
|
||||||
#include "Shell.h"
|
#include "Shell.h"
|
||||||
#include "ShellParameters.h"
|
#include "ShellParameters.h"
|
||||||
|
#include "TermApp.h"
|
||||||
#include "TermConst.h"
|
#include "TermConst.h"
|
||||||
#include "TerminalBuffer.h"
|
#include "TerminalBuffer.h"
|
||||||
#include "TerminalCharClassifier.h"
|
#include "TerminalCharClassifier.h"
|
||||||
@@ -180,7 +181,6 @@ TermView::TermView(BRect frame, const ShellParameters& shellParameters,
|
|||||||
fRows(ROWS_DEFAULT),
|
fRows(ROWS_DEFAULT),
|
||||||
fEncoding(M_UTF8),
|
fEncoding(M_UTF8),
|
||||||
fActive(false),
|
fActive(false),
|
||||||
fTermColorTable(NULL),
|
|
||||||
fScrBufSize(historySize),
|
fScrBufSize(historySize),
|
||||||
fReportX10MouseEvent(false),
|
fReportX10MouseEvent(false),
|
||||||
fReportNormalMouseEvent(false),
|
fReportNormalMouseEvent(false),
|
||||||
@@ -204,7 +204,6 @@ TermView::TermView(int rows, int columns,
|
|||||||
fRows(rows),
|
fRows(rows),
|
||||||
fEncoding(M_UTF8),
|
fEncoding(M_UTF8),
|
||||||
fActive(false),
|
fActive(false),
|
||||||
fTermColorTable(NULL),
|
|
||||||
fScrBufSize(historySize),
|
fScrBufSize(historySize),
|
||||||
fReportX10MouseEvent(false),
|
fReportX10MouseEvent(false),
|
||||||
fReportNormalMouseEvent(false),
|
fReportNormalMouseEvent(false),
|
||||||
@@ -238,7 +237,6 @@ TermView::TermView(BMessage* archive)
|
|||||||
fRows(ROWS_DEFAULT),
|
fRows(ROWS_DEFAULT),
|
||||||
fEncoding(M_UTF8),
|
fEncoding(M_UTF8),
|
||||||
fActive(false),
|
fActive(false),
|
||||||
fTermColorTable(NULL),
|
|
||||||
fScrBufSize(1000),
|
fScrBufSize(1000),
|
||||||
fReportX10MouseEvent(false),
|
fReportX10MouseEvent(false),
|
||||||
fReportNormalMouseEvent(false),
|
fReportNormalMouseEvent(false),
|
||||||
@@ -335,17 +333,13 @@ TermView::_InitObject(const ShellParameters& shellParameters)
|
|||||||
if (fVisibleTextBuffer == NULL)
|
if (fVisibleTextBuffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t error = _InitColorTable();
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
// TODO: Make the special word chars user-settable!
|
// TODO: Make the special word chars user-settable!
|
||||||
fCharClassifier = new(std::nothrow) CharClassifier(
|
fCharClassifier = new(std::nothrow) CharClassifier(
|
||||||
kDefaultSpecialWordChars);
|
kDefaultSpecialWordChars);
|
||||||
if (fCharClassifier == NULL)
|
if (fCharClassifier == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
error = fTextBuffer->Init(fColumns, fRows, fScrBufSize);
|
status_t error = fTextBuffer->Init(fColumns, fRows, fScrBufSize);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
fTextBuffer->SetEncoding(fEncoding);
|
fTextBuffer->SetEncoding(fEncoding);
|
||||||
@@ -394,7 +388,6 @@ TermView::~TermView()
|
|||||||
delete fAutoScrollRunner;
|
delete fAutoScrollRunner;
|
||||||
delete fCharClassifier;
|
delete fCharClassifier;
|
||||||
delete fVisibleTextBuffer;
|
delete fVisibleTextBuffer;
|
||||||
delete[] fTermColorTable;
|
|
||||||
delete fTextBuffer;
|
delete fTextBuffer;
|
||||||
delete shell;
|
delete shell;
|
||||||
}
|
}
|
||||||
@@ -657,7 +650,7 @@ TermView::SetTermColor(uint index, rgb_color color, bool dynamic)
|
|||||||
{
|
{
|
||||||
if (!dynamic) {
|
if (!dynamic) {
|
||||||
if (index < kTermColorCount)
|
if (index < kTermColorCount)
|
||||||
fTermColorTable[index] = color;
|
fTextBuffer->SetPaletteColor(index, color);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,12 +663,12 @@ TermView::SetTermColor(uint index, rgb_color color, bool dynamic)
|
|||||||
SetLowColor(fTextBackColor);
|
SetLowColor(fTextBackColor);
|
||||||
break;
|
break;
|
||||||
case 110:
|
case 110:
|
||||||
fTextForeColor =
|
fTextForeColor = PrefHandler::Default()->getRGB(
|
||||||
PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR);
|
PREF_TEXT_FORE_COLOR);
|
||||||
break;
|
break;
|
||||||
case 111:
|
case 111:
|
||||||
fTextBackColor =
|
fTextBackColor = PrefHandler::Default()->getRGB(
|
||||||
PrefHandler::Default()->getRGB(PREF_TEXT_BACK_COLOR);
|
PREF_TEXT_BACK_COLOR);
|
||||||
SetLowColor(fTextBackColor);
|
SetLowColor(fTextBackColor);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -951,9 +944,9 @@ TermView::_DrawLinePart(int32 x1, int32 y1, uint32 attr, char *buf,
|
|||||||
int backcolor = IS_BACKCOLOR(attr);
|
int backcolor = IS_BACKCOLOR(attr);
|
||||||
|
|
||||||
if (IS_FORESET(attr))
|
if (IS_FORESET(attr))
|
||||||
rgb_fore = fTermColorTable[forecolor];
|
rgb_fore = fTextBuffer->PaletteColor(forecolor);
|
||||||
if (IS_BACKSET(attr))
|
if (IS_BACKSET(attr))
|
||||||
rgb_back = fTermColorTable[backcolor];
|
rgb_back = fTextBuffer->PaletteColor(backcolor);
|
||||||
|
|
||||||
// printf("DLP:[%03x %03x %03x]; [%03x %03x %03x];\n",
|
// 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);
|
// rgb_fore.red, rgb_fore.green, rgb_fore.blue, rgb_back.red, rgb_back.green, rgb_back.blue);
|
||||||
@@ -1064,7 +1057,7 @@ TermView::_DrawCursor()
|
|||||||
fCursor.y - firstVisible);
|
fCursor.y - firstVisible);
|
||||||
|
|
||||||
if (IS_BACKSET(attr))
|
if (IS_BACKSET(attr))
|
||||||
rgb_back = fTermColorTable[IS_BACKCOLOR(attr)];
|
rgb_back = fTextBuffer->PaletteColor(IS_BACKCOLOR(attr));
|
||||||
SetHighColor(rgb_back);
|
SetHighColor(rgb_back);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1272,7 +1265,8 @@ TermView::Draw(BRect updateRect)
|
|||||||
? fSelectBackColor : fTextBackColor;
|
? fSelectBackColor : fTextBackColor;
|
||||||
|
|
||||||
if (fTextBuffer->IsAlternateScreenActive()) {
|
if (fTextBuffer->IsAlternateScreenActive()) {
|
||||||
// alternate screen uses cell attributes beyond the line ends
|
// alternate screen uses cell attributes
|
||||||
|
// beyond the line ends
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
fTextBuffer->GetCellAttributes(j, i, attr, count);
|
fTextBuffer->GetCellAttributes(j, i, attr, count);
|
||||||
rect.right = rect.left + fFontWidth * count - 1;
|
rect.right = rect.left + fFontWidth * count - 1;
|
||||||
@@ -1280,8 +1274,11 @@ TermView::Draw(BRect updateRect)
|
|||||||
} else
|
} else
|
||||||
attr = fVisibleTextBuffer->GetLineColor(j - firstVisible);
|
attr = fVisibleTextBuffer->GetLineColor(j - firstVisible);
|
||||||
|
|
||||||
if (IS_BACKSET(attr))
|
if (IS_BACKSET(attr)) {
|
||||||
rgb_back = fTermColorTable[IS_BACKCOLOR(attr)];
|
int backcolor = IS_BACKCOLOR(attr);
|
||||||
|
rgb_back = fTextBuffer->PaletteColor(backcolor);
|
||||||
|
}
|
||||||
|
|
||||||
SetHighColor(rgb_back);
|
SetHighColor(rgb_back);
|
||||||
rgb_back = HighColor();
|
rgb_back = HighColor();
|
||||||
FillRect(rect);
|
FillRect(rect);
|
||||||
@@ -1893,7 +1890,8 @@ TermView::MessageReceived(BMessage *msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (index < kTermColorCount)
|
if (index < kTermColorCount)
|
||||||
SetTermColor(index, fTermColorTable[index], dynamic);
|
SetTermColor(index,
|
||||||
|
TermApp::DefaultPalette()[index], dynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -3230,51 +3228,6 @@ TermView::_CancelInputMethod()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
TermView::_InitColorTable()
|
|
||||||
{
|
|
||||||
fTermColorTable = new(std::nothrow) rgb_color[kTermColorCount];
|
|
||||||
if (fTermColorTable == NULL)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
// 0 - 15 are system ANSI colors
|
|
||||||
const char * keys[kANSIColorCount] = {
|
|
||||||
PREF_ANSI_BLACK_COLOR,
|
|
||||||
PREF_ANSI_RED_COLOR,
|
|
||||||
PREF_ANSI_GREEN_COLOR,
|
|
||||||
PREF_ANSI_YELLOW_COLOR,
|
|
||||||
PREF_ANSI_BLUE_COLOR,
|
|
||||||
PREF_ANSI_MAGENTA_COLOR,
|
|
||||||
PREF_ANSI_CYAN_COLOR,
|
|
||||||
PREF_ANSI_WHITE_COLOR,
|
|
||||||
PREF_ANSI_BLACK_HCOLOR,
|
|
||||||
PREF_ANSI_RED_HCOLOR,
|
|
||||||
PREF_ANSI_GREEN_HCOLOR,
|
|
||||||
PREF_ANSI_YELLOW_HCOLOR,
|
|
||||||
PREF_ANSI_BLUE_HCOLOR,
|
|
||||||
PREF_ANSI_MAGENTA_HCOLOR,
|
|
||||||
PREF_ANSI_CYAN_HCOLOR,
|
|
||||||
PREF_ANSI_WHITE_HCOLOR
|
|
||||||
};
|
|
||||||
|
|
||||||
rgb_color* color = fTermColorTable;
|
|
||||||
PrefHandler* handler = PrefHandler::Default();
|
|
||||||
for (uint i = 0; i < kANSIColorCount; i++)
|
|
||||||
*color++ = handler->getRGB(keys[i]);
|
|
||||||
|
|
||||||
// 16 - 231 are 6x6x6 color "cubes" in xterm color model
|
|
||||||
for (uint red = 0; red < 256; red += (red == 0) ? 95 : 40)
|
|
||||||
for (uint green = 0; green < 256; green += (green == 0) ? 95 : 40)
|
|
||||||
for (uint blue = 0; blue < 256; blue += (blue == 0) ? 95 : 40)
|
|
||||||
(*color++).set_to(red, green, blue);
|
|
||||||
|
|
||||||
// 232 - 255 are grayscale ramp in xterm color model
|
|
||||||
for (uint gray = 8; gray < 240; gray += 10)
|
|
||||||
(*color++).set_to(gray, gray, gray);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #pragma mark - Listener
|
// #pragma mark - Listener
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ private:
|
|||||||
|
|
||||||
status_t _InitObject(
|
status_t _InitObject(
|
||||||
const ShellParameters& shellParameters);
|
const ShellParameters& shellParameters);
|
||||||
status_t _InitColorTable();
|
|
||||||
|
|
||||||
status_t _AttachShell(Shell* shell);
|
status_t _AttachShell(Shell* shell);
|
||||||
void _DetachShell();
|
void _DetachShell();
|
||||||
@@ -274,8 +273,6 @@ private:
|
|||||||
rgb_color fSelectForeColor;
|
rgb_color fSelectForeColor;
|
||||||
rgb_color fSelectBackColor;
|
rgb_color fSelectBackColor;
|
||||||
|
|
||||||
rgb_color* fTermColorTable;
|
|
||||||
|
|
||||||
// Scroll Region
|
// Scroll Region
|
||||||
float fScrollOffset;
|
float fScrollOffset;
|
||||||
int32 fScrBufSize;
|
int32 fScrBufSize;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
|
#include "Colors.h"
|
||||||
|
#include "TermApp.h"
|
||||||
#include "TermConst.h"
|
#include "TermConst.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +24,7 @@ TerminalBuffer::TerminalBuffer()
|
|||||||
fAlternateScreen(NULL),
|
fAlternateScreen(NULL),
|
||||||
fAlternateHistory(NULL),
|
fAlternateHistory(NULL),
|
||||||
fAlternateScreenOffset(0),
|
fAlternateScreenOffset(0),
|
||||||
|
fColorsPalette(NULL),
|
||||||
fListenerValid(false)
|
fListenerValid(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -31,6 +34,7 @@ TerminalBuffer::~TerminalBuffer()
|
|||||||
{
|
{
|
||||||
delete fAlternateScreen;
|
delete fAlternateScreen;
|
||||||
delete fAlternateHistory;
|
delete fAlternateHistory;
|
||||||
|
delete[] fColorsPalette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +51,13 @@ TerminalBuffer::Init(int32 width, int32 height, int32 historySize)
|
|||||||
for (int32 i = 0; i < height; i++)
|
for (int32 i = 0; i < height; i++)
|
||||||
fAlternateScreen[i]->Clear();
|
fAlternateScreen[i]->Clear();
|
||||||
|
|
||||||
|
fColorsPalette = new(std::nothrow) rgb_color[kTermColorCount];
|
||||||
|
if (fColorsPalette == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
memcpy(fColorsPalette, TermApp::DefaultPalette(),
|
||||||
|
sizeof(rgb_color) * kTermColorCount);
|
||||||
|
|
||||||
return BasicTerminalBuffer::Init(width, height, historySize);
|
return BasicTerminalBuffer::Init(width, height, historySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +222,42 @@ TerminalBuffer::SetCursorHidden(bool hidden)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TerminalBuffer::SetPaletteColor(uint8 index, rgb_color color)
|
||||||
|
{
|
||||||
|
if (index < kTermColorCount)
|
||||||
|
fColorsPalette[index] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rgb_color
|
||||||
|
TerminalBuffer::PaletteColor(uint8 index)
|
||||||
|
{
|
||||||
|
return fColorsPalette[min_c(index, kTermColorCount - 1)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
TerminalBuffer::GuessPaletteColor(int red, int green, int blue)
|
||||||
|
{
|
||||||
|
int distance = 255 * 100;
|
||||||
|
int index = -1;
|
||||||
|
for (int i = 0; i < kTermColorCount && distance > 0; i++) {
|
||||||
|
rgb_color color = fColorsPalette[i];
|
||||||
|
int r = 30 * abs(color.red - red);
|
||||||
|
int g = 59 * abs(color.green - green);
|
||||||
|
int b = 11 * abs(color.blue - blue);
|
||||||
|
int d = r + g + b;
|
||||||
|
if (distance > d) {
|
||||||
|
index = i;
|
||||||
|
distance = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return min_c(index, kTermColorCount - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TerminalBuffer::NotifyQuit(int32 reason)
|
TerminalBuffer::NotifyQuit(int32 reason)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ public:
|
|||||||
void SetCursorStyle(int32 style, bool blinking);
|
void SetCursorStyle(int32 style, bool blinking);
|
||||||
void SetCursorBlinking(bool blinking);
|
void SetCursorBlinking(bool blinking);
|
||||||
void SetCursorHidden(bool hidden);
|
void SetCursorHidden(bool hidden);
|
||||||
|
void SetPaletteColor(uint8 index, rgb_color color);
|
||||||
|
rgb_color PaletteColor(uint8 index);
|
||||||
|
int GuessPaletteColor(int red, int green, int blue);
|
||||||
|
|
||||||
void NotifyQuit(int32 reason);
|
void NotifyQuit(int32 reason);
|
||||||
|
|
||||||
@@ -61,6 +64,7 @@ private:
|
|||||||
TerminalLine** fAlternateScreen;
|
TerminalLine** fAlternateScreen;
|
||||||
HistoryBuffer* fAlternateHistory;
|
HistoryBuffer* fAlternateHistory;
|
||||||
int32 fAlternateScreenOffset;
|
int32 fAlternateScreenOffset;
|
||||||
|
rgb_color* fColorsPalette;
|
||||||
|
|
||||||
// listener/dirty region management
|
// listener/dirty region management
|
||||||
BMessenger fListener;
|
BMessenger fListener;
|
||||||
|
|||||||
Reference in New Issue
Block a user