From: nyov Date: Mon, 12 Mar 2012 09:10:12 +0000 (+0100) Subject: chat: adding history search as in console, displaying results on console is a bit... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3eafbd62ee6e060212202f285ccc65964f6bb81b;p=xonotic%2Fdarkplaces.git chat: adding history search as in console, displaying results on console is a bit inconvenient though --- diff --git a/keys.c b/keys.c index 377cd19c..76145e6c 100644 --- a/keys.c +++ b/keys.c @@ -306,6 +306,7 @@ static void MsgKey_History_Last(void) chat_bufferpos = strlen(chat_buffer); } } + static void Key_History_Find_Backwards(void) { int i; @@ -341,6 +342,41 @@ static void Key_History_Find_Backwards(void) } } +static void MsgKey_History_Find_Backwards(void) +{ + int i; + const char *partial = chat_buffer; + char vabuf[1024]; + size_t digits = strlen(va(vabuf, sizeof(vabuf), "%i", HIST_MAXLINES)); + + if (chathistory_line == -1) // editing the "new" line + strlcpy(chathistory_savedline, chat_buffer, sizeof(chathistory_savedline)); + + if (strcmp(chat_buffer, chathistory_searchstring)) // different string? Start a new search + { + strlcpy(chathistory_searchstring, chat_buffer, sizeof(chathistory_searchstring)); + i = CONBUFFER_LINES_COUNT(&chathistory) - 1; + } + else if (chathistory_line == -1) + i = CONBUFFER_LINES_COUNT(&chathistory) - 1; + else + i = chathistory_line - 1; + + if (!*partial) + partial = "*"; + else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern? + partial = va(vabuf, sizeof(vabuf), "*%s*", partial); + + for ( ; i >= 0; i--) + if (matchpattern_with_separator(ConBuffer_GetLine(&chathistory, i), partial, true, "", false)) + { + Con_Printf("^2%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&chathistory, i)); + chathistory_line = i; + chathistory_matchfound = true; + return; + } +} + static void Key_History_Find_Forwards(void) { int i; @@ -373,6 +409,38 @@ static void Key_History_Find_Forwards(void) } } +static void MsgKey_History_Find_Forwards(void) +{ + int i; + const char *partial = chat_buffer; + char vabuf[1024]; + size_t digits = strlen(va(vabuf, sizeof(vabuf), "%i", HIST_MAXLINES)); + + if (chathistory_line == -1) // editing the "new" line + return; + + if (strcmp(chat_buffer, chathistory_searchstring)) // different string? Start a new search + { + strlcpy(chathistory_searchstring, chat_buffer, sizeof(chathistory_searchstring)); + i = 0; + } + else i = chathistory_line + 1; + + if (!*partial) + partial = "*"; + else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern? + partial = va(vabuf, sizeof(vabuf), "*%s*", partial); + + for ( ; i < CONBUFFER_LINES_COUNT(&chathistory); i++) + if (matchpattern_with_separator(ConBuffer_GetLine(&chathistory, i), partial, true, "", false)) + { + Con_Printf("^2%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&chathistory, i)); + chathistory_line = i; + chathistory_matchfound = true; + return; + } +} + static void Key_History_Find_All(void) { const char *partial = key_line + 1; @@ -395,6 +463,28 @@ static void Key_History_Find_All(void) Con_Printf("%i result%s\n\n", count, (count != 1) ? "s" : ""); } +static void MsgKey_History_Find_All(void) +{ + const char *partial = chat_buffer; + int i, count = 0; + char vabuf[1024]; + size_t digits = strlen(va(vabuf, sizeof(vabuf), "%i", HIST_MAXLINES)); + Con_Printf("Chathistory containing \"%s\":\n", chat_buffer); + + if (!*partial) + partial = "*"; + else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern? + partial = va(vabuf, sizeof(vabuf), "*%s*", partial); + + for (i=0; i