aboutsummaryrefslogtreecommitdiff
path: root/src/chat.h
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2023-01-14 16:14:37 -0500
committerGitHub <noreply@github.com>2023-01-14 16:14:37 -0500
commit2f9f0c09001b8fbc6f4559cbfdccf0261f1377a4 (patch)
treea6fe6efb95c6f6144110aee95b4694219281e143 /src/chat.h
parent8fded9d990d1e1142b630b24c96f1a2c959fef36 (diff)
downloadminetest-2f9f0c09001b8fbc6f4559cbfdccf0261f1377a4.tar.xz
Improve chat history (#12975)
Diffstat (limited to 'src/chat.h')
-rw-r--r--src/chat.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/chat.h b/src/chat.h
index fc080f64b..280701d47 100644
--- a/src/chat.h
+++ b/src/chat.h
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h"
#include "util/enriched_string.h"
+#include "util/Optional.h"
#include "settings.h"
// Chat console related classes
@@ -172,10 +173,10 @@ public:
void addToHistory(const std::wstring &line);
// Get current line
- std::wstring getLine() const { return m_line; }
+ std::wstring getLine() const { return getLineRef(); }
// Get section of line that is currently selected
- std::wstring getSelection() const { return m_line.substr(m_cursor, m_cursor_len); }
+ std::wstring getSelection() const { return getLineRef().substr(m_cursor, m_cursor_len); }
// Clear the current line
void clear();
@@ -233,18 +234,33 @@ public:
void cursorOperation(CursorOp op, CursorOpDir dir, CursorOpScope scope);
protected:
+ const std::wstring &getLineRef() const;
+
+ std::wstring &makeLineRef();
+
// set m_view to ensure that 0 <= m_view <= m_cursor < m_view + m_cols
// if line can be fully shown, set m_view to zero
// else, also ensure m_view <= m_line.size() + 1 - m_cols
void clampView();
private:
+ struct HistoryEntry {
+ std::wstring line;
+ // If line is edited, saved holds the unedited version.
+ Optional<std::wstring> saved;
+
+ HistoryEntry(const std::wstring &line): line(line) {}
+
+ bool operator==(const HistoryEntry &other);
+ bool operator!=(const HistoryEntry &other) { return !(*this == other); }
+ };
+
// Prompt prefix
std::wstring m_prompt = L"";
- // Currently edited line
+ // Non-historical edited line
std::wstring m_line = L"";
// History buffer
- std::vector<std::wstring> m_history;
+ std::vector<HistoryEntry> m_history;
// History index (0 <= m_history_index <= m_history.size())
u32 m_history_index = 0;
// Maximum number of history entries