Terminal: handle color queries
this allows apps like vim to select a color scheme based on a dark or light background. Change-Id: Ia9f98d2373523a8b5fa379225a1c906ae075edf7 Reviewed-on: https://review.haiku-os.org/c/haiku/+/4693 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
fe3e5f05a1
commit
f78b75b15d
@ -87,6 +87,7 @@ static const uint32 MSG_MOVE_TAB_LEFT = 'mvtl';
|
||||
static const uint32 MSG_MOVE_TAB_RIGHT = 'mvtr';
|
||||
static const uint32 MSG_ACTIVATE_TERM = 'msat';
|
||||
static const uint32 MSG_SET_CURSOR_STYLE = 'mscs';
|
||||
static const uint32 MSG_GET_TERMINAL_COLOR = 'getc';
|
||||
|
||||
|
||||
// Preference Read/Write Keys
|
||||
|
@ -1571,6 +1571,10 @@ TermParse::_ProcessOperatingSystemControls(uchar* params)
|
||||
{
|
||||
int32 offset = mode - 10;
|
||||
int32 count = 0;
|
||||
if (strcmp((char*)params, "?") == 0) {
|
||||
fBuffer->GetColor(mode);
|
||||
break;
|
||||
}
|
||||
char* p = strtok((char*)params, ";");
|
||||
do {
|
||||
if (gXColorsTable.LookUpColor(p, &colors[count]) != B_OK) {
|
||||
|
@ -720,6 +720,30 @@ TermView::SetTermColor(uint index, rgb_color color, bool dynamic)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TermView::GetTermColor(uint index, rgb_color* color)
|
||||
{
|
||||
if (color == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
switch (index) {
|
||||
case 10:
|
||||
*color = fTextForeColor;
|
||||
break;
|
||||
case 11:
|
||||
*color = fTextBackColor;
|
||||
break;
|
||||
case 12:
|
||||
*color = fCursorBackColor;
|
||||
break;
|
||||
default:
|
||||
return B_BAD_VALUE;
|
||||
break;
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
TermView::Encoding() const
|
||||
{
|
||||
@ -1833,6 +1857,21 @@ TermView::MessageReceived(BMessage *message)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_GET_TERMINAL_COLOR:
|
||||
{
|
||||
uint8 index = 0;
|
||||
if (message->FindUInt8("index", &index) != B_OK)
|
||||
break;
|
||||
rgb_color color;
|
||||
status_t status = GetTermColor(index, &color);
|
||||
if (status == B_OK) {
|
||||
BString reply;
|
||||
reply.SetToFormat("\033]%u;rgb:%02x/%02x/%02x\033\\",
|
||||
index, color.red, color.green, color.blue);
|
||||
fShell->Write(reply.String(), reply.Length());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_SET_CURSOR_STYLE:
|
||||
{
|
||||
int32 style = BLOCK_CURSOR;
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
void SetSelectColor(rgb_color fore, rgb_color back);
|
||||
void SetTermColor(uint index, rgb_color color,
|
||||
bool dynamic = false);
|
||||
status_t GetTermColor(uint index, rgb_color* color);
|
||||
|
||||
int Encoding() const;
|
||||
void SetEncoding(int encoding);
|
||||
|
@ -228,6 +228,17 @@ TerminalBuffer::ResetColors(uint8* indexes, int32 count, bool dynamic)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TerminalBuffer::GetColor(uint8 index)
|
||||
{
|
||||
if (fListenerValid) {
|
||||
BMessage message(MSG_GET_TERMINAL_COLOR);
|
||||
message.AddUInt8("index", index);
|
||||
fListener.SendMessage(&message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TerminalBuffer::SetCursorStyle(int32 style, bool blinking)
|
||||
{
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
int32 count = 1, bool dynamic = false);
|
||||
void ResetColors(uint8* indexes,
|
||||
int32 count = 1, bool dynamic = false);
|
||||
void GetColor(uint8 index);
|
||||
void SetCursorStyle(int32 style, bool blinking);
|
||||
void SetCursorBlinking(bool blinking);
|
||||
void SetCursorHidden(bool hidden);
|
||||
|
Loading…
Reference in New Issue
Block a user