aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RadTerminal.cpp104
-rw-r--r--RadTerminal.h16
2 files changed, 113 insertions, 7 deletions
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);
}
}
diff --git a/RadTerminal.h b/RadTerminal.h
new file mode 100644
index 0000000..382871b
--- /dev/null
+++ b/RadTerminal.h
@@ -0,0 +1,16 @@
+#pragma once
+
+
+#define RADTERM_DEAD WM_USER+1
+#define RADTERM_SETFORECOLOR WM_USER+2 /* WPARAM is color */
+#define RADTERM_SETBKGDCOLOR WM_USER+3 /* WPARAM is color */
+
+#ifndef BUILD_AS_DLL
+#ifdef RADTERM_DLL
+
+__declspec(dllimport) HWND WINAPI CreateTerminalWindowExW(HINSTANCE hInstance, HWND hParent, LPWSTR fontFace, int fontSize, BOOL darkMode);
+__declspec(dllimport) HWND WINAPI CreateTerminalWindowExA(HINSTANCE hInstance, HWND hParent, LPCSTR fontFace, int fontSize, BOOL darkMode);
+__declspec(dllimport) HWND WINAPI CreateTerminalWindow(HINSTANCE hInstance, HWND hParent, BOOL darkMode);
+
+#endif
+#endif