From b4e3e076b8b42e93c072a7611698b04a9d34a087 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Wed, 11 Jan 2023 14:58:44 -0500 Subject: [PATCH] Support colouring of WriteStatusLog messages If the prefix string includes ERROR or WARNING these messages are now shown in colour (red or yellow) similar to how log lines are displayed. Signed-off-by: Selva Nair --- openvpn.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/openvpn.c b/openvpn.c index c5823ca..41bd94e 100644 --- a/openvpn.c +++ b/openvpn.c @@ -1528,6 +1528,29 @@ WriteStatusLog (connection_t *c, const WCHAR *prefix, const WCHAR *line, BOOL fi wcsncpy (datetime, _wctime(&now), _countof(datetime)); datetime[24] = L' '; + /* change text color if Warning or Error */ + COLORREF text_clr = 0; + + if (wcsstr(prefix, L"ERROR")) + { + text_clr = o.clr_error; + } + else if (wcsstr(prefix, L"WARNING")) + { + text_clr = o.clr_warning; + } + + if (text_clr != 0) + { + CHARFORMAT cfm = { .cbSize = sizeof(CHARFORMAT), + .dwMask = CFM_COLOR|CFM_BOLD, + .dwEffects = 0, + .crTextColor = text_clr, + }; + SendMessage(logWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cfm); + } + + /* Remove lines from log window if it is getting full */ if (SendMessage(logWnd, EM_GETLINECOUNT, 0, 0) > MAX_LOG_LINES) {