From 6b4e6d301a360c7d04e6dae067679b2ba0560dc9 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 1 Mar 2021 16:17:33 -0500 Subject: [PATCH] Delete old messages in the window when content grows beyond a limit --- echo.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/echo.c b/echo.c index a071c25..14f95c4 100644 --- a/echo.c +++ b/echo.c @@ -42,6 +42,9 @@ extern options_t o; #define ECHO_MSG_WINDOW (1) #define ECHO_MSG_NOTIFY (2) +/* Old text in the window is deleted when content grows beyond this many lines */ +#define MAX_MSG_LINES 1000 + struct echo_msg_history { struct echo_msg_fp fp; struct echo_msg_history *next; @@ -457,6 +460,19 @@ AddMessageBoxText(HWND hwnd, const wchar_t *text, const wchar_t *title, const wc pf.wAlignment = pf_align_saved; SendMessage(hmsg, EM_SETPARAFORMAT, 0, (LPARAM) &pf); + /* Remove lines from the window if it is getting full + * We allow the window to grow by upto 50 lines beyond a + * max value before truncating + */ + int pos2 = SendMessage(hmsg, EM_GETLINECOUNT, 0, 0); + if (pos2 > MAX_MSG_LINES + 50) + { + int pos1 = SendMessage(hmsg, EM_LINEINDEX, MAX_MSG_LINES, 0); + SendMessage(hmsg, EM_SETSEL, pos1, -1); + SendMessage(hmsg, EM_REPLACESEL, FALSE, (LPARAM) _T("")); + PrintDebug(L"Text from character position %d to end removed", pos1); + } + /* Select top of the message and scroll to there */ SendMessage(hmsg, EM_SETSEL, 0, 0); SendMessage(hmsg, EM_SCROLLCARET, 0, 0);