From 7f2c8e1885f8e0cc74a3de206c8cf564b7b54124 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Fri, 1 Oct 2021 10:15:22 -0400 Subject: Added some improved embedded terminal creation routines. Added messages to change foreground and background colors. --- RadTerminal.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 7 deletions(-) (limited to 'RadTerminal.cpp') diff --git a/RadTerminal.cpp b/RadTerminal.cpp index a53b238..5be8fce 100644 --- a/RadTerminal.cpp +++ b/RadTerminal.cpp @@ -10,7 +10,27 @@ #include "resource.h" #include "RadTerminal.h" -#define RADTERM_DEAD WM_USER+1 +static uint8_t color_default_pallette[TSM_COLOR_NUM][3] = { + { 7, 54, 66 }, /* black */ + { 220, 50, 47 }, /* red */ + { 133, 153, 0 }, /* green */ + { 181, 137, 0 }, /* yellow */ + { 38, 139, 210 }, /* blue */ + { 211, 54, 130 }, /* magenta */ + { 42, 161, 152 }, /* cyan */ + { 238, 232, 213 }, /* light grey */ + { 0, 43, 54 }, /* dark grey */ + { 203, 75, 22 }, /* light red */ + { 88, 110, 117 }, /* light green */ + { 101, 123, 131 }, /* light yellow */ + { 131, 148, 150 }, /* light blue */ + { 108, 113, 196 }, /* light magenta */ + { 147, 161, 161 }, /* light cyan */ + { 253, 246, 227 }, /* white */ + + { 7, 54, 66 }, /* black */ + { 238, 232, 213 }, /* light grey */ +}; // TODO // https://stackoverflow.com/questions/5966903/how-to-get-mousemove-and-mouseclick-in-bash @@ -185,14 +205,17 @@ RadTerminalCreate GetTerminalCreate(bool bParseCmdLine, std::tstring profile) #ifdef BUILD_AS_DLL extern "C" { - __declspec(dllexport) HWND WINAPI CreateTerminalWindow(HINSTANCE hInstance, HWND hParent, BOOL darkMode) + __declspec(dllexport) HWND WINAPI CreateTerminalWindowExW(HINSTANCE hInstance, HWND hParent, LPWSTR fontFace, int fontSize, BOOL darkMode) { HWND hRet; - + RadTerminalCreate rtc = GetTerminalCreate(true, TEXT("")); - if (darkMode) - InitDarkMode(); + if(fontSize > 0) + rtc.iFontHeight = fontSize; + + if (fontFace != NULL) + rtc.strFontFace = std::tstring(fontFace); hRet = CreateWindowEx( WS_EX_ACCEPTFILES, @@ -215,6 +238,28 @@ extern "C" { return hRet; } + __declspec(dllexport) HWND WINAPI CreateTerminalWindowExA(HINSTANCE hInstance, HWND hParent, LPCSTR fontFace, int fontSize, BOOL darkMode) + { + HWND hRet; + LPWSTR fontFaceW; + + fontFaceW = NULL; + if (fontFace != NULL) { + int fflen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fontFace, strlen(fontFace), NULL, 0); + fontFaceW = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (fflen + 1) * sizeof(WCHAR)); + if (fontFaceW != NULL) { + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fontFace, strlen(fontFace), fontFaceW, fflen + 1); + } + } + + return CreateTerminalWindowExW(hInstance, hParent, fontFaceW, fontSize, darkMode); + } + + __declspec(dllexport) HWND WINAPI CreateTerminalWindow(HINSTANCE hInstance, HWND hParent, BOOL darkMode) + { + return CreateTerminalWindowExW(hInstance, hParent, NULL, -1, darkMode); + } + } /* extern "C" */ #else @@ -554,6 +599,25 @@ void tsm_vte_osc(struct tsm_vte *vte, } } +void tsm_adjust_pallette(struct tsm_vte* vte, COLORREF *fg, COLORREF *bg) +{ + + if (fg != NULL) { + color_default_pallette[TSM_COLOR_FOREGROUND][0] = GetRValue(*fg); + color_default_pallette[TSM_COLOR_FOREGROUND][1] = GetGValue(*fg); + color_default_pallette[TSM_COLOR_FOREGROUND][2] = GetBValue(*fg); + } + + if (bg != NULL) { + color_default_pallette[TSM_COLOR_BACKGROUND][0] = GetRValue(*bg); + color_default_pallette[TSM_COLOR_BACKGROUND][1] = GetGValue(*bg); + color_default_pallette[TSM_COLOR_BACKGROUND][2] = GetBValue(*bg); + } + + tsm_vte_set_custom_palette(vte, color_default_pallette); + tsm_vte_set_palette(vte, "custom"); +} + struct RadTerminalData { struct tsm_screen *screen; @@ -1333,6 +1397,18 @@ void RadTerminalWindowOnDropFiles(HWND hWnd, HDROP hDrop) DragFinish(hDrop); } +void RadTerminalWindowOnSetForeColor(HWND hWnd, COLORREF fg) +{ + const RadTerminalData* const data = (RadTerminalData*)GetWindowLongPtr(hWnd, GWLP_USERDATA); + tsm_adjust_pallette(data->vte, &fg, NULL); +} + +void RadTerminalWindowOnSetBkgdColor(HWND hWnd, COLORREF bg) +{ + const RadTerminalData* const data = (RadTerminalData*)GetWindowLongPtr(hWnd, GWLP_USERDATA); + tsm_adjust_pallette(data->vte, NULL, &bg); +} + void RadTerminalWindowOnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { switch (id) @@ -1352,7 +1428,13 @@ LRESULT RadTerminalWindowOnWatch(HWND hWnd, WPARAM wParam, LPARAM lParam) if (h == data->spd.pi.hProcess) { #ifdef BUILD_AS_DLL - SendMessage(GetParent(hWnd), RADTERM_DEAD, (WPARAM)0, (LPARAM)hWnd); + NMHDR hdr; + + hdr.hwndFrom = hWnd; + hdr.idFrom = 0; + hdr.code = RADTERM_DEAD; + + SendMessage(GetParent(hWnd), WM_NOTIFY, (WPARAM)0, (LPARAM)&hdr); #else PostMessage(hWnd, WM_CLOSE, 0, 0); #endif @@ -1416,6 +1498,14 @@ LRESULT CALLBACK RadTerminalWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR HANDLE_MSG(hWnd, WM_COMMAND, RadTerminalWindowOnCommand); HANDLE_STD_MSG(hWnd, WM_WATCH, RadTerminalWindowOnWatch); HANDLE_STD_MSG(hWnd, WM_READ, RadTerminalWindowOnRead); - default: return MyDefWindowProc(hWnd, uMsg, wParam, lParam); + + case RADTERM_SETFORECOLOR: + RadTerminalWindowOnSetForeColor(hWnd, (COLORREF)wParam); + return TRUE; + case RADTERM_SETBKGDCOLOR: + RadTerminalWindowOnSetBkgdColor(hWnd, (COLORREF)wParam); + return TRUE; + default: + return MyDefWindowProc(hWnd, uMsg, wParam, lParam); } } -- cgit v1.2.3