| File PromptRequest.cpp changed (mode: 100644) (index 7cfc31f..71a1391) |
| 27 |
27 |
#include <memory> |
#include <memory> |
| 28 |
28 |
#include <stdexcept> |
#include <stdexcept> |
| 29 |
29 |
#include <string> |
#include <string> |
|
30 |
|
#include <unordered_map> |
| 30 |
31 |
#include <utility> |
#include <utility> |
| 31 |
32 |
|
|
| 32 |
33 |
#include <readline/history.h> |
#include <readline/history.h> |
| |
| ... |
... |
private: |
| 93 |
94 |
|
|
| 94 |
95 |
} |
} |
| 95 |
96 |
|
|
|
97 |
|
void |
|
98 |
|
PromptHistory::switchContext(const std::string &name) |
|
99 |
|
{ |
|
100 |
|
static struct { |
|
101 |
|
std::unordered_map<std::string, HISTORY_STATE> contexts; |
|
102 |
|
std::string current; |
|
103 |
|
} state; |
|
104 |
|
|
|
105 |
|
auto &s = state; |
|
106 |
|
|
|
107 |
|
if (name == s.current) { |
|
108 |
|
return; |
|
109 |
|
} |
|
110 |
|
|
|
111 |
|
if (HISTORY_STATE *stateSnapshot = history_get_history_state()) { |
|
112 |
|
s.contexts[s.current] = *stateSnapshot; |
|
113 |
|
std::free(stateSnapshot); |
|
114 |
|
} |
|
115 |
|
|
|
116 |
|
auto it = s.contexts.find(name); |
|
117 |
|
if (it != s.contexts.end()) { |
|
118 |
|
history_set_history_state(&it->second); |
|
119 |
|
} else { |
|
120 |
|
HISTORY_STATE emptyState = {}; |
|
121 |
|
history_set_history_state(&emptyState); |
|
122 |
|
} |
|
123 |
|
|
|
124 |
|
s.current = name; |
|
125 |
|
} |
|
126 |
|
|
| 96 |
127 |
void |
void |
| 97 |
128 |
PromptHistory::limit(int limit) |
PromptHistory::limit(int limit) |
| 98 |
129 |
{ stifle_history(limit); } |
{ stifle_history(limit); } |
| File PromptRequest.hpp changed (mode: 100644) (index 86e37a1..b341650) |
| ... |
... |
namespace cursedrl { |
| 37 |
37 |
|
|
| 38 |
38 |
// Groups history management functions. |
// Groups history management functions. |
| 39 |
39 |
namespace PromptHistory { |
namespace PromptHistory { |
|
40 |
|
// Saves current context ("" initially) and loads specified one. |
|
41 |
|
void switchContext(const std::string &name); |
|
42 |
|
|
| 40 |
43 |
// Puts a limit on maximum number of history entries. |
// Puts a limit on maximum number of history entries. |
| 41 |
44 |
void limit(int limit); |
void limit(int limit); |
| 42 |
45 |
// Loads history from the file. |
// Loads history from the file. |