Only drop blank prefixed history entries in command/shell prompts
For regex prompts we actually want to save them, as a leading space is significant Fixes #767
This commit is contained in:
parent
ac81d0f39c
commit
911a32a992
|
@ -1627,11 +1627,12 @@ const CommandDesc prompt_cmd = {
|
||||||
context, flags, prefix, cursor_pos);
|
context, flags, prefix, cursor_pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
const bool password = (bool)parser.get_switch("password");
|
const auto flags = parser.get_switch("password") ?
|
||||||
|
PromptFlags::Password : PromptFlags::None;
|
||||||
|
|
||||||
context.input_handler().prompt(
|
context.input_handler().prompt(
|
||||||
parser[0], initstr.str(), get_face("Prompt"),
|
parser[0], initstr.str(), get_face("Prompt"),
|
||||||
password, std::move(completer),
|
flags, std::move(completer),
|
||||||
[=](StringView str, PromptEvent event, Context& context)
|
[=](StringView str, PromptEvent event, Context& context)
|
||||||
{
|
{
|
||||||
if (event != PromptEvent::Validate)
|
if (event != PromptEvent::Validate)
|
||||||
|
@ -1642,7 +1643,7 @@ const CommandDesc prompt_cmd = {
|
||||||
|
|
||||||
CommandManager::instance().execute(command, context, shell_context);
|
CommandManager::instance().execute(command, context, shell_context);
|
||||||
|
|
||||||
if (password)
|
if (flags & PromptFlags::Password)
|
||||||
{
|
{
|
||||||
const String& str = RegisterManager::instance()[reg].values(context)[0];
|
const String& str = RegisterManager::instance()[reg].values(context)[0];
|
||||||
memset(const_cast<String&>(str).data(), 0, (int)str.length());
|
memset(const_cast<String&>(str).data(), 0, (int)str.length());
|
||||||
|
|
|
@ -621,10 +621,10 @@ class Prompt : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Prompt(InputHandler& input_handler, StringView prompt,
|
Prompt(InputHandler& input_handler, StringView prompt,
|
||||||
String initstr, Face face, bool password,
|
String initstr, Face face, PromptFlags flags,
|
||||||
Completer completer, PromptCallback callback)
|
Completer completer, PromptCallback callback)
|
||||||
: InputMode(input_handler), m_prompt(prompt.str()), m_prompt_face(face),
|
: InputMode(input_handler), m_prompt(prompt.str()), m_prompt_face(face),
|
||||||
m_password(password), m_completer(completer), m_callback(callback),
|
m_flags(flags), m_completer(completer), m_callback(callback),
|
||||||
m_autoshowcompl{context().options()["autoshowcompl"].get<bool>()}
|
m_autoshowcompl{context().options()["autoshowcompl"].get<bool>()}
|
||||||
{
|
{
|
||||||
m_history_it = ms_history[m_prompt].end();
|
m_history_it = ms_history[m_prompt].end();
|
||||||
|
@ -853,7 +853,7 @@ private:
|
||||||
|
|
||||||
auto width = context().client().dimensions().column - m_prompt.char_length();
|
auto width = context().client().dimensions().column - m_prompt.char_length();
|
||||||
DisplayLine display_line;
|
DisplayLine display_line;
|
||||||
if (not m_password)
|
if (not (m_flags & PromptFlags::Password))
|
||||||
display_line = m_line_editor.build_display_line(width);
|
display_line = m_line_editor.build_display_line(width);
|
||||||
display_line.insert(display_line.begin(), { m_prompt, m_prompt_face });
|
display_line.insert(display_line.begin(), { m_prompt, m_prompt_face });
|
||||||
context().print_status(display_line);
|
context().print_status(display_line);
|
||||||
|
@ -872,15 +872,18 @@ private:
|
||||||
String m_prefix;
|
String m_prefix;
|
||||||
LineEditor m_line_editor;
|
LineEditor m_line_editor;
|
||||||
bool m_autoshowcompl;
|
bool m_autoshowcompl;
|
||||||
bool m_password;
|
PromptFlags m_flags;
|
||||||
|
bool m_history_drop_blank_prefix;
|
||||||
|
|
||||||
using History = Vector<String, MemoryDomain::History>;
|
using History = Vector<String, MemoryDomain::History>;
|
||||||
static UnorderedMap<String, History, MemoryDomain::History> ms_history;
|
static UnorderedMap<String, History, MemoryDomain::History> ms_history;
|
||||||
History::iterator m_history_it;
|
History::iterator m_history_it;
|
||||||
|
|
||||||
static void history_push(History& history, StringView entry)
|
void history_push(History& history, StringView entry)
|
||||||
{
|
{
|
||||||
if(entry.empty() or is_horizontal_blank(entry[0_byte]))
|
if(entry.empty() or
|
||||||
|
(m_flags & PromptFlags::DropHistoryEntriesWithBlankPrefix and
|
||||||
|
is_horizontal_blank(entry[0_byte])))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
history.erase(std::remove(history.begin(), history.end(), entry),
|
history.erase(std::remove(history.begin(), history.end(), entry),
|
||||||
|
@ -1293,11 +1296,11 @@ void InputHandler::repeat_last_insert()
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::prompt(StringView prompt, String initstr,
|
void InputHandler::prompt(StringView prompt, String initstr,
|
||||||
Face prompt_face, bool password,
|
Face prompt_face, PromptFlags flags,
|
||||||
Completer completer, PromptCallback callback)
|
Completer completer, PromptCallback callback)
|
||||||
{
|
{
|
||||||
push_mode(new InputModes::Prompt(*this, prompt, initstr, prompt_face,
|
push_mode(new InputModes::Prompt(*this, prompt, initstr, prompt_face,
|
||||||
password, completer, callback));
|
flags, completer, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::set_prompt_face(Face prompt_face)
|
void InputHandler::set_prompt_face(Face prompt_face)
|
||||||
|
|
|
@ -29,6 +29,15 @@ enum class PromptEvent
|
||||||
Validate
|
Validate
|
||||||
};
|
};
|
||||||
using PromptCallback = std::function<void (StringView, PromptEvent, Context&)>;
|
using PromptCallback = std::function<void (StringView, PromptEvent, Context&)>;
|
||||||
|
enum class PromptFlags
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Password = 1 << 0,
|
||||||
|
DropHistoryEntriesWithBlankPrefix = 1 << 1
|
||||||
|
};
|
||||||
|
template<> struct WithBitOps<PromptFlags> : std::true_type {};
|
||||||
|
|
||||||
|
|
||||||
using KeyCallback = std::function<void (Key, Context&)>;
|
using KeyCallback = std::function<void (Key, Context&)>;
|
||||||
|
|
||||||
class InputMode;
|
class InputMode;
|
||||||
|
@ -53,7 +62,7 @@ public:
|
||||||
// returns to normal mode after validation if callback does
|
// returns to normal mode after validation if callback does
|
||||||
// not change the mode itself
|
// not change the mode itself
|
||||||
void prompt(StringView prompt, String initstr,
|
void prompt(StringView prompt, String initstr,
|
||||||
Face prompt_face, bool password,
|
Face prompt_face, PromptFlags flags,
|
||||||
Completer completer, PromptCallback callback);
|
Completer completer, PromptCallback callback);
|
||||||
void set_prompt_face(Face prompt_face);
|
void set_prompt_face(Face prompt_face);
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ void command(Context& context, NormalParams params)
|
||||||
CommandManager::instance().clear_last_complete_command();
|
CommandManager::instance().clear_last_complete_command();
|
||||||
|
|
||||||
context.input_handler().prompt(
|
context.input_handler().prompt(
|
||||||
":", "", get_face("Prompt"), false,
|
":", "", get_face("Prompt"), PromptFlags::DropHistoryEntriesWithBlankPrefix,
|
||||||
[](const Context& context, CompletionFlags flags,
|
[](const Context& context, CompletionFlags flags,
|
||||||
StringView cmd_line, ByteCount pos) {
|
StringView cmd_line, ByteCount pos) {
|
||||||
return CommandManager::instance().complete(context, flags, cmd_line, pos);
|
return CommandManager::instance().complete(context, flags, cmd_line, pos);
|
||||||
|
@ -375,7 +375,9 @@ template<bool replace>
|
||||||
void pipe(Context& context, NormalParams)
|
void pipe(Context& context, NormalParams)
|
||||||
{
|
{
|
||||||
const char* prompt = replace ? "pipe:" : "pipe-to:";
|
const char* prompt = replace ? "pipe:" : "pipe-to:";
|
||||||
context.input_handler().prompt(prompt, "", get_face("Prompt"), false, shell_complete,
|
context.input_handler().prompt(
|
||||||
|
prompt, "", get_face("Prompt"),
|
||||||
|
PromptFlags::DropHistoryEntriesWithBlankPrefix, shell_complete,
|
||||||
[](StringView cmdline, PromptEvent event, Context& context)
|
[](StringView cmdline, PromptEvent event, Context& context)
|
||||||
{
|
{
|
||||||
if (event != PromptEvent::Validate)
|
if (event != PromptEvent::Validate)
|
||||||
|
@ -429,7 +431,9 @@ template<InsertMode mode>
|
||||||
void insert_output(Context& context, NormalParams)
|
void insert_output(Context& context, NormalParams)
|
||||||
{
|
{
|
||||||
const char* prompt = mode == InsertMode::Insert ? "insert-output:" : "append-output:";
|
const char* prompt = mode == InsertMode::Insert ? "insert-output:" : "append-output:";
|
||||||
context.input_handler().prompt(prompt, "", get_face("Prompt"), false, shell_complete,
|
context.input_handler().prompt(
|
||||||
|
prompt, "", get_face("Prompt"),
|
||||||
|
PromptFlags::DropHistoryEntriesWithBlankPrefix, shell_complete,
|
||||||
[](StringView cmdline, PromptEvent event, Context& context)
|
[](StringView cmdline, PromptEvent event, Context& context)
|
||||||
{
|
{
|
||||||
if (event != PromptEvent::Validate)
|
if (event != PromptEvent::Validate)
|
||||||
|
@ -590,7 +594,8 @@ void regex_prompt(Context& context, const String prompt, T func)
|
||||||
{
|
{
|
||||||
CharCoord position = context.has_window() ? context.window().position() : CharCoord{};
|
CharCoord position = context.has_window() ? context.window().position() : CharCoord{};
|
||||||
SelectionList selections = context.selections();
|
SelectionList selections = context.selections();
|
||||||
context.input_handler().prompt(prompt, "", get_face("Prompt"), false, complete_nothing,
|
context.input_handler().prompt(
|
||||||
|
prompt, "", get_face("Prompt"), PromptFlags::None, complete_nothing,
|
||||||
[=](StringView str, PromptEvent event, Context& context) mutable {
|
[=](StringView str, PromptEvent event, Context& context) mutable {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -817,7 +822,8 @@ void keep(Context& context, NormalParams)
|
||||||
void keep_pipe(Context& context, NormalParams)
|
void keep_pipe(Context& context, NormalParams)
|
||||||
{
|
{
|
||||||
context.input_handler().prompt(
|
context.input_handler().prompt(
|
||||||
"keep pipe:", "", get_face("Prompt"), false, shell_complete,
|
"keep pipe:", "", get_face("Prompt"),
|
||||||
|
PromptFlags::DropHistoryEntriesWithBlankPrefix, shell_complete,
|
||||||
[](StringView cmdline, PromptEvent event, Context& context) {
|
[](StringView cmdline, PromptEvent event, Context& context) {
|
||||||
if (event != PromptEvent::Validate)
|
if (event != PromptEvent::Validate)
|
||||||
return;
|
return;
|
||||||
|
@ -959,7 +965,8 @@ void select_object(Context& context, NormalParams params)
|
||||||
AutoInfo::Command, context);
|
AutoInfo::Command, context);
|
||||||
|
|
||||||
context.input_handler().prompt(
|
context.input_handler().prompt(
|
||||||
"object desc:", "", get_face("Prompt"), false, complete_nothing,
|
"object desc:", "", get_face("Prompt"),
|
||||||
|
PromptFlags::None, complete_nothing,
|
||||||
[level,info](StringView cmdline, PromptEvent event, Context& context) {
|
[level,info](StringView cmdline, PromptEvent event, Context& context) {
|
||||||
if (event != PromptEvent::Change)
|
if (event != PromptEvent::Change)
|
||||||
hide_auto_info_ifn(context, info);
|
hide_auto_info_ifn(context, info);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user