From c963d577c0b6e22840255a3c097307ea7f97f830 Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Sun, 6 Feb 2022 19:08:20 +0100 Subject: [PATCH] Fixed issue #3860: Highlight keywords, such as error, fatal and warning in output of git commands Add method StyleWarningsErrors() to parse lines in the output of git commands. Lines starting with "error:" and "fatal:" or "warning:" are highlighted with bold font and color red or yellow, respectively. Method is invoked after all git commands finished. Signed-off-by: Michael Bauer Signed-off-by: Sven Strickroth --- .../TortoiseGit/tgit_dug/dug_settings_advanced.xml | 11 ++++++ src/Changelog.txt | 3 ++ src/TortoiseProc/AppUtils.cpp | 40 +++++++++++++++++++++- src/TortoiseProc/AppUtils.h | 6 +++- src/TortoiseProc/ProgressDlg.cpp | 4 ++- src/TortoiseProc/Settings/SettingsAdvanced.cpp | 4 +++ src/TortoiseProc/SyncDlg.cpp | 2 ++ 7 files changed, 67 insertions(+), 3 deletions(-) diff --git a/doc/source/en/TortoiseGit/tgit_dug/dug_settings_advanced.xml b/doc/source/en/TortoiseGit/tgit_dug/dug_settings_advanced.xml index a2a36e7d7..0b517d8d2 100644 --- a/doc/source/en/TortoiseGit/tgit_dug/dug_settings_advanced.xml +++ b/doc/source/en/TortoiseGit/tgit_dug/dug_settings_advanced.xml @@ -491,6 +491,17 @@ + StyleGitOutput + + + The Git.exe progress dialogs shows the output of a Git.exe + process and use colors to highlights errors and warnings. + If you don't want to do this, set the value to + false. + + + + TGitCacheCheckContentMaxSize diff --git a/src/Changelog.txt b/src/Changelog.txt index 144a38b71..1c23d2d81 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -1,6 +1,9 @@ = Release 2.14.0 = Released: unreleased +== Features == +* Fixed issue #3860: Highlight keywords, such as error, fatal and warning in output of git commands + == Bug Fixes == * Fixed issue #3865: Ampersand in branch name not shown in Windows context menu * Fixed issue #3868: 2.13 has bug for clone without checkout diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 3dbc16eaf..5692d2454 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2021 - TortoiseGit +// Copyright (C) 2008-2022 - TortoiseGit // Copyright (C) 2003-2011, 2013-2014 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -929,6 +929,44 @@ namespace { } } +BOOL CAppUtils::StyleWarningsErrors(const CString& text, CRichEditCtrl* edit) +{ + ASSERT(edit); + + if (text.IsEmpty()) + return FALSE; + const auto fnFindMatchAtLineStart = [&](const wchar_t* const needle, int idxStart, std::vector& vRange) -> void { + const int idxEnd{ idxStart + static_cast(wcslen(needle)) }; + if (idxEnd > text.GetLength()) + return; + + if (CStringUtils::StartsWith(static_cast(text) + idxStart, needle)) + { + const CHARRANGE range{ idxStart, idxEnd }; + vRange.push_back(range); + } + }; + + std::vector rangeErrors; + std::vector rangeWarnings; + int idxStart = 0; + do + { + fnFindMatchAtLineStart(L"fatal: ", idxStart, rangeErrors); + fnFindMatchAtLineStart(L"error: ", idxStart, rangeErrors); + fnFindMatchAtLineStart(L"warning: ", idxStart, rangeWarnings); + } while ((idxStart = text.Find('\n', idxStart) + 1) > 0 && idxStart < text.GetLength()); + + const COLORREF colorError{CTheme::Instance().IsDarkTheme() ? RGB(207, 47, 47) : RGB(255, 0, 0)}; + CAppUtils::SetCharFormat(edit, CFM_BOLD, CFE_BOLD, rangeErrors); + CAppUtils::SetCharFormat(edit, CFM_COLOR, colorError, rangeErrors); + const COLORREF colorWarning{CTheme::Instance().IsDarkTheme() ? RGB(185, 185, 0) : RGB(160, 160, 0)}; + CAppUtils::SetCharFormat(edit, CFM_BOLD, CFE_BOLD, rangeWarnings); + CAppUtils::SetCharFormat(edit, CFM_COLOR, colorWarning, rangeWarnings); + + return (rangeErrors.empty() && rangeWarnings.empty() ? FALSE : TRUE); +} + BOOL CAppUtils::StyleURLs(const CString& msg, CWnd* pWnd) { std::vector positions = FindURLMatches(msg); diff --git a/src/TortoiseProc/AppUtils.h b/src/TortoiseProc/AppUtils.h index 5d128d815..0329fe4a3 100644 --- a/src/TortoiseProc/AppUtils.h +++ b/src/TortoiseProc/AppUtils.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2020 - TortoiseGit +// Copyright (C) 2008-2020, 2022 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -128,6 +128,10 @@ public: static bool FormatTextInRichEditControl(CWnd * pWnd); static bool FindStyleChars(const CString& sText, wchar_t stylechar, int& start, int& end); /** + * highlight warnings and errors returned by git command in rich edit control colored in bold + */ + static BOOL StyleWarningsErrors(const CString& text, CRichEditCtrl* edit); + /** * implements URL searching with the same logic as CSciEdit::StyleURLs */ static std::vector FindURLMatches(const CString& msg); diff --git a/src/TortoiseProc/ProgressDlg.cpp b/src/TortoiseProc/ProgressDlg.cpp index d968aa525..df36631d5 100644 --- a/src/TortoiseProc/ProgressDlg.cpp +++ b/src/TortoiseProc/ProgressDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2020 - TortoiseGit +// Copyright (C) 2008-2020, 2022 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -395,6 +395,8 @@ LRESULT CProgressDlg::OnProgressUpdateUI(WPARAM wParam, LPARAM lParam) CString text; m_Log.GetWindowText(text); text.Remove('\r'); + if (static_cast(CRegStdDWORD(L"Software\\TortoiseGit\\StyleGitOutput", TRUE)) == TRUE) + CAppUtils::StyleWarningsErrors(text, &m_Log); CAppUtils::StyleURLs(text, &m_Log); } diff --git a/src/TortoiseProc/Settings/SettingsAdvanced.cpp b/src/TortoiseProc/Settings/SettingsAdvanced.cpp index 188d3052c..39f366a3d 100644 --- a/src/TortoiseProc/Settings/SettingsAdvanced.cpp +++ b/src/TortoiseProc/Settings/SettingsAdvanced.cpp @@ -199,6 +199,10 @@ CSettingsAdvanced::CSettingsAdvanced() settings[i].type = CSettingsAdvanced::SettingTypeBoolean; settings[i++].def.b = true; + settings[i].sName = L"StyleGitOutput"; + settings[i].type = CSettingsAdvanced::SettingTypeBoolean; + settings[i++].def.b = true; + settings[i].sName = L"TGitCacheCheckContentMaxSize"; settings[i].type = CSettingsAdvanced::SettingTypeNumber; settings[i++].def.l = 10 * 1024; diff --git a/src/TortoiseProc/SyncDlg.cpp b/src/TortoiseProc/SyncDlg.cpp index b98e06e90..ba13a1d36 100644 --- a/src/TortoiseProc/SyncDlg.cpp +++ b/src/TortoiseProc/SyncDlg.cpp @@ -1448,6 +1448,8 @@ LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam) CString text; m_ctrlCmdOut.GetWindowText(text); text.Remove('\r'); + if (static_cast(CRegStdDWORD(L"Software\\TortoiseGit\\StyleGitOutput", TRUE)) == TRUE) + CAppUtils::StyleWarningsErrors(text, &m_ctrlCmdOut); CAppUtils::StyleURLs(text, &m_ctrlCmdOut); } -- 2.11.4.GIT