Skip to content

Commit

Permalink
Maximus5gh-1244: GuiMacro: Use SetOption to change color palettes.
Browse files Browse the repository at this point in the history
  * `SetOption("Scheme", "<SchemeName>")` changes color palette for the whole ConEmu window
  * `SetOption("VConScheme", "<SchemeName>")` changes color palette for the active console

  For example, user may execute from the active shell prompt:

~~~
ConEmuC -GuiMacro SetOption Scheme "<Tomorrow>"
~~~
  • Loading branch information
Maximus5 committed Sep 7, 2017
1 parent 9ae92a2 commit ed8864f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/ConEmu/About.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ _DBGHLP(L"-ZoneId - Try to drop :Zone.Identifier without confirmation.\r\n") \
L" Value: path to the executable with arguments\r\n" \
L" \"QuakeAutoHide\": auto hide on focus lose, Quake mode\r\n" \
L" Value: 2 - switch auto-hide, 1 - enable, 0 - disable\r\n" \
L" \"Scheme\": switch color scheme for the whole ConEmu window\r\n" \
L" \"VConScheme\": switch color scheme for the active console\r\n" \
L" Value: color palette name, e.g. \"<Solarized>\"\r\n" \
L"Settings([<PageResourceId>])\r\n" \
L" - Show ‘Settings’ dialog with specified page activated (optionally)\r\n" \
L" PageResourceId: integer DialogID from ‘resource.h’\r\n" \
Expand Down
12 changes: 11 additions & 1 deletion src/ConEmu/Macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3113,14 +3113,24 @@ LPWSTR ConEmuMacro::SetOption(GuiMacro* p, CRealConsole* apRCon, bool abFromPlug
if (p->GetIntArg(1, nValue))
pszResult = gpSetCls->SetOption(pszName, nValue) ? lstrdup(L"OK") : NULL;
}
else if (!lstrcmpi(pszName, L"FarGotoEditorPath"))
else if (!lstrcmpi(pszName, L"FarGotoEditorPath")
|| !lstrcmpi(pszName, L"Scheme"))
{
if (p->GetStrArg(1, pszValue))
pszResult = gpSetCls->SetOption(pszName, pszValue) ? lstrdup(L"OK") : NULL;
}
else if (!lstrcmpi(pszName, L"VConScheme"))
{
if (apRCon && p->GetStrArg(1, pszValue))
{
CVConGuard VCon(apRCon ? apRCon->VCon() : NULL);
pszResult = VCon->ChangePalette(pszValue) ? lstrdup(L"OK") : NULL;
}
}
else
{
//TODO: More options on demand
_ASSERTE(FALSE && "Option is not supported yet");
}

return pszResult ? pszResult : lstrdup(L"UnknownOption");
Expand Down
9 changes: 9 additions & 0 deletions src/ConEmu/OptionsClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,15 @@ bool CSettings::SetOption(LPCWSTR asName, LPCWSTR asValue)
lbRc = true;
}
}
else if (!lstrcmpi(asName, L"Scheme"))
{
const ColorPalette* pPal = gpSet->PaletteGetByName(asValue);
if (pPal)
{
ChangeCurrentPalette(pPal, true);
lbRc = true;
}
}
else
{
_ASSERTE(FALSE && "Unsupported parameter name");
Expand Down
13 changes: 12 additions & 1 deletion src/ConEmu/VirtualConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2592,12 +2592,23 @@ int CVirtualConsole::GetPaletteIndex()
}

bool CVirtualConsole::ChangePalette(int aNewPaletteIdx)
{
const ColorPalette* pPal = gpSet->PaletteGet(aNewPaletteIdx);
return ChangePalette(pPal);
}

bool CVirtualConsole::ChangePalette(LPCWSTR asNewPalette)
{
const ColorPalette* pPal = gpSet->PaletteGetByName(asNewPalette);
return ChangePalette(pPal);
}

bool CVirtualConsole::ChangePalette(const ColorPalette* pPal)
{
if (!this || !mp_RCon)
return false;

const ColorPalette* pOldPal = gpSet->PaletteGet(GetPaletteIndex());
const ColorPalette* pPal = gpSet->PaletteGet(aNewPaletteIdx);
if (!pPal)
return false;

Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/VirtualConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class CVirtualConsole :
COLORREF* GetColors(bool bFade);
int GetPaletteIndex();
bool ChangePalette(int aNewPaletteIdx);
bool ChangePalette(LPCWSTR asNewPalette);
bool ChangePalette(const ColorPalette* pPal);
void PaintVCon(HDC hPaintDc);
bool PrintClient(HDC hPrintDc, bool bAllowRepaint, const LPRECT PaintRect);
bool Blit(HDC hPaintDC, int anX, int anY, int anShowWidth, int anShowHeight);
Expand Down

0 comments on commit ed8864f

Please sign in to comment.