diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-01-11 18:58:42 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-11 21:09:36 +0100 |
commit | 510030971bb8670af373fb35f2fc567687ee4766 (patch) | |
tree | ca1734048ea4a49569f77bfbb92f5dd05f9a1f3f /Libraries/LibLine/Editor.h | |
parent | 711ced80c0c2a62ae18e12f4d828c7f7316dd935 (diff) | |
download | serenity-510030971bb8670af373fb35f2fc567687ee4766.zip |
LibLine: Handle history across multiple concurrent sessions better
- Store history entries as (timestamp)::(entry)\n\n
- Merge the entries together when saving to avoid loss of history
entries
To ideally make having two concurrently open shells
(or `js` repls or whatever) not overwrite each others' history entries.
Diffstat (limited to 'Libraries/LibLine/Editor.h')
-rw-r--r-- | Libraries/LibLine/Editor.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index 65655043e9..407b3fd9fa 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -154,7 +154,7 @@ public: void add_to_history(const String& line); bool load_history(const String& path); bool save_history(const String& path); - const Vector<String>& history() const { return m_history; } + const auto& history() const { return m_history; } void register_key_input_callback(const KeyBinding&); void register_key_input_callback(Vector<Key> keys, Function<bool(Editor&)> callback) { m_callback_machine.register_key_input_callback(move(keys), move(callback)); } @@ -451,9 +451,13 @@ private: bool m_was_resized { false }; // FIXME: This should be something more take_first()-friendly. - Vector<String> m_history; + struct HistoryEntry { + String entry; + time_t timestamp; + }; + Vector<HistoryEntry> m_history; size_t m_history_cursor { 0 }; - size_t m_history_capacity { 100 }; + size_t m_history_capacity { 1024 }; enum class InputState { Free, |