diff --git a/src/command_manager.cc b/src/command_manager.cc index d53070326..e8d1158a4 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -479,7 +479,7 @@ void CommandManager::execute(StringView command_line, execute_single_command(params, context, shell_context, command_coord); } -CommandInfo CommandManager::command_info(const Context& context, StringView command_line) const +Optional CommandManager::command_info(const Context& context, StringView command_line) const { TokenList tokens = parse(command_line); size_t cmd_idx = 0; @@ -489,19 +489,19 @@ CommandInfo CommandManager::command_info(const Context& context, StringView comm cmd_idx = i+1; } - CommandInfo res; if (cmd_idx == tokens.size() or (tokens[cmd_idx].type() != Token::Type::Raw and tokens[cmd_idx].type() != Token::Type::RawQuoted)) - return res; + return {}; auto cmd = find_command(context, tokens[cmd_idx].content()); if (cmd == m_commands.end()) - return res; + return {}; - res.first = cmd->first; + CommandInfo res; + res.name = cmd->first; if (not cmd->second.docstring.empty()) - res.second += cmd->second.docstring + "\n"; + res.info += cmd->second.docstring + "\n"; if (cmd->second.helper) { @@ -520,7 +520,7 @@ CommandInfo CommandManager::command_info(const Context& context, StringView comm { if (helpstr.back() != '\n') helpstr += '\n'; - res.second += helpstr; + res.info += helpstr; } } @@ -528,14 +528,14 @@ CommandInfo CommandManager::command_info(const Context& context, StringView comm for (auto& alias : context.aliases().aliases_for(cmd->first)) aliases += " " + alias; if (not aliases.empty()) - res.second += "Aliases:" + aliases + "\n"; + res.info += "Aliases:" + aliases + "\n"; auto& switches = cmd->second.param_desc.switches; if (not switches.empty()) { - res.second += "Switches:\n"; - res.second += generate_switches_doc(switches); + res.info += "Switches:\n"; + res.info += generate_switches_doc(switches); } return res; diff --git a/src/command_manager.hh b/src/command_manager.hh index 4a3266132..55d629219 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -8,6 +8,7 @@ #include "shell_manager.hh" #include "parameters_parser.hh" #include "string.hh" +#include "optional.hh" #include "utils.hh" #include "unordered_map.hh" @@ -38,7 +39,7 @@ enum class CommandFlags template<> struct WithBitOps : std::true_type {}; -using CommandInfo = std::pair; +struct CommandInfo { String name, info; }; struct Token { @@ -91,8 +92,8 @@ public: CommandParameters params, size_t token_to_complete, ByteCount pos_in_token); - CommandInfo command_info(const Context& context, - StringView command_line) const; + Optional command_info(const Context& context, + StringView command_line) const; bool command_defined(const String& command_name) const; diff --git a/src/normal.cc b/src/normal.cc index 282d18e6a..54cbbc6c5 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -366,16 +366,21 @@ void command(Context& context, NormalParams params) if (context.has_client()) { context.client().info_hide(); - auto autoinfo = context.options()["autoinfo"].get(); - if (event == PromptEvent::Change and autoinfo & AutoInfo::Command) + if (event == PromptEvent::Change) { - if (cmdline.length() == 1 and is_horizontal_blank(cmdline[0_byte])) - context.client().info_show("prompt", "commands preceded by a blank wont be saved to history", - {}, InfoStyle::Prompt); - auto info = CommandManager::instance().command_info(context, cmdline); - if (not info.first.empty() and not info.second.empty()) - context.client().info_show(info.first, info.second, {}, InfoStyle::Prompt); + context.input_handler().set_prompt_face(get_face(info ? "Prompt" : "Error")); + + auto autoinfo = context.options()["autoinfo"].get(); + if (autoinfo & AutoInfo::Command) + { + if (cmdline.length() == 1 and is_horizontal_blank(cmdline[0_byte])) + context.client().info_show("prompt", + "commands preceded by a blank wont be saved to history", + {}, InfoStyle::Prompt); + else if (info and not info->info.empty()) + context.client().info_show(info->name, info->info, {}, InfoStyle::Prompt); + } } } if (event == PromptEvent::Validate)